Java Webdriver-与远程浏览器通信时出错
即使在多次等待之后,我也会不断出现以下错误。我目前使用的是firefox 26.0,并出现以下错误。当条件为true时,测试工作正常,但如果条件在检查html中的子字符串时为false,则失败时始终会给出此错误。这个奇怪错误的原因是什么。我想显示正确的错误 令人惊讶的是,该测试在我的笔记本电脑(LinuxMint)中运行良好。服务器上有ubuntu和firefox 26.0Java Webdriver-与远程浏览器通信时出错,java,selenium,webdriver,Java,Selenium,Webdriver,即使在多次等待之后,我也会不断出现以下错误。我目前使用的是firefox 26.0,并出现以下错误。当条件为true时,测试工作正常,但如果条件在检查html中的子字符串时为false,则失败时始终会给出此错误。这个奇怪错误的原因是什么。我想显示正确的错误 令人惊讶的是,该测试在我的笔记本电脑(LinuxMint)中运行良好。服务器上有ubuntu和firefox 26.0 String abc = wd.findElement(By.tagName("html")).getText()
String abc = wd.findElement(By.tagName("html")).getText();
System.out.println(abc);
if (!abc.contains("Narendra Modiii")) {
System.out.println("came here");
File scrFile = ((TakesScreenshot)wd).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("failedscreenshot.png"));
又能正常工作了
String abc = wd.findElement(By.tagName("html")).getText();
System.out.println(abc);
if (!abc.contains("Narendra Modiii")) {
// System.out.println("came here");
File scrFile = ((TakesScreenshot)wd).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("failedscreenshot.png"));
给出了以下例外情况
Jun 04, 2014 10:20:55 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
Jun 04, 2014 10:20:55 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
下面是我的JavaWebDriver测试
public class classqb8ksladhq {
public static void main(String[] args) {
FirefoxDriver wd = null;
try {
String Xport = System.getProperty("lmportal.xvfb.id", ":1");
final File firefoxPath = new File(System.getProperty("lmportal.deploy.firefox.path",
"/usr/bin/firefox"));
FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
wd = new FirefoxDriver(firefoxBinary, null);
wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
wd.get("http://dev.scroll.in/");
wd.findElement(By.xpath("//div[@class='searchbox']/input")).click();
Thread.sleep(5*1000);
wd.findElement(By.xpath("//div[@class='searchbox']/input")).clear();
Thread.sleep(5*1000);
wd.findElement(By.xpath("//div[@class='searchbox']/input")).sendKeys("bjp");
Thread.sleep(60*1000);
if (!wd.findElement(By.tagName("html")).getText().contains("zzzzzzzz")) {
File scrFile = ((TakesScreenshot)wd).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("failedscreenshot.png"));
throw new RuntimeException("!wd.findElement(By.tagName(\"html\")).getText().contains(\"Narendra Modiii\") is false");
}
System.out.println("Test ran successfully.");
}
catch (Exception e) {
try{
File scrFile = ((TakesScreenshot)wd).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("failedscreenshot.png"));
e.printStackTrace();
} catch(Exception e1) {
}
}
}
//wd.quit()
}
假设是由于超时问题,请检查wd.findElement(By.tagName(“html”))。getText()contains(“zzzzzz”)导致问题。我是否对浏览器进行了太多调用,导致浏览器没有响应?以及Thread.sleep(60*1000)以上。线程正在睡觉,但当它醒来时,它可能已经死了(c)。尝试尝试使用hub的'-timeout'或'-browserTimeout'更新问题,因为无法在注释中添加所有内容。在屏幕截图期间出现问题。在新服务器中安装ubuntu12.04并开始在该服务器中运行后,我没有遇到任何问题。我假设webdriver版本、firefox版本和ubuntu14的组合导致了这个问题。