serenity-bdd / serenity-cucumber4

Other
13 stars 10 forks source link

"timeout" not working "withTimeoutOf(Duration.of(timeout, SECONDS))" for shouldNotContainText() and shouldContainText() Methods #34

Closed bzsharm closed 3 years ago

bzsharm commented 3 years ago

Error Description:- "timeout" not working "withTimeoutOf(Duration.of(timeout, SECONDS))" for shouldNotContainText() and shouldContainText();

While using "withTimeoutOf(Duration.of(timeout, SECONDS))" for method "shouldNotContainText(String)/shouldContainText(String)" ,"timeout" duration is getting overridden by webdriver.wait.for.timeout = 30000 from the serenity.properties file instead of "timeout" parsed in the custom method created .

Version Details:-

2.1.1 4.2.0 **Example:-** public void waitUntilElementContainsText(WebElementFacade elem, String strTxt,int timeout){ elem.withTimeoutOf(Duration.of(timeout, SECONDS)).shouldNotContainText(strTxt); }
wakaleo commented 3 years ago

This is expected behaviour. You need to put withTimeoutOf() BEFORE the element variable, otherwise the timeout will be applied the first time the variable is used, ie before withTimeoutOf is called.

bzsharm commented 3 years ago

WebElementFacade elem ;

elem.withTimeoutOf(Duration.of(timeout, SECONDS))

Something like this right?

bzsharm commented 3 years ago

I used it in the same way that you advised , this is how the method looks

**public void waitUntilElementContainsText(WebElementFacade elem, String strTxt,int timeout){
elem.withTimeoutOf(Duration.of(timeout, SECONDS)).shouldNotContainText(strTxt);

}**

bzsharm commented 3 years ago

@wakaleo any thoughts

wakaleo commented 3 years ago

withTimeoutOf(Duration.of(timeout, SECONDS))...

wakaleo commented 3 years ago

It only applies to operations following the "withTimeoutOf(), not the object itself.

bzsharm commented 3 years ago

thanks for your response @wakaleo My Intention here is to make the "element wait till it contains the particular String / Text". (WebElementFacade) ! Please advise

wakaleo commented 3 years ago
withTimeoutOf(Duration.ofSeconds(10)).waitFor(ExpectedConditions.textToBe(By.cssSelector("#my-element"), "Expected Text"));
bzsharm commented 3 years ago

@wakaleo thanks for the response John !