使用java和selenium-server-standalone-2.20.0.jar自动执行以下测试。
测试因错误而崩溃:
Page title is: cheese! - Google Search
Starting browserTest
2922 [main] INFO org.apache.http.impl.client.DefaultHttpClient - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
2922 [main] INFO org.apache.http.impl.client.DefaultHttpClient - Retrying request
Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.20 seconds
Build info: version: '2.20.0', revision: '16008', time: '2012-02-27 19:03:04'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_24'
Driver info: driver.version: InternetExplorerDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:170)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:438)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:139)
at org.openqa.selenium.ie.InternetExplorerDriver.setup(InternetExplorerDriver.java:91)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:48)
at com.pwc.test.java.InternetExplorer7.browserTest(InternetExplorer7.java:34)
at com.pwc.test.java.InternetExplorer7.main(InternetExplorer7.java:27)
测试类:
package com.pwc.test.java;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import com.thoughtworks.selenium.Selenium;
public class InternetExplorer7 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver webDriver = new HtmlUnitDriver();
webDriver.get("http://www.google.com");
WebElement webElement = webDriver.findElement(By.name("q"));
webElement.sendKeys("cheese!");
webElement.submit();
System.out.println("Page title is: "+webDriver.getTitle());
browserTest();
}
public static void browserTest() {
System.out.println("Starting browserTest");
String baseURL = "http://www.mail.yahoo.com";
WebDriver driver = new InternetExplorerDriver();
driver.get(baseURL);
Selenium selenium = new WebDriverBackedSelenium(driver, baseURL);
selenium.windowMaximize();
WebElement username = driver.findElement(By.id("username"));
WebElement password = driver.findElement(By.id("passwd"));
WebElement signInButton = driver.findElement(By.id(".save"));
username.sendKeys("myusername");
password.sendKeys("magic");
signInButton.click();
driver.close();
}
}
手动启动IE7 / 8浏览器时,我没有看到任何模态对话框。可能导致这种情况的原因是什么?
答案 0 :(得分:0)
您可以通过webDriver截取屏幕截图,以便在发生此异常时查看模式对话框。
答案 1 :(得分:0)
我在Firefox上也遇到了同样的例外。我发现用户名和密码字段已自动完成,因为在Firefox中启用了“记住网站密码”选项。因此,即使我删除内容并进入录制,它也不会记录输入的数据。我禁用了该选项并重新录制了我的测试用例。现在,它运作正常。
希望它有所帮助。