首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置测试用例,以便跨多台计算机进行测试?

如何设置测试用例,以便跨多台计算机进行测试?
EN

Stack Overflow用户
提问于 2013-02-20 22:47:27
回答 2查看 9.2K关注 0票数 6

我已经成功地设置了SeleniumGrid,以便在具有不同操作系统和浏览器的多台计算机上运行我的Python测试。但是,由于对节点的引用在测试用例中,所以我仍然需要为每个节点编写3次相同的测试用例。

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

有了Mozilla的这个,我不知道如何用我的测试用例/如何运行它来设置这个文件:sumo.py?view=markup

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

我的集线器命令提示符指令是:

代码语言:javascript
复制
java -jar selenium-server-standalone-2.29.0.jar -host http://localmachineipaddress -port 4444 -role hub

我的节点命令提示符指令是:

代码语言:javascript
复制
*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   

我的测试用例命令提示符指令是:

代码语言:javascript
复制
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

我的测试用例是:

代码语言:javascript
复制
# 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())
EN

回答 2

Stack Overflow用户

发布于 2016-12-05 20:05:27

我能够同时使用nose_parameterized模块测试两个浏览器。(使用nose_parameterized模块不需要使用鼻子测试运行程序。)

代码语言:javascript
复制
from django.test import LiveServerTestCase
from nose_parameterized import parameterized
from selenium import webdriver


class UITest(LiveServerTestCase):

    def setUp(self):
        self.selenium = {
            'chrome': webdriver.Chrome(),
            'firefox': webdriver.Firefox(),
        }

    def tearDown(self):
        for browser in self.selenium:
            self.selenium[browser].quit()

    testdata = [
        ('chrome',),
        ('firefox',),
    ]

    @parameterized.expand(testdata)
    def test_something(self, browser):
        driver = self.selenium[browser]
        # [...]

要使用Selenium,正如您的问题所问的,只需更改the驱动程序即可。

票数 2
EN

Stack Overflow用户

发布于 2013-04-01 20:03:43

与其通过shell调用传递浏览器和平台的参数,不如让Python脚本读取配置文件。本质上,您将拥有一个配置文件,该文件列出了希望在其上运行的浏览器以及一个平台列表。

诀窍是,您需要一个更高级别的套件文件,该文件将通过每次组合调用其他测试。因此,您将有一个套件文件,它轮询此配置文件以查找浏览器和平台组合,使用不同的组合执行套件。

如果Python中有多线程支持,甚至可以并行测试执行。

例如,在Ruby中,我将从一个.yml文件中读取我的配置,然后使用每个浏览器平台组合在多个线程中执行rake调用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14991393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档