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

fix: Safari noSuchWindowException and Page/Frame not ready #385

Merged
merged 9 commits into from
Apr 23, 2024

Conversation

scottmries
Copy link
Contributor

@scottmries scottmries commented Apr 9, 2024

QA Notes:

The following code occasionally caused Safari to throw a noSuchWindowException around 1 in 10 times, and I expect it never to do so now.

require "selenium-webdriver"
require_relative "../../lib/axe/api/run"
require "json"


driver = Selenium::WebDriver.for :safari
# driver.navigate.to "http://google.com"
driver.navigate.to "https://dequeuniversity.com/demo/mars/"

res = Axe::Core.new(driver).call Axe::API::Run.new.with_options

puts JSON.pretty_generate res.results.to_h

driver.quit

Note the commented # driver.navigate to "http://google.com". Issue #353 notes that attempting to navigate to http://google.com would also occasionally cause an exception "Page/Frame not ready" to be thrown; it should no longer do so.

Please uncomment this line, comment driver.navigate.to "https://dequeuniversity.com/demo/mars/" and test again. This fix is included here since they are closely related.

Closes: #352
Closes: #353

@scottmries scottmries requested a review from a team as a code owner April 9, 2024 16:14
@scottmries scottmries marked this pull request as draft April 9, 2024 16:14
@scottmries scottmries changed the title Safari nosuchwindowexception fix: Safari noSuchindowexception Apr 9, 2024
@scottmries scottmries changed the title fix: Safari noSuchindowexception fix: Safari noSuchWindowException and Page/Frame not ready Apr 9, 2024
@page.evaluate_script <<-JS
document.readyState === 'complete'
JS
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This now checks readyState repeatedly for a 'complete' state. Previously, the state would be checked once; given an 'interactive' state, assert_frame_ready would fail and never succeed, hence #353.

@scottmries scottmries force-pushed the safari-nosuchwindowexception branch from d3408fd to ca52618 Compare April 9, 2024 16:24
@scottmries scottmries marked this pull request as ready for review April 9, 2024 17:40
@scottmries scottmries force-pushed the safari-nosuchwindowexception branch from ca52618 to a1dba66 Compare April 9, 2024 18:54
@scottmries scottmries force-pushed the safari-nosuchwindowexception branch from a1dba66 to 2469099 Compare April 9, 2024 18:59
Copy link
Contributor

@Zidious Zidious left a comment

Choose a reason for hiding this comment

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

The noSuchWindowException change is looking good! I had a question on the Page/Frame not ready change inline -

Comment on lines 43 to 46
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until {
readyState = @page.evaluate_script <<-JS
document.readyState
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this has been here for a while, but have you tested if we even need this anymore? I know for Selenium they have implemented the WebDriver as per the spec which by default is set to so we should be waiting for the page finish loading before trying to inject:

An HTTP session has an associated page loading strategy, which is one of the keywords from the table of page load strategies. This is initially set to normal.

Copy link

Choose a reason for hiding this comment

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

If it's for backcompat with older selenium versions that we expect are missing that behavior, it'd be helpful to leave a comment explaining that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested removing this against both latest 3 and 4, and I didn't find any issue against either the "fast" or "slow" URLs in my repro script. I'm removing it for this reason. If I'm misunderstanding, please let me know.
It seems odd that it would work on latest 3, but there may have been a fix in place since this was first written.

@scottmries scottmries requested a review from Zidious April 22, 2024 17:41
Copy link
Contributor

@Zidious Zidious left a comment

Choose a reason for hiding this comment

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

👇

repro/repro.rb Outdated Show resolved Hide resolved
@scottmries scottmries merged commit a02013a into develop Apr 23, 2024
6 checks passed
@scottmries scottmries deleted the safari-nosuchwindowexception branch April 23, 2024 13:41
@scottmries scottmries added the next up Ticket is groomed for next sprint label Apr 23, 2024
@github-actions github-actions bot mentioned this pull request May 8, 2024
dequejenn added a commit that referenced this pull request May 8, 2024
##
[4.9.1](v4.9.0...v4.9.1)
(2024-05-08)


### Bug Fixes

* Safari noSuchWindowException and Page/Frame not ready
([#385](#385))
([a02013a](a02013a)),
closes [#353](#353)
[#352](#352)
[#353](#353)
* Update axe-core to v4.9.1
([#387](#387))
([0d32cea](0d32cea))
@dequejenn dequejenn mentioned this pull request May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next up Ticket is groomed for next sprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ruby throwing Page/Frame not ready exception Safari Ruby with the Safari driver causes noSuchWindowException
3 participants