0

我想在我的本地机器和远程机器之间分发我的测试。我有 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,它会自动分发测试吗?使用我注册的节点?还是我需要做点别的?

4

1 回答 1

2

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

于 2016-06-17T06:56:57.827 回答