Skip to content

Improve waiting behavior#194

Merged
tlconnor merged 3 commits intomasterfrom
pkImproveWaiting
Oct 28, 2016
Merged

Improve waiting behavior#194
tlconnor merged 3 commits intomasterfrom
pkImproveWaiting

Conversation

@pkmiec
Copy link
Copy Markdown
Contributor

@pkmiec pkmiec commented Oct 28, 2016

There are 2 main problems with AePageObjects making it prone to flakiness,

  • The page polling in AePageObjects uses Capybara.using_wait_time(0) preventing Capybara from retrying errors and reloading nodes. The page polling also does not catch any errors itself causing exceptions to be potentially raised prior to waiting the asked for time. The page polling is used browser.find_document, window.change_to, and absent? / present? / and friends on element proxy.
  • The ensure_loaded! is difficult to write / reason about as it is sometimes called inside of page polling block (see above) and sometimes it is not. This means that implementors have to know about all the exceptions that should be caught and using AePageObjects#wait_until is not good because it can blocks for longer than what is intended by page polling.

This PR improves AePageObjects by,

  • Removing PagePolling and instead solely relying on the improved #wait_until. It now rescues and retries all relevant selenium / capybara / ae_page_objects exceptions. It only throws 'WaitTimeoutError' (which includes the original cause) making it easy for user to rescue errors. It lowers Capybara's default time allowing capybara to retry / reload, but also allowing errors to be handled at the higher level (and thus another chance to success). It allows itself to be called multiple times which the top-level invocation being in charge of the timeout.
  • The ensure_loaded! now calls is_loaded? which is meant to quickly return an answer. Subclasses should override is_loaded? now, but no waiting / rescuing is needed.
  • Removed #all / #find from being delegated to Capybara node. These return Capybara nodes (and in case of all not reloadable once) and it is better to be explicit about their use. Also avoids confusion with #find provided by AePageObjects::Colleciton.

Copy link
Copy Markdown

@tlconnor tlconnor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a few small things, but otherwise this looks good to go.

@@ -1,53 +0,0 @@
module AePageObjects
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these file removals meant to be part of this commit or the next?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that got messed up a bit. I squashed most of it together now with a better msg.

Comment thread lib/ae_page_objects.rb
def wait_until(seconds_to_wait = nil, error_message = nil)
seconds_to_wait ||= default_max_wait_time
start_time = Time.now
def wait_until(seconds_to_wait = nil, error_message = nil, &block)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've called this commit pk - passing tests but really this one contains the bulk of the changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded the commit msg.

Comment thread lib/ae_page_objects.rb Outdated
def wait_until(seconds_to_wait = nil, error_message = nil, &block)
@wait_until ||= 0
@wait_until += 1
# start_time = Time.now
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these commented lines needed anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Comment thread lib/ae_page_objects.rb Outdated

result
ensure
# puts "#{"--" * @wait_until} wait_until => #{Time.now - start_time}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment thread lib/ae_page_objects/version.rb Outdated
@@ -1,3 +1,3 @@
module AePageObjects
VERSION = '2.1.0'.freeze
VERSION = '2.0.1'.freeze
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the version number decreased? Given the API changes we'll need a major version number, making this 3.0.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. This should not have changed here. Once it is merged, we can bump to 3.0, update changelog, and release.

@@ -1,5 +1,6 @@
ENV['RAILS_ENV'] = 'test'

puts $LOAD_PATH
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to remove this 😃

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@tlconnor tlconnor merged commit 7f4e4b6 into master Oct 28, 2016
@tlconnor tlconnor deleted the pkImproveWaiting branch October 28, 2016 22:32
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

Successfully merging this pull request may close these issues.

2 participants