1

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
}
Lukas Eichler
  • 5,689
  • 1
  • 24
  • 43
  • 1
    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 Apr 22 '14 at 09:00
  • @Harsha I added an example how the driver is created and destroyed – Lukas Eichler Apr 22 '14 at 10:58
  • 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 Apr 23 '14 at 02:32
  • @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 Apr 23 '14 at 07:57
  • 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 May 06 '14 at 02:19

4 Answers4

1

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();
    }
}    
HemaSundar
  • 1,263
  • 3
  • 17
  • 28
0

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

Robbie Wareham
  • 3,380
  • 1
  • 20
  • 38
-1

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>
nitin chawda
  • 1,378
  • 11
  • 24
-1

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

HemaSundar
  • 1,263
  • 3
  • 17
  • 28
  • This would be not useful since we are not speaking about just two parallel tests but 10+. Solving this through parallel IDEs would just cause too much overhead. – Lukas Eichler Apr 22 '14 at 11:12
  • And executing them at large scale if required causes many issues in terms of memory, unwanted cpu utilization..... Instead of that, better we could do it from command line in multiple units saving the memory occupied by eclipse – Harshavardhan Konakanchi May 06 '14 at 02:16