I currently have the following setup, but I'm not sure that my waits (Implicit and pageLoadTimeout) are working. Is this the proper implementation? By putting it in the @Before("@setup"), does it work for every Scenario or Step Definition run? Will the driver wait accordingly, everytime I call a @Given, @When..etc?
@Before("@setup")
public void setUp() {
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
}
Why is it necessary to assign a WebElement to the following wait , what does WebElement element receive? Is this the right implementation? -
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(id)));
boolean status = element.isDisplayed();
If you just started to use selenium, is a legit question. I always suggest to have a look to the official doc.
Example:
In this case, if the web element with id myDynamicElement is not present in the DOM when you try to locate it, you are saying to re-try until 10 seconds. The polling time depends on the webdriver that you are using. The thing that you have to know is that it will try to find the element for 10 seconds. Of course, if the element is located before the end of this time, the code will go on. Otherwise, an exception is thrown.
Example:
And, at the end, there is written: This example is also functionally equivalent to the first Implicit Waits example.
So, if you use presenceOfElementLocated as expected condition (for each elements that you try to locate), is exactly the same to use an implicit wait. But there isn't only this as condition. As you can see from ExpectedConditions you can specify other conditions (example: elementToBeClickable, stalenessOf and so on).
So, returning to your question:
With
you are saying to wait, whenever you try lo locate an element, the presence (remember, it's like presenceOfElementLocated) until 30 seconds.
With
you are setting to 30 seconds the time that a webpage needs to be loaded.
With:
You are saying that you want to wait the visibilityOfElementLocated, of the web element with id:"id", until 30 seconds.
Finally:
What does the WebElement element receive? what else if not the webelement with id:"id"? Of course, if it's visible. Otherwise, an exception will be thrown.