使用子过程方法(普通网格或使用jenkins)使用selenium网格分发测试

时间:2016-06-16 18:44:27

标签: python selenium selenium-grid2 parallel-testing

我想在本地计算机和远程计算机之间分发测试。我有2个测试,并希望并排运行它们以加快执行速度。 一台在本地机器上,另一台在远程机器上。我已在本地设置了我的集线器和一个节点,并且我已在远程计算机上注册了另一个节点..

以下是我保存在同一目录中的三个代码文件:

TestOnChrome.py

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
import time, unittest


class OnFirefox(unittest.TestCase):

    def setUp(self) :
        self.driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)


    def test_Google_Search_FF(self):
        driver = self.driver
        driver.get("http://www.google.com")
        inputElement = driver.find_element_by_name("q")
        inputElement.send_keys("Cheese!")
        inputElement.submit()



    def tearDown(self):
        self.driver.quit()


if __name__ == "__main__":
    unittest.main()

TestOnChromeTwo.py

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
import time, unittest


class OnFirefox(unittest.TestCase):

    def setUp(self) :
        self.driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)


    def test_Google_Search_FF(self):
        driver = self.driver
        driver.get("http://www.google.com")
        inputElement = driver.find_element_by_name("q")
        inputElement.send_keys("Cheese!")
        inputElement.submit()



    def tearDown(self):
        self.driver.quit()


if __name__ == "__main__":
    unittest.main()

这是我的runner.py

from subprocess import Popen
import glob
tests = glob.glob('test*.py')
processes = []
for test in tests:
    processes.append(Popen('python %s' % test, shell=True))
for process in processes:
    process.wait()

如果我运行runner.py它会自动分发测试吗?使用我注册的节点?或者我需要做点什么?

1 个答案:

答案 0 :(得分:2)

只要您的代码从网格集线器请求浏览器,网格集线器就会在其注册的网格节点中搜索与您请求的功能匹配的免费浏览器实例。您不需要为此做任何事情,除非您在此处请求浏览器self.driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)

相关问题