python selenium grid_如何设置Selenium Grid Python测试用例以跨多台计算机进行测试?...

我已经成功地设置了SeleniumGrid,以便在具有不同操作系统和浏览器的多台计算机上运行我的Python测试。

但是,我仍然需要编写相同的测试用例3次,每个节点一次,因为对节点的引用在测试用例中。

我已经看过各种关于Python的在线建议,例如将节点ip分离到外部文件中并将其导入到测试用例中,但是它们似乎都不起作用,或者说明是针对Java的。

如何设置Python测试用例,以便只编写一次?

我的集线器命令提示指令是:java -jar selenium-server-standalone-2.29.0.jar -host http://localmachineipaddress -port 4444 -role hub

我的节点命令提示说明如下:*FireFox PC, Chrome PC, Safari PC, and IE9 PC on local machine*

java -jar selenium-server-standalone-2.29.0.jar -host localhost -role webdriver -hub http://theHubIP:4444/grid/register -port 5555 -browser browserName=firefox,maxInstances=5,platform=WINDOWS -browser browserName=chrome,maxInstances=5,platform=WINDOWS -Dwebdriver.chrome.driver=c:\SeleniumGrid\chromedriver.exe -browser browserName=iehta,maxInstances=5,platform=WINDOWS -Dwebdriver.ie.driver=c:\SeleniumGrid\IEDriverServer.exe -browser browserName=safari,maxInstances=5,platform=WINDOWS -Dwebdriver.safari.driver=c:\Python27\SafariDriver2.28.0.safariextz

*FireFox MAC, Safari MAC, and Chrome MAC machine*

java -jar selenium-server-standalone-2.29.0.jar -role webdriver -hub http://theHubIP:4444/grid/register -debug -port 5556 -browser browserName=firefox,maxInstances=5,platform=MAC -browser browserName=chrome,maxInstances=5,platform=MAC -browser browserName=safari,maxInstances=5,platform=MAC -Dwebdriver.safari.driver=c:\Python27\SafariDriver2.28.0.safariextz

*IE8 PC machine*

java -jar selenium-server-standalone-2.29.0.jar -role webdriver -hub http://theHubIP:4444/grid/register -port 5559 -browser browserName=iehta,maxInstances=5,platform=WINDOWS -Dwebdriver.ie.driver=c:\SeleniumGrid\IEDriverServer.exe

我的测试用例命令提示符说明是:python Python27/Test_Cases/SeleniumTest.py 5555 firefox WINDOWS

python Python27/Test_Cases/SeleniumTest.py 5555 chrome WINDOWS

python Python27/Test_Cases/SeleniumTest.py 5555 iehta WINDOWS

python Python27/Test_Cases/SeleniumTest.py 5555 safari WINDOWS

python Python27/Test_Cases/SeleniumTestIE8.py 5559 iehta WINDOWS

python Python27/Test_Cases/SeleniumTestApple.py 5556 chrome MAC

python Python27/Test_Cases/SeleniumTestApple.py 5556 firefox MAC

python Python27/Test_Cases/SeleniumTestApple.py 5556 safari MAC

我的测试用例是:# coding: utf-8

from selenium import webdriver

from selenium.common.exceptions import TimeoutException

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.keys import Keys

import HTMLTestRunner

import unittest, time

import sys

class SeleniumTest1(unittest.TestCase):

def setUp(self):

self.driver = webdriver.Remote(command_executor="http://theNodeIP:5555/wd/hub",desired_capabilities={ "browserName": browser, "platform": platform, "node":node })

self.driver.implicitly_wait(2)

def mytest(self):

self.driver.get("http://url.com")

self.driver.find_element_by_css_xpath("test_some_stuff").click()

def tearDown(self):

self.driver.quit()

def suite():

s1 = unittest.TestLoader().loadTestsFromTestCase(SeleniumTest1)

return unittest.TestSuite([s1])

def run(suite, report = "C:\\Python27\\Test_Cases\\Reports\\SeleniumTest1.html"):

with open(report, "w") as f:

HTMLTestRunner.HTMLTestRunner(

stream = f,

title = 'SeleniumTest1',

verbosity = 2,

description = 'SeleniumTest1'

).run(suite)

if __name__ == "__main__":

args = sys.argv

node=args[1]

browser = args[2]

platform = args[3]

run(suite())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值