Quit() 在 selenium grid 3.4.0 (ThreadLocal) 中不起作用
Quit() is not working in selenium grid 3.4.0 (ThreadLocal)
我正在使用 selenium grid 和 selenium 3.4.0 版本。 tearDown()
函数出现错误(浏览器关闭但函数出错),我在 tearDown() 函数中尝试了 @After、before、suite、class 等注释,但没有工作。请指出我的错误是什么以及如何解决。
基础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();
}
}
第一个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>
错误信息:
org.openqa.selenium.WebDriverException: quit
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
我不知道你使用的节点url。尝试此 link 并设置集线器、节点,然后尝试您的代码,如果有效,则您的节点 url 有问题,否则请告诉我们您使用的节点 url。
我正在使用 selenium grid 和 selenium 3.4.0 版本。 tearDown()
函数出现错误(浏览器关闭但函数出错),我在 tearDown() 函数中尝试了 @After、before、suite、class 等注释,但没有工作。请指出我的错误是什么以及如何解决。
基础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();
}
}
第一个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>
错误信息:
org.openqa.selenium.WebDriverException: quit
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
我不知道你使用的节点url。尝试此 link 并设置集线器、节点,然后尝试您的代码,如果有效,则您的节点 url 有问题,否则请告诉我们您使用的节点 url。