How to open too many browsers using Selenium WebDriver?

I have a requirement to open 50 to 100 URLs once and verify the login for each URL. All URLs belongs to Same App but hosted for different customers? How I can open multiple browsers, say 20 to 50 browser with different URLs using Selenium WebDriver? I tried TestNG with Parallel attribute set to "Tests" and instantiating driver object in @BeforeTest but after opening 2 browsers getting selenium exception as browser closed or died for 3rd browser.

Below find code for this. @Test @Parameters({ "url" }) public void testParallel(String url) throws Exception {

    try {
        driver.get(url);

        int i = 0;
        i++;
        System.out.println("Browser Count" + i);

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

I think it is not possible to use multiple IEDriver instances in parallel on the same machine using Java bindings. (remember reading somewhere.. .NET bindings support parallel IE instances)

As per official documentation of IEDriver, "Unlike other WebDriver classes, there should only ever be a single InternetExplorerDriver instance at one time for some language bindings. If you need to run more than one instance of the InternetExplorerDriver at a time, consider using the RemoteWebDriver and virtual machines.". Refer here.

This should work with FirefoxDriver provided you have got your testng xml right. Or if you want it on IE, then you should consider setting up a grid and launch IE nodes on different machines, so that parallel runs can happen.


Why do you need to open them all at once? Selenium is not designed for load testing. If you want to check how your application or server is doing under load you better have a look at JMeter.


For a test like that I would recommend not using a browser per-se but instead use HTMLUnit driver (which is like a headless browser). Also, there is a thing called GhostDriver than might also accomplish similar. Still, you should probably use a remote Grid node+hub but you don't need to in order to accomplish your goal.

Selenium can do load testing in that respect. Also, I wouldh't use TestNG: instead, I would use Gradle or Maven because they have JUnit forking-multithread capability in themselves. In Gradle or Maven, create a task that filters and identifies certain test class and then forks processes to run them multi-threaded. I created an example here.

链接地址: http://www.djcxy.com/p/52328.html

上一篇: 使用硒登录页面的测试用例; java和Eclipse IDE

下一篇: 如何使用Selenium WebDriver打开太多浏览器?