-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
fix flaky Ruby test element_spec.rb
#16709
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
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
6cc333a to
122a21a
Compare
Wait until the new URL gets loaded.
Sometimes after executing `driver.navigate.to url_for('new_page.html')` the browser is still showing the previous page.
Example of failure:
```ruby
Selenium::WebDriver::Element raises if different element receives click
Failure/Error: element = wait_for_element(id: 'contents', timeout: 10)
Selenium::WebDriver::Error::TimeoutError:
could not find element {:id=>"contents", :timeout=>10} in 25 seconds;
page url: http://localhost:49887/resultPage.html?x=25&y=25;
page source:
<p id="greeting">Success!</p> ...
# ./rb/lib/selenium/webdriver/common/wait.rb:76:in `until'
# /Users/runner/work/selenium/selenium/rb/spec/integration/selenium/webdriver/spec_support/helpers.rb:93:in `wait_for_element'
# ./rb/spec/integration/selenium/webdriver/element_spec.rb:35:in `block (2 levels) in <module:WebDriver>'
```
See https://github.com/SeleniumHQ/selenium/actions/runs/20055175531/job/57520193372#step:19:920 for example.
122a21a to
718eb0d
Compare
It's a good practice to avoid tests affecting each other: 1. Open "about:blank" page - this stops any current activity / background requests / animations on the previous page 2. Open an empty page which clears sessionStorage, localStorage and cookies. This technique allows reusing the browser between tests, while keeping the tests independent.
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
User description
Wait until the new URL gets loaded.
Sometimes after executing
driver.navigate.to url_for('new_page.html')the browser is still showing the previous page.Example of failure:
See https://github.com/SeleniumHQ/selenium/actions/runs/20055175531/job/57520193372#step:19:920 for example.
💥 What does this PR do?
This PR adds a waiting for the new URL.
💡 Additional Considerations
Currently I did it only for one test file (that often fails).
Maybe it should be applied to all ruby tests...
🔄 Types of changes
PR Type
Bug fix
Description
Replace direct navigation with
open_filehelper for test isolationAdd blank page navigation to clear storage and stop background activity
Improve
wait_for_urlwith longer timeout and better error messagesCreate
open_filehelper method to standardize page loading in testsDiagram Walkthrough
File Walkthrough
element_spec.rb
Standardize page navigation using open_file helperrb/spec/integration/selenium/webdriver/element_spec.rb
driver.navigate.to url_for()calls with newopen_filehelper method
isolation
helpers.rb
Add open_file helper and improve wait timeoutsrb/spec/integration/selenium/webdriver/spec_support/helpers.rb
open_filehelper method that navigates through blank pagesbefore target page
wait_for_urltimeout from 5 to 15 seconds with improved errormessaging
wait_for_titletimeout from 5 to 15 seconds for consistencywait_for_urlfor better debugging informationblank.html
Add storage clearing to blank pagecommon/src/web/blank.html
load