使用子进程方法(普通网格或使用 jenkins)使用 selenium 网格分发测试
Distributing tests using selenium grid using subprocess approach(plain grid or using jenkins)
我想在我的本地机器和远程机器之间分发我的测试。我有 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 它会自动分发测试吗?使用我注册的节点?或者我需要做其他事情?
只要您的代码从网格中心请求浏览器,网格中心就会在其注册的网格节点中搜索与您请求的功能相匹配的免费浏览器实例。你不需要为此做任何事情,除了像你在这里做的那样请求浏览器 self.driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)
.
我想在我的本地机器和远程机器之间分发我的测试。我有 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 它会自动分发测试吗?使用我注册的节点?或者我需要做其他事情?
只要您的代码从网格中心请求浏览器,网格中心就会在其注册的网格节点中搜索与您请求的功能相匹配的免费浏览器实例。你不需要为此做任何事情,除了像你在这里做的那样请求浏览器 self.driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)
.