Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

Command waitForElementPresent when exported as java waits for default timeout * 60 Seconds #8562

@lukeis

Description

@lukeis

Originally reported on Google Code with ID 8562



What steps will reproduce the problem?
1. Record a test case in IDE with one waitForElementPresent command.
2. Export this test case as Java/Junit/WebDriver.
3. Run the test case.

What is the expected output?

When the element is not present it should wait for 60 seconds and fail.

 What do you see instead?

When the element is not present it is waiting for (60*30 = 1800) seconds and then fail.


Selenium version:2.44.0
OS: Windows8
Browser:All
Browser version:


Note: When the file is exported as java, the @Before method contains the implicit timeouts
of 30 seconds. The formatted code for waitForElementPresent contains a loop which iterates
60 seconds. But for each iteration isElementPresent method will wait for 30 seconds
and hence the timeout time is (60*30 = 1800) seconds.


I think the for loop should iterate only twice then after (2* 30 = 60) seconds time
out will occur. 


Exported Test case:
package com.autorabit.tests;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.junit.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class JavaFormatterTest {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://www.google.co.in/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void example() throws Exception {
        driver.get(baseUrl + "/");
        for (int second = 0;; second++) {
        if (second >=60) fail("timeout");
        try {   
            if (isElementPresent(By.xpath("//li[@id='xpath_which_is_not_present']"))) break;
} catch (Exception e) {}
        }
        Thread.sleep(1000);
    }
  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}


Reported by shaikh.arifullah on 2015-03-04 10:58:45

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions