Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting implicit wait timeout when using PageFactory #203

Closed
Simon-Kaz opened this issue Jun 13, 2015 · 6 comments
Closed

Setting implicit wait timeout when using PageFactory #203

Simon-Kaz opened this issue Jun 13, 2015 · 6 comments

Comments

@Simon-Kaz
Copy link

The following:
driver.manage().timeouts().implicitlyWait(0);

Doesn't affect the implicit wait - i still have to wait the time specified in Page Factory.

And the following:
PageFactory.initElements(new AppiumFieldDecorator(driver, 0, TimeUnit.SECONDS), this);

Doesn't work - my app is still waiting the originally set timeout before confirming that the element has not been found. The original set timeout was 10 seconds and this is what I see in logs:

info: [debug] Set Android implicit wait to 10000ms

@Jonahss
Copy link
Member

Jonahss commented Jun 15, 2015

@TikhomirovSergey any ideas?

@TikhomirovSergey
Copy link
Contributor

Hi!
AppiumFieldDecorator contains time out that has been set. You can try to change it this way:

afd = new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS);
PageFactory.initElements(afd, this);
//some code 
afd.resetImplicitlyWaitTimeOut(0, TimeUnit.SECONDS);

@Simon-Kaz please let me know about the result. If you are still facing the problem please provide a gist with code sample that descrides your use case. ... Still interesting. Why do you need 0-timeout?

@TikhomirovSergey
Copy link
Contributor

@Simon-Kaz @Jonahss
I have some ideas...

It seems some elements need a timeout that differs from the default. What if user would able to define it like that:

@WithTimeout(timeOut = time, timeUnit = unit)
@FindBy("your locator")
WebElement e; //waits for the rendering. Duratin is time out that has been set via @WithTimeout

@FindBy("your another locator")
WebElement e2; //waits for the rendering. Duratin is time out that has been set by default
//e.g. PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS), this);

?
What do think about this?

I wish github had a voting for some project features.

@Simon-Kaz
Copy link
Author

Sorry, just getting back to this now. My use case is that I need to set implicit wait to 0 to prevent unnecessary waiting if element is not found.

I created a custom scrolling method (borrowed a lot from uiAutomator scrolling ;) ) that takes a webElement, as the scrollTo and scrollToExact only take strings, and uiAutomator only takes UiSelector.

https://gist.github.com/Simon-Kaz/551b66e177c1063893b5

I check for visibility of element at the beginning, after scrollUpScreenLength , and after every scrollDownScreenLength.

Now, if the implicit wait is set to, for example, 5 seconds, then every time I check if the element is visible, I will have to wait 5 seconds. I want to reset that timeout so that the isElementVisible takes as little time as possible.

@TikhomirovSergey
Copy link
Contributor

@Simon-Kaz
Ок. Does it help (was time out changed?)

afd = new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS);
PageFactory.initElements(afd, this);
//some code 
afd.resetImplicitlyWaitTimeOut(0, TimeUnit.SECONDS);

and what do you think about the idea above?

@Simon-Kaz
Copy link
Author

I haven't tried that yet, I'll try this later today and report my findings ! :)

I think the additional annotation for timeout could be very useful. For example:

  • an increased timeout could be set for an element that's selected first after opening app - as the process can take much longer on older/slower devices.
  • a reduced timeout could be used for assertions ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants