Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with 2 FireFoxDrivers simultaneously? Does Selenium support multithreading?

How to work with 2 FireFoxDrivers simultaneously? Does Selenium support multithreading?

I have the below test which opens 2 firefox browsers but both navigations happen only on the first browser instance!

  [Test]
    public void TestMultithreading()
    {
        var tasks = new List<Task>
                        {
                            new Task(goToBbc),
                            new Task(goToGoogle)
                        };

        tasks.ForEach(task => task.Start());

        Task.WaitAll(tasks.ToArray());
    }

    private void goToBbc()
    {
        openBrowserAndGoTo("http://www.bbc.com");
    }

    private void goToGoogle()
    {
        openBrowserAndGoTo("http://www.google.com");
    }

    private void openBrowserAndGoTo(string url)
    {
        var webDriver = new FirefoxDriver();
        webDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 1, 0));
        webDriver.Navigate().GoToUrl(url);
        Thread.Sleep(5000);
        webDriver.Quit();
    }

Hope the question is clear.

Thanks,

like image 464
The Light Avatar asked Mar 16 '12 14:03

The Light


People also ask

Can you do multithreading in selenium?

Selenium can use multi−threading in one browser with the help of TestNG framework. TestNG provides the feature of parallel execution which works on the concept of Java multi−threading. To execute tests based on various parameters, the TestNG has an XML file where we have the configurations.

How do I run a test on multiple browsers in parallel?

In parallel testing, we test different modules or applications on multiple browsers in parallel rather than one by one. The parallel test execution is different from sequential testing, where we test different modules or functionalities one after the other.

What is the use of thread count in TestNG?

Thread count is basically a number of instances running to execute multiple tests simultaneously or in parallel. The attribute thread-count allows the user to specify how many threads should be run for this execution.

What is cross browser testing and parallel testing in selenium?

What is Cross Browser Testing in Selenium? Cross browser testing refers to testing a website in multiple browsers like IE, Chrome, Firefox to check its efficacy on each. Cross-browser compatibility is the ability of the website or web application to function across different browsers and operating systems.


1 Answers

Selenium RC/WebDriver is intended to automate a browser. If you want to run multiple tests in parallel, you should look at running your scripts through Selenium Grid/RemoteDriver.

like image 118
bryanbcook Avatar answered Sep 24 '22 06:09

bryanbcook