raju
raju

Reputation: 5008

Webdriver - Error communicating with the remote browser

I am constantly getting the following error even after multiple waits etc. I am currently using firefox 26.0 and get following error. test works fine when the conditional is true but fails always gives this error if the conditional when it checks for substring in html is false. What is the reason for this weird error. I want to show correct error.

Surprisingly test works fine in my laptop(Linux mint). Server has ubuntu with 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"));

works well again

    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"));

gives following exception

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

Following is my java webdriver test

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()
}

Upvotes: 0

Views: 707

Answers (1)

user3535807
user3535807

Reputation: 268

Suppose its because of timeout issue, check Configuring timeouts

Upvotes: 1

Related Questions