Multiple WebDriver instances in Selenium without G

2019-09-01 01:06发布

问题:

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
}

回答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();
    }
}    


回答2:

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



回答3:

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



回答4:

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>