Quit()在selenium网格3.4.0(ThreadLocal)

时间:2017-08-15 13:00:36

标签: selenium-webdriver selenium-grid selenium-grid2

我使用的是selenium grid和selenium 3.4.0版本。我收到tearDown()函数的错误(浏览器关闭但函数错误),我在tearDown()函数中尝试了@After,before,suite,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();
}
}

头等舱:

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>

错误讯息:

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

1 个答案:

答案 0 :(得分:1)

我不知道您使用的节点网址。尝试此链接和设置集线器,节点然后尝试您的代码,如果工作,那么您有节点URL的问题,否则让我们知道您使用的节点URL。

Link for your solution