axe-core-api 2.6.1.pre.0f0b25b

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ require "dumb_delegator"
2
+
3
+ module WebDriverScriptAdapter
4
+ class FrameAdapter < ::DumbDelegator
5
+ def self.wrap(driver)
6
+ if driver.respond_to?(:within_frame)
7
+ CapybaraAdapter.new driver
8
+ elsif !driver.respond_to?(:switch_to)
9
+ WatirAdapter.new driver
10
+ elsif driver.switch_to.respond_to?(:parent_frame)
11
+ SeleniumAdapter.new driver # add within_frame to selenium
12
+ else
13
+ ParentlessFrameAdapter.new driver # old selenium doesn't support parent_frame
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ class CapybaraAdapter < ::DumbDelegator
20
+ def find_frames
21
+ all(:css, "iframe")
22
+ end
23
+ end
24
+
25
+ class WatirAdapter < ::DumbDelegator
26
+ # delegate to Watir's Selenium #driver
27
+ def within_frame(frame, &block)
28
+ SeleniumAdapter.instance_method(:within_frame).bind(FrameAdapter.wrap driver).call(frame, &block)
29
+ end
30
+
31
+ def find_frames
32
+ driver.find_elements(:css, "iframe")
33
+ end
34
+ end
35
+
36
+ class SeleniumAdapter < ::DumbDelegator
37
+ def within_frame(frame)
38
+ switch_to.frame(frame)
39
+ yield
40
+ ensure
41
+ begin
42
+ switch_to.parent_frame
43
+ rescue => e
44
+ if /switchToParentFrame|frame\/parent/.match(e.message)
45
+ ::Kernel.warn "WARNING:
46
+ This browser only supports first-level iframes.
47
+ Second-level iframes and beyond will not be audited.
48
+ To skip auditing all iframes,
49
+ set Axe::Configuration#skip_iframes=true"
50
+ end
51
+ switch_to.default_content
52
+ end
53
+ end
54
+
55
+ def find_frames
56
+ find_elements(:css, "iframe")
57
+ end
58
+ end
59
+
60
+ # Selenium Webdriver < 2.43 doesnt support moving back to the parent
61
+ class ParentlessFrameAdapter < ::DumbDelegator
62
+ # storage of frame stack (for reverting to parent) taken from Capybara
63
+ # : https://github.com/jnicklas/capybara/blob/2.6.2/lib/capybara/selenium/driver.rb#L117-L147
64
+ #
65
+ # There doesnt appear to be any way in Selenium Webdriver < 2.43 to move back to a parent frame
66
+ # other than going back to the root and then reiterating down
67
+ def within_frame(frame)
68
+ @frame_stack[window_handle] ||= []
69
+ @frame_stack[window_handle] << frame
70
+
71
+ switch_to.frame(frame)
72
+ yield
73
+ ensure
74
+ @frame_stack[window_handle].pop
75
+ switch_to.default_content
76
+ @frame_stack[window_handle].each { |f| switch_to.frame(f) }
77
+ end
78
+ end
79
+
80
+ def find_frames
81
+ find_elements(:css, "iframe")
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,17 @@
1
+ require 'dumb_delegator'
2
+
3
+ module WebDriverScriptAdapter
4
+ class QuerySelectorAdapter < ::DumbDelegator
5
+ def self.wrap(driver)
6
+ # capybara: all(<tag>) but also seems to support all(:css, <tag>)
7
+ # watir: elements(:css); also supports #iframes
8
+ # selenium: find_elements(:css, <tag>); aliased as all
9
+
10
+ driver.respond_to?(:find_elements) ? driver : new(driver)
11
+ end
12
+
13
+ def find_elements(*args)
14
+ respond_to?(:elements) ? elements(*args) : all(*args)
15
+ end
16
+ end
17
+ end