Fix few more flaky ruby tests#16695
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:
|
||||||||||||
275cf06 to
92fbd13
Compare
830dd21 to
a7512f2
Compare
Wait until the page gets loaded and the element ges rendered.
Example of failure:
```ruby
Selenium::WebDriver::Element raises if different element receives click
Failure/Error: expect { driver.find_element(id: 'contents').click }.to raise_error(Error::ElementClickInterceptedError)
expected Selenium::WebDriver::Error::ElementClickInterceptedError, got #<Selenium::WebDriver::Error::NoSuchElementError:"no such element: Unable to locate element: {\"metho...it: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#nosuchelementexception"> with backtrace:
# ./rb/lib/selenium/webdriver/remote/response.rb:63:in `add_cause'
# ./rb/lib/selenium/webdriver/remote/response.rb:41:in `error'
# ./rb/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
# ./rb/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
# ./rb/lib/selenium/webdriver/remote/http/common.rb:103:in `new'
# ./rb/lib/selenium/webdriver/remote/http/common.rb:103:in `create_response'
# ./rb/lib/selenium/webdriver/remote/http/default.rb:103:in `request'
# ./rb/lib/selenium/webdriver/remote/http/common.rb:68:in `call'
# ./rb/lib/selenium/webdriver/remote/bridge.rb:625:in `execute'
# ./rb/lib/selenium/webdriver/remote/bridge.rb:493:in `find_element_by'
# ./rb/lib/selenium/webdriver/common/search_context.rb:71:in `find_element'
# ./rb/spec/integration/selenium/webdriver/element_spec.rb:34:in `block (3 levels) in <module:WebDriver>'
# ./rb/spec/integration/selenium/webdriver/element_spec.rb:34:in `block (2 levels) in <module:WebDriver>'
# ./rb/spec/integration/selenium/webdriver/element_spec.rb:34:in `block (2 levels) in <module:WebDriver>'
```
See https://github.com/SeleniumHQ/selenium/actions/runs/19987626355/job/57324241360?pr=13739 for example.
instead of sleeping for 0.5s, just wait for the needed URL. NB! The previous helper method `wait_for_new_url(old_url)` caused flaky tests because in Firefox, browsers changes URLs like this: "<old url>" -> "about:blank" -> "<new url>".
instead of sleeping for 2.5s, just wait for the needed logs.
a7512f2 to
6efb912
Compare
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
🔗 Related Issues
e.g. failed build: https://github.com/SeleniumHQ/selenium/actions/runs/19987626355/job/57324241360?pr=13739
💥 What does this PR do?
Fixes few flaky Ruby tests
🔧 Implementation Notes
This PR adds few "waits" to Ruby tests.
🔄 Types of changes
PR Type
Bug fix, Tests
Description
Adds
message_provideroption to Wait class for better error messagesReplaces hardcoded sleeps with proper wait conditions in Ruby tests
Improves
wait_for_elementhelper with timeout parameter and detailed error outputRefactors devtools and element specs to use wait helpers instead of sleep
Diagram Walkthrough
File Walkthrough
wait.rb
Add message_provider option to Wait classrb/lib/selenium/webdriver/common/wait.rb
message_provideroption to constructor for custom error messagegeneration
untilmethod to callmessage_provider.callwhen providedhelpers.rb
Improve wait helpers with better error messages and flexibilityrb/spec/integration/selenium/webdriver/spec_support/helpers.rb
wait_for_elementwith optional timeout parameter and detailederror messages
message_providerlambda that includes page URL and HTML source ontimeout
wait_for_new_urltowait_for_urlwith simplified logicwait_for_titlehelper method for title-based waitselement_spec.rb
Replace direct element finding with wait helpersrb/spec/integration/selenium/webdriver/element_spec.rb
find_elementcalls withwait_for_elementhelperthroughout
sleepcalls and replaces withwait_for_urlhelperwait_for_elementfor element clickintercepted test
are rendered
devtools_spec.rb
Remove sleeps and improve log event test reliabilityrb/spec/integration/selenium/webdriver/devtools_spec.rb
log.args[0]instead of full logobject
wait.untilcondition to ensure all logs are collected beforeassertions