Selenium parallel testing on multiple browsers (JAVA)

会有一股神秘感。 提交于 2019-12-13 18:47:25

问题


I was surprised not to find any intelligent solution how run Selenium webdriver tests using Selenium Grid but running each test with multiple browsers. Preferably I'd like to have some kind of configuration (file, or hard coded) where I can specify all browsers I want my tests to run. And then each test would be run on each of those browsers.

I assume it is possible to write your own testrunner and place a loop iterating each test rung through all the browsers. But maybe someone knows a more elegant solution? Anyone has done this?

P.S. I have found solutions which advise duplicating the tests and specifying browser parameters for each test. I don't want that.


回答1:


I'm unfamiliar with Selenium Grid, but I know you can have Selenium open multiple browsers simultaneously by running each test on a different thread. You may want to look in to this.




回答2:


I have solved this in a way that I specify different browser parameter for each TestNG suite.




回答3:


What I do is run my test at class level then create a TestNG.xml then inside there specify what classes I wish to run and what browsers they should run on. So my TestNG file would look something like:

    <?xml version="1.0" encoding="UTF-8"?>
<suite name = "suite1" verbose = "6" preserve-order="true" parallel = "false" thread-count="1">

    <test name = "Any Test">
    <parameter name = "browser" value ="chrome">
    <parameter name = "port" value = "5555">
    </parameter>
    </parameter>
        <classes>
             <class name = "name of class to run"/>      
        </classes>
    </test>
</suite>

Then because I'm running on Selenium Grid I pass parameters for browser and port in my code like so:

@BeforeMethod()
    @Parameters({"browser","port"})
    public void launchBrowsers(String browser, String port) throws Exception {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName(browser);
        capabilities.setJavascriptEnabled(true);

        setSelenium(new RemoteWebDriver(new URL("http://localhost:".concat(port).concat("/wd/hub")), capabilities));

        getSelenium().get(baseUrl); 
        getSelenium().manage().window().maximize();             
    }

Hope this helps



来源:https://stackoverflow.com/questions/26380378/selenium-parallel-testing-on-multiple-browsers-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!