axe-core-api 4.7.0.pre.5cb81f7 → 4.7.0.pre.a4597d5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/axe/api/run.rb +48 -31
  3. data/lib/axe/core.rb +15 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63159393301b9412aef8c4985d721bb4296316866a8cbc05a8465fa40077fcb2
4
- data.tar.gz: e0e8b4c76b4f1a512ab415a22c4dc373a3eae9a898a7067dd1aed02a977ee61b
3
+ metadata.gz: 4ef01ebd003d7ecdfc4c7dc8dc84df26c04d9528608a0983e7d96fc4c5b7d792
4
+ data.tar.gz: 74c53e8a1426b341ed99bd084f9ce71cb29da9a8e7ee89b130a32ff594269c08
5
5
  SHA512:
6
- metadata.gz: e62475b52597c15a2f5dcaefffbf7d457fae86a6a03c19aee013234a19ce15f80c2f33000f57cb4ab683731b899eb1d9e4a6d85569fd80a63f051d338ad87b69
7
- data.tar.gz: 501a16eb84da7b92075645d84f1f40b05eaeaf7568abd4c423455b72db2231289f8121a1d8195464fd0236e2f9b0a7eb6e59a775efdad79f4477851571e37e5e
6
+ metadata.gz: '03919852ac12762a4f6c079659c9b85e0cfb600440faa7c057ebf4620dcb876b16c921579ab38990982391a762abd529678d93d95399774f6958c9bf567c9f53'
7
+ data.tar.gz: 204df2debeb78194be81ae99def82aa41e130fc127298953e0c8714988d7aae71b9eb422a52aa9bf0dc0686dabe5c31ae45233f12360d1fd5bc391bba021cfab
data/lib/axe/api/run.rb CHANGED
@@ -32,27 +32,34 @@ module Axe
32
32
  end
33
33
 
34
34
  def analyze_post_43x(page, lib)
35
- @original_window = window_handle page
36
- partial_results = run_partial_recursive(page, @context, lib, true)
37
- throw partial_results if partial_results.respond_to?("key?") and partial_results.key?("errorMessage")
38
- results = within_about_blank_context(page) { |page|
39
- partial_res_str = partial_results.to_json
40
- size_limit = 10_000_000
41
- while not partial_res_str.empty? do
42
- chunk_size = size_limit
43
- chunk_size = partial_res_str.length if chunk_size > partial_res_str.length
44
- chunk = partial_res_str[0..chunk_size-1]
45
- partial_res_str = partial_res_str[chunk_size..-1]
46
- store_chunk page, chunk
47
- end
48
-
49
- Common::Loader.new(page, lib).load_top_level Axe::Configuration.instance.jslib
50
- begin
51
- axe_finish_run page
52
- rescue
53
- raise StandardError.new "axe.finishRun failed. Please check out https://github.com/dequelabs/axe-core-gems/blob/develop/error-handling.md"
54
- end
55
- }
35
+ user_page_load = (get_selenium page).manage.timeouts.page_load
36
+ (get_selenium page).manage.timeouts.page_load = 1
37
+ begin
38
+ @original_window = window_handle page
39
+ partial_results = run_partial_recursive(page, @context, lib, true)
40
+ throw partial_results if partial_results.respond_to?("key?") and partial_results.key?("errorMessage")
41
+ results = within_about_blank_context(page) { |page|
42
+ partial_res_str = partial_results.to_json
43
+ size_limit = 10_000_000
44
+ while not partial_res_str.empty? do
45
+ chunk_size = size_limit
46
+ chunk_size = partial_res_str.length if chunk_size > partial_res_str.length
47
+ chunk = partial_res_str[0..chunk_size-1]
48
+ partial_res_str = partial_res_str[chunk_size..-1]
49
+ store_chunk page, chunk
50
+ end
51
+
52
+ Common::Loader.new(page, lib).load_top_level Axe::Configuration.instance.jslib
53
+ begin
54
+ axe_finish_run page
55
+ rescue
56
+ raise StandardError.new "axe.finishRun failed. Please check out https://github.com/dequelabs/axe-core-gems/blob/develop/error-handling.md"
57
+ end
58
+
59
+ }
60
+ ensure
61
+ (get_selenium page).manage.timeouts.page_load = user_page_load
62
+ end
56
63
  Audit.new to_js, Results.new(results)
57
64
  end
58
65
 
@@ -108,15 +115,15 @@ module Axe
108
115
  page.current_window_handle
109
116
  end
110
117
 
111
- def run_partial_recursive(page, context, lib, top_level = false)
118
+ def run_partial_recursive(page, context, lib, top_level = false, frame_stack = [])
112
119
  begin
120
+ current_window_handle = window_handle page
113
121
  if not top_level
114
122
  begin
115
123
  Common::Loader.new(page, lib).load_top_level Axe::Configuration.instance.jslib
116
124
  rescue
117
125
  return [nil]
118
126
  end
119
-
120
127
  end
121
128
 
122
129
  frame_contexts = get_frame_context_script page
@@ -126,20 +133,30 @@ module Axe
126
133
  end
127
134
 
128
135
  res = axe_run_partial page, context
129
- if res.key?("errorMessage")
130
- throw res if top_level
136
+ if res.nil? || res.key?("errorMessage")
137
+ if top_level
138
+ throw res unless res.nil?
139
+ throw "axe.runPartial returned null"
140
+ end
131
141
  return [nil]
132
142
  else
133
143
  results = [res]
134
144
  end
135
145
 
136
146
  for frame_context in frame_contexts
137
- frame_selector = frame_context["frameSelector"]
138
- frame_context = frame_context["frameContext"]
139
- frame = axe_shadow_select page, frame_selector
140
- switch_to_frame_by_handle page, frame
141
- res = run_partial_recursive page, frame_context, lib
142
- results += res
147
+ begin
148
+ frame_selector = frame_context["frameSelector"]
149
+ frame_context = frame_context["frameContext"]
150
+ frame = axe_shadow_select page, frame_selector
151
+ switch_to_frame_by_handle page, frame
152
+ res = run_partial_recursive page, frame_context, lib, false, [*frame_stack, frame]
153
+ results += res
154
+ rescue Selenium::WebDriver::Error::TimeoutError
155
+ page = get_selenium page
156
+ page.switch_to.window current_window_handle
157
+ frame_stack.each {|frame| page.switch_to.frame frame }
158
+ results.push nil
159
+ end
143
160
  end
144
161
 
145
162
  ensure
data/lib/axe/core.rb CHANGED
@@ -3,6 +3,7 @@ require_relative "../webdriver_script_adapter/frame_adapter"
3
3
  require_relative "../webdriver_script_adapter/query_selector_adapter"
4
4
  require_relative "../loader"
5
5
  require_relative "./configuration"
6
+ require 'timeout'
6
7
 
7
8
  module Axe
8
9
  class Core
@@ -37,8 +38,22 @@ module Axe
37
38
  Core.has_run_partial?(@page) and not Axe::Configuration.instance.legacy_mode
38
39
  end
39
40
 
41
+ def assert_frame_ready
42
+ begin
43
+ ready = Timeout.timeout(10) {
44
+ @page.evaluate_script <<-JS
45
+ document.readyState === 'complete'
46
+ JS
47
+ }
48
+ rescue Timeout::Error
49
+ ready = false
50
+ end
51
+ raise Exception.new "Page/frame not ready" if not ready
52
+ end
53
+
40
54
  def load_axe_core(source)
41
55
  return if already_loaded?
56
+ assert_frame_ready
42
57
  loader = Common::Loader.new(@page, self)
43
58
  loader.load_top_level source
44
59
  return if use_run_partial
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axe-core-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.0.pre.5cb81f7
4
+ version: 4.7.0.pre.a4597d5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deque Systems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-16 00:00:00.000000000 Z
11
+ date: 2023-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dumb_delegator