bauxite 0.6.18 → 0.6.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +293 -293
- data/Rakefile +128 -128
- data/bin/bauxite +27 -27
- data/doc/Bauxite.html +6 -9
- data/doc/Bauxite/Action.html +298 -315
- data/doc/Bauxite/ActionModule.html +23 -26
- data/doc/Bauxite/Application.html +36 -38
- data/doc/Bauxite/Context.html +303 -303
- data/doc/Bauxite/Errors.html +6 -9
- data/doc/Bauxite/Errors/AssertionError.html +6 -9
- data/doc/Bauxite/Errors/FileNotFoundError.html +6 -9
- data/doc/Bauxite/Errors/FormatError.html +6 -9
- data/doc/Bauxite/Loggers.html +6 -9
- data/doc/Bauxite/Loggers/CompositeLogger.html +29 -32
- data/doc/Bauxite/Loggers/EchoLogger.html +10 -13
- data/doc/Bauxite/Loggers/FileLogger.html +25 -28
- data/doc/Bauxite/Loggers/HtmlLogger.html +99 -102
- data/doc/Bauxite/Loggers/NullLogger.html +16 -19
- data/doc/Bauxite/Loggers/ReportLogger.html +43 -46
- data/doc/Bauxite/Loggers/TerminalLogger.html +76 -79
- data/doc/Bauxite/Loggers/XtermLogger.html +28 -31
- data/doc/Bauxite/Parser.html +87 -89
- data/doc/Bauxite/ParserModule.html +19 -22
- data/doc/Bauxite/Selector.html +99 -105
- data/doc/Bauxite/SelectorModule.html +27 -30
- data/doc/README_md.html +117 -103
- data/doc/created.rid +58 -58
- data/doc/fonts.css +167 -167
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +117 -103
- data/doc/js/darkfish.js +32 -11
- data/doc/js/jquery.js +0 -0
- data/doc/js/navigation.js +0 -0
- data/doc/js/search.js +0 -0
- data/doc/js/search_index.js +1 -1
- data/doc/js/searcher.js +0 -0
- data/doc/rdoc.css +580 -580
- data/doc/table_of_contents.html +69 -72
- data/lib/bauxite.rb +28 -28
- data/lib/bauxite/actions/alias.rb +51 -51
- data/lib/bauxite/actions/assert.rb +49 -49
- data/lib/bauxite/actions/asserth.rb +60 -60
- data/lib/bauxite/actions/assertm.rb +49 -49
- data/lib/bauxite/actions/assertv.rb +40 -40
- data/lib/bauxite/actions/assertw.rb +47 -47
- data/lib/bauxite/actions/break.rb +39 -39
- data/lib/bauxite/actions/capture.rb +61 -61
- data/lib/bauxite/actions/click.rb +36 -36
- data/lib/bauxite/actions/debug.rb +103 -103
- data/lib/bauxite/actions/doif.rb +43 -43
- data/lib/bauxite/actions/dounless.rb +43 -43
- data/lib/bauxite/actions/echo.rb +36 -36
- data/lib/bauxite/actions/exec.rb +46 -46
- data/lib/bauxite/actions/exit.rb +35 -35
- data/lib/bauxite/actions/failif.rb +52 -52
- data/lib/bauxite/actions/js.rb +41 -41
- data/lib/bauxite/actions/load.rb +49 -49
- data/lib/bauxite/actions/open.rb +35 -35
- data/lib/bauxite/actions/params.rb +40 -40
- data/lib/bauxite/actions/replace.rb +37 -37
- data/lib/bauxite/actions/reset.rb +38 -38
- data/lib/bauxite/actions/return.rb +68 -68
- data/lib/bauxite/actions/ruby.rb +58 -58
- data/lib/bauxite/actions/select.rb +48 -48
- data/lib/bauxite/actions/set.rb +39 -39
- data/lib/bauxite/actions/setif.rb +44 -44
- data/lib/bauxite/actions/source.rb +44 -44
- data/lib/bauxite/actions/store.rb +38 -38
- data/lib/bauxite/actions/submit.rb +37 -37
- data/lib/bauxite/actions/test.rb +67 -67
- data/lib/bauxite/actions/tryload.rb +71 -71
- data/lib/bauxite/actions/wait.rb +38 -38
- data/lib/bauxite/actions/write.rb +44 -44
- data/lib/bauxite/application.rb +349 -349
- data/lib/bauxite/core/action.rb +199 -199
- data/lib/bauxite/core/context.rb +791 -791
- data/lib/bauxite/core/errors.rb +41 -41
- data/lib/bauxite/core/logger.rb +169 -169
- data/lib/bauxite/core/parser.rb +85 -85
- data/lib/bauxite/core/selector.rb +152 -152
- data/lib/bauxite/loggers/composite.rb +91 -91
- data/lib/bauxite/loggers/echo.rb +36 -36
- data/lib/bauxite/loggers/file.rb +68 -68
- data/lib/bauxite/loggers/html.rb +154 -154
- data/lib/bauxite/loggers/terminal.rb +134 -134
- data/lib/bauxite/loggers/xterm.rb +101 -101
- data/lib/bauxite/parsers/csv.rb +43 -43
- data/lib/bauxite/parsers/default.rb +42 -42
- data/lib/bauxite/parsers/html.rb +79 -79
- data/lib/bauxite/selectors/attr.rb +39 -39
- data/lib/bauxite/selectors/frame.rb +60 -60
- data/lib/bauxite/selectors/json.rb +88 -88
- data/lib/bauxite/selectors/sid.rb +38 -38
- data/lib/bauxite/selectors/smart.rb +80 -80
- data/lib/bauxite/selectors/window.rb +77 -77
- data/test/alert.bxt +3 -3
- data/test/alert/page.html +4 -4
- data/test/alias.bxt +9 -9
- data/test/asserth.bxt +2 -2
- data/test/assertv.bxt +1 -1
- data/test/assertw.bxt +7 -7
- data/test/broken.bxt.manual +0 -0
- data/test/bug_load_path.bxt.manual +0 -0
- data/test/bug_load_path/broken.bxt.manual +0 -0
- data/test/bug_load_path/test.bxt +0 -0
- data/test/capture.bxt.manual +20 -20
- data/test/capture/my_test.bxt +1 -1
- data/test/capture/page.html +6 -6
- data/test/capture_on_error.bxt.manual +3 -3
- data/test/capture_on_error/my_test.bxt +1 -1
- data/test/capture_on_error/page.html +2 -2
- data/test/debug.bxt.manual +0 -0
- data/test/default_selector.bxt.manual +7 -7
- data/test/default_selector/page.html +10 -10
- data/test/default_selector_var.bxt +1 -1
- data/test/delay.bxt +2 -2
- data/test/delay/page.html +4 -4
- data/test/doif.bxt +6 -6
- data/test/dounless.bxt +6 -6
- data/test/exec.bxt +6 -6
- data/test/exit.bxt +3 -3
- data/test/exit/test.bxt +3 -3
- data/test/extension.bxt.manual +4 -4
- data/test/extension/custom.rb +12 -12
- data/test/extension/page.html +4 -4
- data/test/failif.bxt +7 -7
- data/test/failif/page.html +5 -5
- data/test/format.bxt +17 -17
- data/test/format/page.html +6 -6
- data/test/frame.bxt +6 -6
- data/test/frame/child_frame.html +6 -6
- data/test/frame/grandchild_frame.html +4 -4
- data/test/frame/page.html +4 -4
- data/test/js.bxt +4 -4
- data/test/json.bxt +19 -19
- data/test/json/array.json +3 -3
- data/test/json/object.json +13 -13
- data/test/load.bxt +18 -18
- data/test/load/child.bxt +12 -12
- data/test/parsers.bxt +1 -1
- data/test/parsers.csv +7 -7
- data/test/parsers.html +32 -32
- data/test/parsers/page.html +6 -6
- data/test/return.bxt +1 -1
- data/test/return/f1.bxt +1 -1
- data/test/return/f2.bxt +1 -1
- data/test/return/f3.bxt +1 -1
- data/test/return/f4.bxt +2 -2
- data/test/ruby.bxt +1 -1
- data/test/ruby/custom.rb +5 -5
- data/test/select.bxt +9 -9
- data/test/select/page.html +8 -8
- data/test/selectors.bxt +7 -7
- data/test/selectors/page.html +6 -6
- data/test/set_builtin.bxt +5 -0
- data/test/set_builtin/page.html +5 -0
- data/test/setif.bxt +3 -3
- data/test/smart_selector.bxt +17 -17
- data/test/smart_selector/page.html +17 -17
- data/test/stdin.bxt +0 -0
- data/test/submit.bxt +4 -4
- data/test/submit/page.html +6 -6
- data/test/submit/page2.html +4 -4
- data/test/test.bxt.manual +6 -6
- data/test/test/test1.bxt +2 -2
- data/test/test/test2.bxt +3 -3
- data/test/test/test3.bxt +2 -2
- data/test/test/test4.bxt +1 -1
- data/test/test/test5.bxt +1 -1
- data/test/window.bxt +14 -14
- data/test/window/page.html +5 -5
- data/test/window/popup.html +4 -4
- metadata +5 -3
@@ -1,88 +1,88 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2014 Patricio Zavolinsky
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
-
# SOFTWARE.
|
21
|
-
#++
|
22
|
-
|
23
|
-
require 'json'
|
24
|
-
|
25
|
-
class Bauxite::Selector
|
26
|
-
# Select a field in a JSON document.
|
27
|
-
#
|
28
|
-
# The JSON selector syntax is:
|
29
|
-
# # For objects:
|
30
|
-
# json=key # {"key":1} => 1
|
31
|
-
# json=key.subkey # {"key":{"subkey":2}} => 2
|
32
|
-
# json=key[0] # {"key": [3]} => 3
|
33
|
-
# json=key[1].subkey # {"key": [{"subkey":4}]} => 4
|
34
|
-
# json=key.length # {"key": [5]} => 1
|
35
|
-
#
|
36
|
-
# # For arrays:
|
37
|
-
# json=[0] # [1] => 1
|
38
|
-
# json=[1].value # [{"value": 2}] => 2
|
39
|
-
# json=length # [3] => 1
|
40
|
-
#
|
41
|
-
# For example:
|
42
|
-
# # assuming {"key": [{"subkey":4},{"val":"42"}]}
|
43
|
-
# assert json=key[0].subkey 4
|
44
|
-
# assert json=key[1].val 42
|
45
|
-
# assert json=key.length 2
|
46
|
-
# # => these assertions would pass
|
47
|
-
#
|
48
|
-
# :category: Selector Methods
|
49
|
-
def json(arg, &block)
|
50
|
-
source = JSON::parse(@ctx.driver.page_source.sub(/^<html[^>]*>.*<pre>/, '').sub(/<\/pre>.*<\/html>$/, ''))
|
51
|
-
element = _json_find(source, arg)
|
52
|
-
raise Selenium::WebDriver::Error::NoSuchElementError, "Cannot find JSON element: #{arg}" unless element
|
53
|
-
|
54
|
-
element = element.to_s
|
55
|
-
def element.text; self; end
|
56
|
-
def element.tag_name; 'json'; end
|
57
|
-
yield element if block_given?
|
58
|
-
element
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
def _json_find(parent, selector)
|
63
|
-
if selector[0] == '['
|
64
|
-
delim = selector.index(']')
|
65
|
-
raise ArgumentError, "Invalid format for JSON selector (missing closing ']'): #{selector}" unless delim
|
66
|
-
i = selector[1...delim].to_i
|
67
|
-
selector = selector[delim+1..-1]
|
68
|
-
parent = parent[i]
|
69
|
-
return parent if selector == ''
|
70
|
-
end
|
71
|
-
if selector[0] == '.'
|
72
|
-
selector = selector[1..-1]
|
73
|
-
end
|
74
|
-
if selector == 'length' and parent.respond_to? :size
|
75
|
-
return parent.size
|
76
|
-
end
|
77
|
-
|
78
|
-
delim = selector.index(/[\[.]/)
|
79
|
-
if delim
|
80
|
-
target = parent[selector[0...delim]]
|
81
|
-
return unless target
|
82
|
-
rest = selector[delim..-1]
|
83
|
-
_json_find(target, rest)
|
84
|
-
else
|
85
|
-
parent[selector]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2014 Patricio Zavolinsky
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
# SOFTWARE.
|
21
|
+
#++
|
22
|
+
|
23
|
+
require 'json'
|
24
|
+
|
25
|
+
class Bauxite::Selector
|
26
|
+
# Select a field in a JSON document.
|
27
|
+
#
|
28
|
+
# The JSON selector syntax is:
|
29
|
+
# # For objects:
|
30
|
+
# json=key # {"key":1} => 1
|
31
|
+
# json=key.subkey # {"key":{"subkey":2}} => 2
|
32
|
+
# json=key[0] # {"key": [3]} => 3
|
33
|
+
# json=key[1].subkey # {"key": [{"subkey":4}]} => 4
|
34
|
+
# json=key.length # {"key": [5]} => 1
|
35
|
+
#
|
36
|
+
# # For arrays:
|
37
|
+
# json=[0] # [1] => 1
|
38
|
+
# json=[1].value # [{"value": 2}] => 2
|
39
|
+
# json=length # [3] => 1
|
40
|
+
#
|
41
|
+
# For example:
|
42
|
+
# # assuming {"key": [{"subkey":4},{"val":"42"}]}
|
43
|
+
# assert json=key[0].subkey 4
|
44
|
+
# assert json=key[1].val 42
|
45
|
+
# assert json=key.length 2
|
46
|
+
# # => these assertions would pass
|
47
|
+
#
|
48
|
+
# :category: Selector Methods
|
49
|
+
def json(arg, &block)
|
50
|
+
source = JSON::parse(@ctx.driver.page_source.sub(/^<html[^>]*>.*<pre>/, '').sub(/<\/pre>.*<\/html>$/, ''))
|
51
|
+
element = _json_find(source, arg)
|
52
|
+
raise Selenium::WebDriver::Error::NoSuchElementError, "Cannot find JSON element: #{arg}" unless element
|
53
|
+
|
54
|
+
element = element.to_s
|
55
|
+
def element.text; self; end
|
56
|
+
def element.tag_name; 'json'; end
|
57
|
+
yield element if block_given?
|
58
|
+
element
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def _json_find(parent, selector)
|
63
|
+
if selector[0] == '['
|
64
|
+
delim = selector.index(']')
|
65
|
+
raise ArgumentError, "Invalid format for JSON selector (missing closing ']'): #{selector}" unless delim
|
66
|
+
i = selector[1...delim].to_i
|
67
|
+
selector = selector[delim+1..-1]
|
68
|
+
parent = parent[i]
|
69
|
+
return parent if selector == ''
|
70
|
+
end
|
71
|
+
if selector[0] == '.'
|
72
|
+
selector = selector[1..-1]
|
73
|
+
end
|
74
|
+
if selector == 'length' and parent.respond_to? :size
|
75
|
+
return parent.size
|
76
|
+
end
|
77
|
+
|
78
|
+
delim = selector.index(/[\[.]/)
|
79
|
+
if delim
|
80
|
+
target = parent[selector[0...delim]]
|
81
|
+
return unless target
|
82
|
+
rest = selector[delim..-1]
|
83
|
+
_json_find(target, rest)
|
84
|
+
else
|
85
|
+
parent[selector]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2014 Patricio Zavolinsky
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
-
# SOFTWARE.
|
21
|
-
#++
|
22
|
-
|
23
|
-
class Bauxite::Selector
|
24
|
-
# Select an element by id suffix.
|
25
|
-
#
|
26
|
-
# This is the default selector. Any selector strings that do not contain an
|
27
|
-
# equal sign (i.e. '=') will use this selector.
|
28
|
-
#
|
29
|
-
# For example:
|
30
|
-
# # assuming <div id="strange_uuid_like_stuff_myDiv">foo</div>
|
31
|
-
# assert sid=myDiv "foo"
|
32
|
-
# # => matches the element above.
|
33
|
-
#
|
34
|
-
# :category: Selector Methods
|
35
|
-
def sid(arg, &block)
|
36
|
-
selenium_find(:css, "[id$='#{arg.gsub("'", "\\'")}']", &block)
|
37
|
-
end
|
38
|
-
end
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2014 Patricio Zavolinsky
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
# SOFTWARE.
|
21
|
+
#++
|
22
|
+
|
23
|
+
class Bauxite::Selector
|
24
|
+
# Select an element by id suffix.
|
25
|
+
#
|
26
|
+
# This is the default selector. Any selector strings that do not contain an
|
27
|
+
# equal sign (i.e. '=') will use this selector.
|
28
|
+
#
|
29
|
+
# For example:
|
30
|
+
# # assuming <div id="strange_uuid_like_stuff_myDiv">foo</div>
|
31
|
+
# assert sid=myDiv "foo"
|
32
|
+
# # => matches the element above.
|
33
|
+
#
|
34
|
+
# :category: Selector Methods
|
35
|
+
def sid(arg, &block)
|
36
|
+
selenium_find(:css, "[id$='#{arg.gsub("'", "\\'")}']", &block)
|
37
|
+
end
|
38
|
+
end
|
@@ -1,80 +1,80 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2014 Patricio Zavolinsky
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
-
# SOFTWARE.
|
21
|
-
#++
|
22
|
-
|
23
|
-
class Bauxite::Selector
|
24
|
-
# Select an element by applying different Selector strategies.
|
25
|
-
#
|
26
|
-
# This selector tries to find elements by using the following strategies:
|
27
|
-
# 1. default (id suffix)
|
28
|
-
# 2. by +name+
|
29
|
-
# 3. by +class_name+
|
30
|
-
# 4. by +id+ fragment (the +id+ contains the text specified)
|
31
|
-
# 5. by +placeholder+ attribute
|
32
|
-
# 6. by text content (unless the element is a label)
|
33
|
-
# 7. by radio/checkbox/button/submit value
|
34
|
-
# 8. by referenced element (find a label by its text, then find the element
|
35
|
-
# pointed by the label's +for+ attribute)
|
36
|
-
# 9. by child element (find a label by its text, then find the first
|
37
|
-
# element child control element, including input, select, textarea and
|
38
|
-
# button).
|
39
|
-
#
|
40
|
-
# For example:
|
41
|
-
# # assuming <label>By label parent<input type="text" value="By label parent"/></label>
|
42
|
-
# assert "smart=By label parent" "By label parent"
|
43
|
-
# # => the assertion succeeds.
|
44
|
-
#
|
45
|
-
# :category: Selector Methods
|
46
|
-
def smart(arg, &block)
|
47
|
-
b = lambda { |e| e }
|
48
|
-
target = _smart_try_find { sid(arg, &b) }
|
49
|
-
target ||= _smart_try_find { selenium_find(:name, arg) }
|
50
|
-
target ||= _smart_try_find { selenium_find(:class_name, arg) }
|
51
|
-
target ||= _smart_try_find { attr("id*:"+arg, &b) }
|
52
|
-
target ||= _smart_try_find { attr("placeholder:"+arg, &b) }
|
53
|
-
quoted_arg = "'"+arg.gsub("'", "\\'")+"'"
|
54
|
-
target ||= _smart_try_find do
|
55
|
-
selenium_find(:css, ["input[type='checkbox'][value=#{quoted_arg}]",
|
56
|
-
"input[type='radio'][value=#{quoted_arg}]",
|
57
|
-
"input[type='button'][value=#{quoted_arg}]",
|
58
|
-
"input[type='submit'][value=#{quoted_arg}]"
|
59
|
-
].join(',')
|
60
|
-
)
|
61
|
-
end
|
62
|
-
return yield target if target
|
63
|
-
|
64
|
-
target = selenium_find(:xpath, "//*[contains(text(), '#{arg.gsub("'", "\\'")}')]")
|
65
|
-
return yield target unless target.tag_name.downcase == 'label'
|
66
|
-
label = target
|
67
|
-
id = label['for']
|
68
|
-
return yield selenium_find(:id, id) if id
|
69
|
-
|
70
|
-
target = _smart_try_find { label.find_element(:css, "input, select, textarea, button") }
|
71
|
-
return yield target if target
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
def _smart_try_find()
|
76
|
-
@ctx.with_driver_timeout(0) { yield }
|
77
|
-
rescue StandardError => e
|
78
|
-
nil
|
79
|
-
end
|
80
|
-
end
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2014 Patricio Zavolinsky
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
# SOFTWARE.
|
21
|
+
#++
|
22
|
+
|
23
|
+
class Bauxite::Selector
|
24
|
+
# Select an element by applying different Selector strategies.
|
25
|
+
#
|
26
|
+
# This selector tries to find elements by using the following strategies:
|
27
|
+
# 1. default (id suffix)
|
28
|
+
# 2. by +name+
|
29
|
+
# 3. by +class_name+
|
30
|
+
# 4. by +id+ fragment (the +id+ contains the text specified)
|
31
|
+
# 5. by +placeholder+ attribute
|
32
|
+
# 6. by text content (unless the element is a label)
|
33
|
+
# 7. by radio/checkbox/button/submit value
|
34
|
+
# 8. by referenced element (find a label by its text, then find the element
|
35
|
+
# pointed by the label's +for+ attribute)
|
36
|
+
# 9. by child element (find a label by its text, then find the first
|
37
|
+
# element child control element, including input, select, textarea and
|
38
|
+
# button).
|
39
|
+
#
|
40
|
+
# For example:
|
41
|
+
# # assuming <label>By label parent<input type="text" value="By label parent"/></label>
|
42
|
+
# assert "smart=By label parent" "By label parent"
|
43
|
+
# # => the assertion succeeds.
|
44
|
+
#
|
45
|
+
# :category: Selector Methods
|
46
|
+
def smart(arg, &block)
|
47
|
+
b = lambda { |e| e }
|
48
|
+
target = _smart_try_find { sid(arg, &b) }
|
49
|
+
target ||= _smart_try_find { selenium_find(:name, arg) }
|
50
|
+
target ||= _smart_try_find { selenium_find(:class_name, arg) }
|
51
|
+
target ||= _smart_try_find { attr("id*:"+arg, &b) }
|
52
|
+
target ||= _smart_try_find { attr("placeholder:"+arg, &b) }
|
53
|
+
quoted_arg = "'"+arg.gsub("'", "\\'")+"'"
|
54
|
+
target ||= _smart_try_find do
|
55
|
+
selenium_find(:css, ["input[type='checkbox'][value=#{quoted_arg}]",
|
56
|
+
"input[type='radio'][value=#{quoted_arg}]",
|
57
|
+
"input[type='button'][value=#{quoted_arg}]",
|
58
|
+
"input[type='submit'][value=#{quoted_arg}]"
|
59
|
+
].join(',')
|
60
|
+
)
|
61
|
+
end
|
62
|
+
return yield target if target
|
63
|
+
|
64
|
+
target = selenium_find(:xpath, "//*[contains(text(), '#{arg.gsub("'", "\\'")}')]")
|
65
|
+
return yield target unless target.tag_name.downcase == 'label'
|
66
|
+
label = target
|
67
|
+
id = label['for']
|
68
|
+
return yield selenium_find(:id, id) if id
|
69
|
+
|
70
|
+
target = _smart_try_find { label.find_element(:css, "input, select, textarea, button") }
|
71
|
+
return yield target if target
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def _smart_try_find()
|
76
|
+
@ctx.with_driver_timeout(0) { yield }
|
77
|
+
rescue StandardError => e
|
78
|
+
nil
|
79
|
+
end
|
80
|
+
end
|
@@ -1,77 +1,77 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2014 Patricio Zavolinsky
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
-
# SOFTWARE.
|
21
|
-
#++
|
22
|
-
|
23
|
-
class Bauxite::Selector
|
24
|
-
# Change the selector scope to the given window and finds an element in that
|
25
|
-
# window.
|
26
|
-
#
|
27
|
-
# This is a composite selector. The window selector syntax is:
|
28
|
-
# window=|window_name|child_selector
|
29
|
-
#
|
30
|
-
# Where +window_name+ is the name or url pattern of the target window,
|
31
|
-
# +child_selector+ is any selector available that matches the target
|
32
|
-
# element inside the target window.
|
33
|
-
#
|
34
|
-
# Note that the '|' character can be replaced with any single-character
|
35
|
-
# delimiter.
|
36
|
-
#
|
37
|
-
# For example:
|
38
|
-
# # assuming <div id='label'>hello!</div> in popup.html
|
39
|
-
# js "window.w = window.open('popup.html', 'mypopup')"
|
40
|
-
# assert "window=|mypopup|label" "hello!"
|
41
|
-
# # => this assertion would pass
|
42
|
-
#
|
43
|
-
# assert "window=|popup.html|label" "hello!"
|
44
|
-
# # => this assertion would pass
|
45
|
-
#
|
46
|
-
# :category: Selector Methods
|
47
|
-
def window(arg, &block)
|
48
|
-
current = @ctx.driver.window_handle
|
49
|
-
|
50
|
-
delimiter = arg[0]
|
51
|
-
name,child = arg[1..-1].split(delimiter, 2)
|
52
|
-
|
53
|
-
pattern = /#{name}/
|
54
|
-
if name =~ /^\/.*\/[imxo]*$/
|
55
|
-
pattern = eval(name)
|
56
|
-
end
|
57
|
-
|
58
|
-
match = @ctx.driver.window_handles.find do |h|
|
59
|
-
@ctx.driver.switch_to.window h
|
60
|
-
@ctx.driver.current_url =~ pattern
|
61
|
-
end
|
62
|
-
|
63
|
-
name = match if match
|
64
|
-
begin
|
65
|
-
@ctx.driver.switch_to.window name
|
66
|
-
rescue StandardError => e
|
67
|
-
@ctx.driver.switch_to.window current
|
68
|
-
raise Bauxite::Errors::AssertionError, "Cannot find a window matching '#{name}' (either by name exact match or by url regex)." + e.message
|
69
|
-
end
|
70
|
-
|
71
|
-
begin
|
72
|
-
find(child, &block)
|
73
|
-
ensure
|
74
|
-
@ctx.driver.switch_to.window current
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2014 Patricio Zavolinsky
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
# SOFTWARE.
|
21
|
+
#++
|
22
|
+
|
23
|
+
class Bauxite::Selector
|
24
|
+
# Change the selector scope to the given window and finds an element in that
|
25
|
+
# window.
|
26
|
+
#
|
27
|
+
# This is a composite selector. The window selector syntax is:
|
28
|
+
# window=|window_name|child_selector
|
29
|
+
#
|
30
|
+
# Where +window_name+ is the name or url pattern of the target window,
|
31
|
+
# +child_selector+ is any selector available that matches the target
|
32
|
+
# element inside the target window.
|
33
|
+
#
|
34
|
+
# Note that the '|' character can be replaced with any single-character
|
35
|
+
# delimiter.
|
36
|
+
#
|
37
|
+
# For example:
|
38
|
+
# # assuming <div id='label'>hello!</div> in popup.html
|
39
|
+
# js "window.w = window.open('popup.html', 'mypopup')"
|
40
|
+
# assert "window=|mypopup|label" "hello!"
|
41
|
+
# # => this assertion would pass
|
42
|
+
#
|
43
|
+
# assert "window=|popup.html|label" "hello!"
|
44
|
+
# # => this assertion would pass
|
45
|
+
#
|
46
|
+
# :category: Selector Methods
|
47
|
+
def window(arg, &block)
|
48
|
+
current = @ctx.driver.window_handle
|
49
|
+
|
50
|
+
delimiter = arg[0]
|
51
|
+
name,child = arg[1..-1].split(delimiter, 2)
|
52
|
+
|
53
|
+
pattern = /#{name}/
|
54
|
+
if name =~ /^\/.*\/[imxo]*$/
|
55
|
+
pattern = eval(name)
|
56
|
+
end
|
57
|
+
|
58
|
+
match = @ctx.driver.window_handles.find do |h|
|
59
|
+
@ctx.driver.switch_to.window h
|
60
|
+
@ctx.driver.current_url =~ pattern
|
61
|
+
end
|
62
|
+
|
63
|
+
name = match if match
|
64
|
+
begin
|
65
|
+
@ctx.driver.switch_to.window name
|
66
|
+
rescue StandardError => e
|
67
|
+
@ctx.driver.switch_to.window current
|
68
|
+
raise Bauxite::Errors::AssertionError, "Cannot find a window matching '#{name}' (either by name exact match or by url regex)." + e.message
|
69
|
+
end
|
70
|
+
|
71
|
+
begin
|
72
|
+
find(child, &block)
|
73
|
+
ensure
|
74
|
+
@ctx.driver.switch_to.window current
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|