selenium-webdriverselenium-gridselenium-grid2

Quit() is not working in selenium grid 3.4.0 (ThreadLocal)


I am using selenium grid and selenium 3.4.0 version. I am getting error for the tearDown() function (Browser closing but error at the function), I tried @After, before, suite, class etc annotation at tearDown() function but not working. Please suggest what is my mistake and how to resolve.

Base class:

public class TestBase {

//public ThreadLocal<RemoteWebDriver> driver;
public ThreadLocal<RemoteWebDriver> driver = new ThreadLocal<RemoteWebDriver>();

//Do the test setup
@BeforeMethod
@Parameters(value="browser")
public void setupTest (String browser) throws MalformedURLException {
    //Assign driver to a ThreadLocal
    //driver = new ThreadLocal<>();
    DesiredCapabilities capabilities = new DesiredCapabilities();
    if (browser.equals("chrome")) {
        capabilities.setCapability("browserName", browser);
        driver.set(new RemoteWebDriver(new URL("http://123.123.0.50:4444/wd/hub"), capabilities));

    }   else if(browser.equals("internet explorer")){
        capabilities.setCapability("browserName", browser);
        driver.set(new RemoteWebDriver(new URL("http://123.123.0.50:4444/wd/hub"), capabilities));
        capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
    }
    else if(browser.equals("firefox")){
        capabilities.setCapability("browserName", browser);
        driver.set(new RemoteWebDriver(new URL("http://123.123.0.50:4444/wd/hub"), capabilities));
    }
}

public WebDriver getDriver() {
    return driver.get();
}

@AfterMethod
public void tearDown() throws Exception {
     //getDriver().close();
    getDriver().quit();
}
}

First Class:

public class FirstTest extends TestBase {

@Test
public void firstTest() throws Exception {
    System.out.println("First Test Started!");
    getDriver().navigate().to("http://www.facebook.com");
    System.out.println("First Test's Page title is: " + getDriver().getTitle());
    System.out.println("First Test Ended!");
}

@Test
public void firstTests() throws Exception {
    System.out.println("First of Second Test Started!");
    getDriver().navigate().to("http://www.facebook.com");
    System.out.println("First Test's Page title is: " + getDriver().getTitle());
    System.out.println("First of Second Test Ended!");
}
}

TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests"  thread-count="2">

<test name="FFTest">
 <parameter name="browser" value="firefox" />
 <classes>
 <class name="parallelGrid.SecondTest" />
 </classes>
 </test>
</suite>

Error message:

org.openqa.selenium.WebDriverException: quit
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'

Solution

  • I do not know your Node url you using. Try this link and setup hub, node then try your code, if worked then you have an issue with node url else let us know the node url you using.

    Link for your solution