Reputation: 221
I have a scenario where I have 29 test cases. All the test cases pop-up new firefox windows and run to completion when run independently. However when I combine the test cases(all 29) into a test suite, I get random errors of "unable to locate element". If I run the test suite multiple times, I can see different test cases fail at different places, randomly. Note- I am waiting for every elements visibility for around 100 seconds, before clicking on them. Code looks like-
WebElement myDynamicElement = (new WebDriverWait(driver, 100))
.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return driver.findElement(element);
}
Could someone advice? Are smaller test suites recommended?
Upvotes: 0
Views: 479
Reputation: 7339
not so far come across with a similar problem type.
IMHO try to use a lil bit more robust wait mechanism fluentWait
:
public WebElement fluentWait(final By locator){
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(org.openqa.selenium.NoSuchElementException.class);
WebElement foo = wait.until(
new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(locator);
}
}
);
return foo; } ;
here is documentation on fluent wait
usage be like :
String cssSelectorElement ="blablablab";
String xPathElement = "balblabla";
fluentWait(By.cssSelector(cssSelectorElement)).click()
//fluentWait(By.cssSelector(cssSelectorElement)).getText();
fluentWait(By.xpath(xPathElement)).click()
//fluentWait(By.xpath(xPathElement)).getText();
Don't forget about step by step debug in IDE(IDEA, Eclipse,NetBeans) you work.
Upvotes: 1