Skip to content

Commit

Permalink
fix: assert_frame_ready false negative when document.readyState is 'i…
Browse files Browse the repository at this point in the history
…nteractive' #353
  • Loading branch information
scottmries committed Apr 9, 2024
1 parent 14a69be commit a1dba66
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 76 deletions.
68 changes: 0 additions & 68 deletions packages/axe-core-api/e2e/selenium/Gemfile.lock

This file was deleted.

2 changes: 0 additions & 2 deletions packages/axe-core-api/lib/axe/api/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ def within_about_blank_context(page)
end
new_handle = new_handles[0]
driver.switch_to.window new_handle


driver.get "about:blank"

ret = yield page
Expand Down
12 changes: 8 additions & 4 deletions packages/axe-core-api/lib/axe/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ def use_run_partial

def assert_frame_ready
begin
ready = Timeout.timeout(10) {
@page.evaluate_script <<-JS
document.readyState === 'complete'
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
ready = wait.until {
puts "waiting"
readyState = @page.evaluate_script <<-JS
document.readyState
JS
readyState == 'complete'
}
rescue Timeout::Error
rescue Selenium::WebDriver::Error::TimeoutError
ready = false
end

raise Exception.new "Page/frame not ready" if not ready
end

Expand Down
11 changes: 9 additions & 2 deletions packages/axe-core-api/spec/axe/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module Axe
let(:page) {
spy("page", evaluate_script: false)
}
before { allow(page).to receive(:evaluate_script).and_return(false, true, false) }

before { allow(page).to receive(:evaluate_script).and_return(false, 'complete', false) }
describe "initialize" do
# We have removed comments from `axe.min.js`, so excluding this test
# Hence cannot do start_with("/*! aXe"), instead do a function we know should exist check
Expand All @@ -25,6 +24,14 @@ module Axe
expect(page).not_to have_received(:execute_script)
end
end

context "when document.readyState is interactive" do
before { allow(page).to receive(:evaluate_script).and_return(false, 'interactive', 'interactive', 'complete') }
it "should check ready frame until complete, then proceed" do
described_class.new(page)
expect(page).to have_received(:execute_script).with(a_string_including ("axe.run="))
end
end
end

describe "call" do
Expand Down

0 comments on commit a1dba66

Please sign in to comment.