简体   繁体   English

硒网格。 在各种浏览器中并行执行

[英]Selenium grid. Parallel execution in various browser

Now I use this to run tests. 现在我用它来运行测试。 I pass in the command line the name of the browser and the number of help streams. 我在命令行中传递浏览器的名称和帮助流的数量。 pytest-xdist

def __init__(self, browser):
    desired_capabilites = None
    comand_executor = "http://localhost:4444/wd/hub"

    if browser == "chrome":
        desired_capabilites =  {
                "browserName": "chrome",
                "maxInstances": 5
            }
    elif browser == "firefox":
        desired_capabilites = {
            "browserName": "firefox",
            "maxInstances": 5
        }

    self.driver = webdriver.Remote(
        command_executor=comand_executor,
        desired_capabilities=desired_capabilites)

But this method, it seems to me, has several drawbacks: 但在我看来,这种方法有几个缺点:

  • Before launch, always start * selenium-server * ( java -jar selenium-standalone-server.jar ) - To test everything in different browsers 在发布之前,始终启动* selenium-server *( java -jar selenium-standalone-server.jar ) - 测试不同浏览器中的所有内容
  • I have to run tests twice (one for chrome, second for ff) 我必须运行两次测试(一次用于铬,第二次用于ff)

Is it possible to automate server startup somehow? 有可能以某种方式自动化服务器启动吗?

And how to run tests in parallel in different browsers? 以及如何在不同的浏览器中并行运行测试?

An excellent option would be to create two nodes and run tests simultaneously in both. 一个很好的选择是创建两个节点并在两者中同时运行测试。 Or create several different browsers in one node and launch them already. 或者在一个节点中创建几个不同的浏览器并启动它们。 But I dont know how. 但我不知道如何。 Thanks in advance for your help 在此先感谢您的帮助

There are two ways that you can handle the this. 有两种方法可以解决这个问题。

  1. Get a cloud instance or a server where you can boot up selenium grid and use the server Url to access it. 获取云实例或服务器,您可以在其中启动selenium网格并使用服务器Url访问它。 So that you don't need to tare down the server after you are done testing. 因此,在完成测试后,您无需关闭服务器。

  2. If you want to automate the whole setup and tare down process you can use Jenkins and configure Jenkins such a way that you can setup the whole grid before you run the tests and tare down after you are done with it. 如果你想自动完成整个设置和去皮过程,你可以使用Jenkins并配置Jenkins,这样你就可以在运行测试之前设置整个网格,并在完成测试后去掉它。

If you are using cucumber you can tag the test cases as @Chrome and @FF and when you do the remote browser use if scenario.tagName.equals(Chrome) then run in a node or fire up the remotedriver with chrome capabilities. 如果您使用黄瓜,您可以将测试用例标记为@Chrome和@FF,当您使用远程浏览器时,如果使用scenario.tagName.equals(Chrome),则在节点中运行或使用chrome功能启动remotedriver。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM