我已经编写了一些selenium代码来测试使用Testng + webdriver的Web应用程序。 我有一个集线器和一个节点,我用符文firefox + chrome和一个Android平板电脑运行android测试。
我可以逐个运行android测试但是当我作为testng套件的一部分运行时,我遇到了以下问题:
即使我在@aftertest注释中调用driver.quit(),每次测试后android浏览器都没有关闭。在我的一个测试中:
public class LanguageCheckEN {
WebDriver driverEN, driverFR;
String BaseURL, winURL, TestURL, andURL;
@BeforeTest
@Parameters({ "browser" })
public void setup(String browser) throws IOException
{
File file = new File("config.properties");
FileInputStream fileInput = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fileInput);
fileInput.close();
TestURL = properties.getProperty("AppURL");
BaseURL = properties.getProperty("HubURL");
winURL = properties.getProperty("WinURL");
andURL = properties.getProperty("AndURL");
DesiredCapabilities capability = null;
if (browser.equalsIgnoreCase("firefox")) {
System.out.println("firefox");
capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(Platform.WINDOWS);
// capability.setVersion("");
driverEN = new RemoteWebDriver(new URL(winURL), capability);
}
if (browser.equalsIgnoreCase("chrome")) {
System.out.println("chrome");
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setPlatform(Platform.WINDOWS);
driverEN = new RemoteWebDriver(new URL(winURL), capability);
// capability.setVersion("");
}
if (browser.equalsIgnoreCase("android")) {
System.out.println("android");
capability = DesiredCapabilities.android();
capability.setBrowserName("android");
capability.setPlatform(Platform.ANDROID);
driverEN = new RemoteWebDriver(new URL(andURL), capability);
// capability.setVersion("");
}
}
@Test
private void checkLanguageEN() {
driverEN.get(TestURL);
WebElement input1 = driverEN
.findElement(By.id("login_form_user_input"));
input1.sendKeys("guest");
WebElement input2 = driverEN.findElement(By
.id("login_form_password_input"));
input2.sendKeys("guest");
WebElement btn = driverEN
.findElement(By.id("login_form_signin_button"));
btn.click();
WebElement img = driverEN.findElement(By.id("header_language_button"));
String lng = img.getText();
if (lng.equals("en"))
{
WebDriverWait wait = new WebDriverWait(driverEN, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.linkText("Calendar Search")));
}
else
{
img.click();
WebDriverWait wait = new WebDriverWait(driverEN, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.linkText("Calendar Search")));
}
}
@AfterTest
private void quitTest() {
driverEN.close();
}
public void aftertest()
{
quitTest();
}
}
这也是我的testng.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Dollar Universe Explorer E2E Testing" thread-count="3" parallel="tests" >
<test name="Language English Chrome">
<parameter name="browser" value="chrome" />
<classes>
<class name="basicWebElements.LanguageCheckEN" />
</classes>
</test>
<test name="Language English firefox">
<parameter name="browser" value="firefox" />
<classes>
<class name="basicWebElements.LanguageCheckEN" />
</classes>
</test>
<test name="Language English android">
<parameter name="browser" value="android" />
<classes>
<class name="basicWebElements.LanguageCheckEN" />
</classes>
</test>
</suite>
由于这个问题,当我运行整个套件时,我收到此错误:
org.openqa.selenium.remote.UnreachableBrowserException:与远程浏览器通信时出错。它可能已经死了。
感谢您的帮助。
答案 0 :(得分:1)
答案如下:
Android now whinges when you destroy an activity that has view that you
没有与它断开连接
WebView webview = (WebView) findViewById(R.id.webview);
if (webview != null)
{
webview.removeAllViews();
webview.destroy();
}
WebView rssWebView = (WebView) findViewById(R.id.rssWebView);
if (rssWebView != null)
{
rssWebView.removeAllViews();
rssWebView.destroy();
}
onDestroy中需要才能停止抱怨