0
votes

Is it possible to use multiple selenium webdrivers locally without using selenium grid to run multiple test at the same time?

I am creating multiple instances by calling new FireFoxDriver() but the sessions in the windows seem to interfere with each other.

The driver is created and destroyed by the JUnit-Methods shown below. For every Test-class there is one WebDriver but each testcase has a different execution duration. And after the first Test-class has finished and tearDownClass() from this class was called. This exception this thrown:

org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called. Build info: version: '2.39.0', revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16 13:18:38' System info: host: 'T61', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.11.0-15-generic', java.version: '1.7.0_51'

@BeforeClass
public static void setUpClass() {
    driver = new FireFoxDriver();
}

@AfterClass
public static void tearDownClass() {
    driver.quit(); // this should only kill the current driver
}
4
Multiple instances of firefox, invoked using FirefoxDriver(), do not interfere each other until and unless we are messed up in handling the webdriver instances. Can you let us know, how the invocation is happening ? - Harshavardhan Konakanchi
@Harsha I added an example how the driver is created and destroyed - Lukas Eichler
I prefer following this way In JUnit class, need to have everything non-static, so, we will get rid of instance interferences with other Create a wrapper around your JUnit class, using threads, so that you can call the desired methods based on the parameters for the testcases or testmethods to be executed - Harshavardhan Konakanchi
@Harsha My changes for the concurrent test execution are built upon other testingclasses in this framework and the driver was a static reference. :( - Lukas Eichler
You can use a super class inherited by all the sub classes, so that sharing the webdriver instance can be done without static and, create threads based on the super class so it coverges at a point whwree there is no static & no interference across threads - Harshavardhan Konakanchi

4 Answers

1
votes

Then Try to use different driver variables for different instances:

Eg:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Testing 
{
    WebDriver driver1, driver2;
    @BeforeClass
    public void BeforeClass()
    {
        driver1 = new FirefoxDriver();
        driver2 = new FirefoxDriver();
    }
    @Test
    public void Test1() throws InterruptedException
    {
        driver1.get("http://www.google.com");
        driver2.get("http://gmail.com");

    }
    @org.testng.annotations.AfterClass
    public void AfterClass()
    {
        driver1.quit();
    }
}    
0
votes

Try to use different Eclipses.. I mean, start 2 eclipses & run the same program in both the eclipses....

0
votes

You can use RemoteWebDriver without having a full Selenium Grid. If you start the Selenium Standalone jar locally without defining a role, then it is in effect a Grid and Node combined into one. With this local Selenium Server instance, you can run several browsers concurrently.

Creating a Firefox instance via RemoteWebDriver is pretty simple and well documented on line

-1
votes

Default selenium will run on 4444 port. Please create your instances as such that it takes different port each one by adding

     -port <port id/number>