Multiple WebDriver instances in Selenium without Grid?
Asked Answered
B

4

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
}
Betteanne answered 22/4, 2014 at 8:24 Comment(5)
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 ?Jarrett
@Harsha I added an example how the driver is created and destroyedBetteanne
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 executedJarrett
@Harsha My changes for the concurrent test execution are built upon other testingclasses in this framework and the driver was a static reference. :(Betteanne
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 threadsJarrett
D
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();
    }
}    
Dipteral answered 22/4, 2014 at 11:31 Comment(0)
C
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

Crankcase answered 22/4, 2014 at 23:43 Comment(0)
S
-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>
Synclastic answered 22/4, 2014 at 8:46 Comment(1)
This is regarding multiple WebDriver InstancesJarrett
D
-1

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

Dipteral answered 22/4, 2014 at 11:0 Comment(2)
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.Betteanne
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 eclipseJarrett

© 2022 - 2024 — McMap. All rights reserved.