即使经过多次等待,我也不断收到以下错误。我目前正在使用firefox 26.0并收到以下错误。当条件为真时,测试工作正常但是如果在html中检查子字符串时的条件为假,则失败总是会出现此错误。造成这种奇怪错误的原因是什么?我想表明正确的错误。
令人惊讶的是,我的笔记本电脑(Linux mint)测试工作正常。服务器有ubuntu和firefox 26.0
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
以下是我的java webdriver测试
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()
}