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

Make it more convenient to wait on something while reloading the page #499

Closed
ldaley opened this Issue Sep 7, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@ldaley
Member

ldaley commented Sep 7, 2017

I think it would be useful to have a waitFor like construct that refreshes the browser before each try. I think it would be the same in all other regards.

It should support nested use such as:

refreshWaitFor {
  waitFor(1) {
    // some condition
  } 
}

Based on my, somewhat hazy, understanding of how waitFor is implemented, that support for nesting would come for free.

@ldaley ldaley added the New feature label Sep 7, 2017

@erdi

This comment has been minimized.

Member

erdi commented Sep 7, 2017

To confirm that I understand what you're after, refreshWaitFor()'s implementation should be along these lines (this is obviously simplified):

public <T> T refreshWaitFor(Closure<T> block) {
    waitFor {
        browser.driver.navigate.refresh()
        block.call()
    }
}

while keeping the implicit assertions feature on the block passed to it. Is that right?

The method should only be available on Page and not on Module because modules have bases which will become stale as soon as the refresh happens.

@ldaley

This comment has been minimized.

Member

ldaley commented Sep 11, 2017

Yeah, that's basically it.

I think this method should probably on be on Browser, as Pages can have cached elements that are going to go stale. However, it's conceivable that the user is going to go on and make use of the page after doing this, so it might be beneficial to get a freshly loaded page out of it.

So perhaps…

<T extends Page> T refreshWaitFor(Class<T> pageType, Closure<?> block) {
  browser.driver.navigate.refresh()
  def page = at(pageType)
  block.call()
  page
}

Page refreshWaitFor(Closure<?> block) {
  def pageType = browser.page.class
  browser.driver.navigate.refresh()
  def page = at(pageType)
  block.call()
  page
}
@erdi

This comment has been minimized.

Member

erdi commented Mar 15, 2018

I decided against passing pages to refreshWaitFor() for it to handle navigating to them because there are 4 signatures of Browser.to() and 4 signatures of waitFor() and combining them in a meaningful way proved tricky. I went with my initial idea, hopefully it still makes things easier for you @ldaley and @timyates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment