bauxite 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/Rakefile +69 -0
  4. data/bin/bauxite +27 -0
  5. data/doc/Bauxite/Action.html +1463 -0
  6. data/doc/Bauxite/ActionModule.html +342 -0
  7. data/doc/Bauxite/Context.html +1439 -0
  8. data/doc/Bauxite/Errors/AssertionError.html +107 -0
  9. data/doc/Bauxite/Errors/FileNotFoundError.html +107 -0
  10. data/doc/Bauxite/Errors.html +100 -0
  11. data/doc/Bauxite/Loggers/CompositeLogger.html +325 -0
  12. data/doc/Bauxite/Loggers/EchoLogger.html +164 -0
  13. data/doc/Bauxite/Loggers/FileLogger.html +215 -0
  14. data/doc/Bauxite/Loggers/NullLogger.html +334 -0
  15. data/doc/Bauxite/Loggers/TerminalLogger.html +586 -0
  16. data/doc/Bauxite/Loggers/XtermLogger.html +287 -0
  17. data/doc/Bauxite/Loggers.html +103 -0
  18. data/doc/Bauxite/Selector.html +422 -0
  19. data/doc/Bauxite/SelectorModule.html +283 -0
  20. data/doc/Bauxite.html +98 -0
  21. data/doc/created.rid +37 -0
  22. data/doc/fonts/Lato-Light.ttf +0 -0
  23. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  24. data/doc/fonts/Lato-Regular.ttf +0 -0
  25. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  26. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  27. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  28. data/doc/fonts.css +167 -0
  29. data/doc/images/add.png +0 -0
  30. data/doc/images/arrow_up.png +0 -0
  31. data/doc/images/brick.png +0 -0
  32. data/doc/images/brick_link.png +0 -0
  33. data/doc/images/bug.png +0 -0
  34. data/doc/images/bullet_black.png +0 -0
  35. data/doc/images/bullet_toggle_minus.png +0 -0
  36. data/doc/images/bullet_toggle_plus.png +0 -0
  37. data/doc/images/date.png +0 -0
  38. data/doc/images/delete.png +0 -0
  39. data/doc/images/find.png +0 -0
  40. data/doc/images/loadingAnimation.gif +0 -0
  41. data/doc/images/macFFBgHack.png +0 -0
  42. data/doc/images/package.png +0 -0
  43. data/doc/images/page_green.png +0 -0
  44. data/doc/images/page_white_text.png +0 -0
  45. data/doc/images/page_white_width.png +0 -0
  46. data/doc/images/plugin.png +0 -0
  47. data/doc/images/ruby.png +0 -0
  48. data/doc/images/tag_blue.png +0 -0
  49. data/doc/images/tag_green.png +0 -0
  50. data/doc/images/transparent.png +0 -0
  51. data/doc/images/wrench.png +0 -0
  52. data/doc/images/wrench_orange.png +0 -0
  53. data/doc/images/zoom.png +0 -0
  54. data/doc/index.html +111 -0
  55. data/doc/js/darkfish.js +140 -0
  56. data/doc/js/jquery.js +18 -0
  57. data/doc/js/navigation.js +142 -0
  58. data/doc/js/search.js +109 -0
  59. data/doc/js/search_index.js +1 -0
  60. data/doc/js/searcher.js +228 -0
  61. data/doc/rdoc.css +580 -0
  62. data/doc/table_of_contents.html +510 -0
  63. data/lib/bauxite/actions/alias.rb +51 -0
  64. data/lib/bauxite/actions/assert.rb +49 -0
  65. data/lib/bauxite/actions/assertv.rb +40 -0
  66. data/lib/bauxite/actions/break.rb +39 -0
  67. data/lib/bauxite/actions/click.rb +35 -0
  68. data/lib/bauxite/actions/debug.rb +99 -0
  69. data/lib/bauxite/actions/echo.rb +36 -0
  70. data/lib/bauxite/actions/exec.rb +46 -0
  71. data/lib/bauxite/actions/js.rb +41 -0
  72. data/lib/bauxite/actions/load.rb +49 -0
  73. data/lib/bauxite/actions/open.rb +34 -0
  74. data/lib/bauxite/actions/params.rb +40 -0
  75. data/lib/bauxite/actions/replace.rb +37 -0
  76. data/lib/bauxite/actions/reset.rb +37 -0
  77. data/lib/bauxite/actions/return.rb +62 -0
  78. data/lib/bauxite/actions/ruby.rb +58 -0
  79. data/lib/bauxite/actions/set.rb +39 -0
  80. data/lib/bauxite/actions/source.rb +44 -0
  81. data/lib/bauxite/actions/store.rb +38 -0
  82. data/lib/bauxite/actions/test.rb +61 -0
  83. data/lib/bauxite/actions/tryload.rb +79 -0
  84. data/lib/bauxite/actions/wait.rb +38 -0
  85. data/lib/bauxite/actions/write.rb +40 -0
  86. data/lib/bauxite/application.rb +150 -0
  87. data/lib/bauxite/core/Action.rb +205 -0
  88. data/lib/bauxite/core/Context.rb +575 -0
  89. data/lib/bauxite/core/Errors.rb +36 -0
  90. data/lib/bauxite/core/Logger.rb +86 -0
  91. data/lib/bauxite/core/Selector.rb +156 -0
  92. data/lib/bauxite/loggers/composite.rb +70 -0
  93. data/lib/bauxite/loggers/echo.rb +36 -0
  94. data/lib/bauxite/loggers/file.rb +45 -0
  95. data/lib/bauxite/loggers/terminal.rb +130 -0
  96. data/lib/bauxite/loggers/xterm.rb +79 -0
  97. data/lib/bauxite/selectors/attr.rb +39 -0
  98. data/lib/bauxite/selectors/default.rb +38 -0
  99. data/lib/bauxite/selectors/frame.rb +60 -0
  100. data/lib/bauxite.rb +29 -0
  101. data/test/alias.bxt +6 -0
  102. data/test/assertv.bxt +2 -0
  103. data/test/delay/page.html +5 -0
  104. data/test/delay.bxt +2 -0
  105. data/test/exec.bxt +6 -0
  106. data/test/format/page.html +7 -0
  107. data/test/format.bxt +17 -0
  108. data/test/frame/child_frame.html +7 -0
  109. data/test/frame/grandchild_frame.html +5 -0
  110. data/test/frame/page.html +5 -0
  111. data/test/frame.bxt +6 -0
  112. data/test/js.bxt +5 -0
  113. data/test/load/child.bxt +13 -0
  114. data/test/load.bxt +17 -0
  115. data/test/ruby/custom.rb +5 -0
  116. data/test/ruby.bxt +2 -0
  117. data/test/selectors/page.html +7 -0
  118. data/test/selectors.bxt +7 -0
  119. data/test/stdin.bxt +1 -0
  120. data/test/test/test1.bxt +2 -0
  121. data/test/test/test2.bxt +3 -0
  122. data/test/test/test3.bxt +2 -0
  123. data/test/test.bxt.manual +4 -0
  124. metadata +194 -0
@@ -0,0 +1,39 @@
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::Action
24
+ # Prompts the user to press ENTER before resuming execution.
25
+ #
26
+ # Note that this method provides an action named +break+ and not
27
+ # break_action.
28
+ #
29
+ # See Context::wait.
30
+ #
31
+ # For example:
32
+ # break
33
+ # # => echoes "Press ENTER to continue" and waits for user input
34
+ #
35
+ # :category: Action Methods
36
+ def break_action
37
+ lambda { Bauxite::Context::wait }
38
+ end
39
+ end
@@ -0,0 +1,35 @@
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::Action
24
+ # Triggers the +click+ event on the selected element.
25
+ #
26
+ # For example:
27
+ # # assuming <button type="button" id="btn">click me</button>
28
+ # click btn
29
+ # # => this would click the button
30
+ #
31
+ # :category: Action Methods
32
+ def click(selector)
33
+ @ctx.find(selector) { |e| e.click }
34
+ end
35
+ end
@@ -0,0 +1,99 @@
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::Action
24
+ # Breaks into the debug console.
25
+ #
26
+ # In the debug console you can type action strings and test their result.
27
+ #
28
+ # The debug console supports a history of previously executed actions and
29
+ # autocomplete (pressing the +TAB+ key).
30
+ #
31
+ # For example:
32
+ # debug
33
+ # # => this breaks into the debug console
34
+ # :category: Action Methods
35
+ def debug
36
+ lambda { _debug_process }
37
+ end
38
+
39
+ private
40
+ @@debug_line = 0
41
+ def _debug_process
42
+ Readline.completion_append_character = " "
43
+ Readline.completer_word_break_characters = ""
44
+ Readline.completion_proc = lambda { |str| _debug_auto_complete(str) }
45
+
46
+ while line = _debug_get_line
47
+ break if line.strip == 'exit'
48
+ @ctx.handle_errors(false, false) do
49
+ @ctx.exec_action({ :text => line, :file => '<debug>', :line => @@debug_line }, true)
50
+ end
51
+ @@debug_line += 1
52
+ end
53
+ end
54
+
55
+ def _debug_get_line
56
+ line = Readline.readline(@ctx.logger.debug_prompt, true)
57
+ return nil if line.nil?
58
+ if line =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == line
59
+ Readline::HISTORY.pop
60
+ end
61
+ line
62
+ end
63
+
64
+ def _debug_auto_complete(str)
65
+ action_name = str.sub(/ .*/, '')
66
+ #puts "\n\nac: ==>#{str}<==\nname: ==>#{action_name}<==\n\n"
67
+
68
+ actions = (Bauxite::Context::actions + ['exit']).grep(/^#{Regexp.escape(action_name)}/)
69
+
70
+ return actions unless actions.size == 1 and actions[0] == action_name and action_name != 'exit'
71
+
72
+ args = str.sub(/^\S+ /, '')
73
+
74
+ data = ['']
75
+
76
+ if args != ''
77
+ begin
78
+ data = Bauxite::Context::parse_args(args)
79
+ rescue
80
+ #puts "\nhasta aca\n"
81
+ return []
82
+ end
83
+ end
84
+ return [] if data.size == 0
85
+
86
+ arg_name = Bauxite::Context::action_args(actions[0])[data.size - 1]
87
+ return [] if arg_name != 'selector'
88
+
89
+ arg_value = data[-1]
90
+ #puts "\n\val: ==>#{arg_value}<==\n\n"
91
+
92
+ data.pop
93
+ data = data.join('" "')
94
+ data = '"'+data+'" ' if data.size > 0
95
+
96
+ selectors = Bauxite::Context::selectors.grep(/^#{Regexp.escape(arg_value)}/)
97
+ .map { |s| "#{action_name} #{data}#{s}=" }
98
+ end
99
+ end
@@ -0,0 +1,36 @@
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::Action
24
+ # Prints the value of the specified +text+.
25
+ #
26
+ # +text+ is subject to variable expansion (see Context#expand).
27
+ #
28
+ # For example:
29
+ # echo "Hello World!"
30
+ # # => this would print "Hello World!" in the terminal window.
31
+ #
32
+ # :category: Action Methods
33
+ def echo(text)
34
+ true
35
+ end
36
+ end
@@ -0,0 +1,46 @@
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::Action
24
+ # Executes +command+, optionally storing the results in a variable.
25
+ #
26
+ # If the first argument of +command+ is <tt>name=...</tt> the results
27
+ # of the execution will be assigned to the variable named +name+.
28
+ #
29
+ # For example:
30
+ # exec "that_day=date --date='2001-01-01' | cut -f 1 -d ' '"
31
+ # echo "${that_day}"
32
+ # # => this would print 'Mon'
33
+ #
34
+ # :category: Action Methods
35
+ def exec(*command)
36
+ data = command[0].split('=', 2)
37
+ name = nil
38
+ if (data.size == 2)
39
+ name = data[0]
40
+ command[0] = data[1]
41
+ end
42
+
43
+ ret = `#{command.join(' ')}`
44
+ @ctx.variables[name] = ret.strip if name
45
+ end
46
+ end
@@ -0,0 +1,41 @@
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::Action
24
+ # Executes the specified Javascript +script+, optionally storing the
25
+ # results the variable named +name+.
26
+ #
27
+ # Note that if +name+ is provided, the script must return a value using
28
+ # the Javascript +return+ statement.
29
+ #
30
+ # For example:
31
+ # js "return document.title" title_var
32
+ # echo "${title_var}"
33
+ # # => this would print the title of the page
34
+ #
35
+ # :category: Action Methods
36
+ def js(script, name = nil)
37
+ result = @ctx.driver.execute_script(script)
38
+ @ctx.variables[name] = result if name
39
+ true
40
+ end
41
+ end
@@ -0,0 +1,49 @@
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::Action
24
+ # Load the specified file into an isolated variable context and execute
25
+ # the actions specified. If the file does not exist, this action fails.
26
+ # See #tryload for a similar action that skips if the file does not exist.
27
+ #
28
+ # +file+ can be a path relative to the current test file.
29
+ #
30
+ # An optional list of variables can be provided in +vars+. These variables
31
+ # will override the value of the context variables for the execution of the
32
+ # file (See Context#with_vars).
33
+ #
34
+ # The syntax of the variable specification is:
35
+ # "var1_name=var1_value" "var2_name=var2_value" ...
36
+ #
37
+ # For example:
38
+ # load other_test.bxt "othervar=value_just_for_other"
39
+ # echo "${othervar}"
40
+ # # => this would load and execute other_test.bxt, injecting othervar
41
+ # # into its context. After other_test.bxt completes, othervar will
42
+ # # be restored to its original value (or be undefined if it didn't
43
+ # # exist prior to the 'load' call).
44
+ #
45
+ # :category: Action Methods
46
+ def load(file, *vars)
47
+ tryload(file, *vars) || (raise Bauxite::Errors::FileNotFoundError, "File not found: #{file}")
48
+ end
49
+ end
@@ -0,0 +1,34 @@
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::Action
24
+ # Opens the specified +url+ in the browser.
25
+ #
26
+ # For example:
27
+ # open "http://www.ruby-lang.org"
28
+ # # => this would open http://www.ruby-lang.org in the browser window
29
+ #
30
+ # :category: Action Methods
31
+ def open(url)
32
+ @ctx.driver.navigate.to url
33
+ end
34
+ end
@@ -0,0 +1,40 @@
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::Action
24
+ # Asserts that the variables named +vars+ are defined and not empty.
25
+ #
26
+ # For example:
27
+ # params host db_name username password
28
+ # # => this would fail if any of the four variables listed above
29
+ # # is not defined or is empty
30
+ #
31
+ # :category: Action Methods
32
+ def params(*vars)
33
+ missing = vars.select { |v| (@ctx.variables[v] || '') == '' }.join(', ')
34
+ if missing != ''
35
+ raise Bauxite::Errors::AssertionError,
36
+ "Assertion failed: the following variables must be defined and not be empty: #{missing}."
37
+ end
38
+ true
39
+ end
40
+ end
@@ -0,0 +1,37 @@
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::Action
24
+ # Replaces the occurrences of +pattern+ in +text+ with +replacement+ and
25
+ # assigns the result to the variable named +name+.
26
+ #
27
+ # For example:
28
+ # set place "World"
29
+ # replace "Hello ${place}" "World" "Universe" greeting
30
+ # echo "${greeting}!"
31
+ # # => this would print 'Hello Universe!'
32
+ #
33
+ # :category: Action Methods
34
+ def replace(text, pattern, replacement, name)
35
+ @ctx.variables[name] = text.gsub(_pattern(pattern), replacement)
36
+ end
37
+ end
@@ -0,0 +1,37 @@
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::Action
24
+ # Resets the test engine by closing and reopening the browser. As a side
25
+ # effect of resetting the test engine, all cookies, logins and cache items
26
+ # are destroyed.
27
+ #
28
+ # For example:
29
+ # reset
30
+ # # => this would close and re-open the browser window, removing
31
+ # # cookies, cache, login sessions, etc.
32
+ #
33
+ # :category: Action Methods
34
+ def reset()
35
+ @ctx.reset_driver
36
+ end
37
+ end
@@ -0,0 +1,62 @@
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::Action
24
+ # Returns the specified variables to the parent scope (if any).
25
+ #
26
+ # If +vars+ is <tt>*</tt> every variable defined in the current scope
27
+ # will be returned to the parent scope.
28
+ #
29
+ # The syntax of the variable specification is:
30
+ # "var1_name" "var2_name" ...
31
+ #
32
+ # Note that this method provides an action named +return+ and not
33
+ # return_action.
34
+ #
35
+ # For example:
36
+ # set result "42"
37
+ # return result
38
+ # # => this would inject the result variable (whose value is 42)
39
+ # # into the calling context.
40
+ #
41
+ # Full example (see #load, #write, #click, #store and #assert for more
42
+ # details):
43
+ # # in main.bxt
44
+ # load login.txt "username=jdoe" "password=hello world!"
45
+ #
46
+ # # in login.bxt
47
+ # write id=user "${username}"
48
+ # write id=pass "${password}"
49
+ # click id=login
50
+ # store id=loginName fullName
51
+ # return fullName
52
+ #
53
+ # # back in main.bxt
54
+ # assert id=greeting "Welcome ${fullName}!"
55
+ # # => this assertion uses the variable returned from login.bxt
56
+ #
57
+ # :category: Action Methods
58
+ def return_action(*vars)
59
+ rets = @ctx.variables['__RETURN__'] || []
60
+ @ctx.variables['__RETURN__'] = rets + vars
61
+ end
62
+ end
@@ -0,0 +1,58 @@
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::Action
24
+ # Load the specified ruby file into an isolated variable context and
25
+ # execute the ruby code.
26
+ #
27
+ # +file+ can be a path relative to the current test file.
28
+ #
29
+ # An optional list of variables can be provided in +vars+. See #load.
30
+ #
31
+ # The ruby action file must contain a single lambda that takes a Context
32
+ # instance as its only argument.
33
+ #
34
+ # For example:
35
+ # # === my_test.rb ======= #
36
+ # lambda do |ctx|
37
+ # ctx.exec_action 'echo "${message}"'
38
+ # ctx.driver.navigate.to 'http://www.ruby-lang.org'
39
+ # ctx.variables['new'] = 'from ruby!'
40
+ # ctx.exec_action 'return new'
41
+ # end
42
+ # # === end my_test.rb === #
43
+ #
44
+ # # in main.bxt
45
+ # ruby my_test.rb "message=Hello World!"
46
+ # echo "${new}"
47
+ # # => this would print 'from ruby!'
48
+ #
49
+ # :category: Action Methods
50
+ def ruby(file, *vars)
51
+ # _load_file_action is defined in tryload.rb
52
+ _load_file_action(file, *vars) do |f|
53
+ content = ''
54
+ File.open(f, 'r') { |ff| content = ff.read }
55
+ eval(content).call(@ctx)
56
+ end || (raise Bauxite::Errors::FileNotFoundError, "File not found: #{file}")
57
+ end
58
+ end
@@ -0,0 +1,39 @@
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::Action
24
+ # Sets the variable named +name+ to the +value+ specified.
25
+ #
26
+ # Both +name+ and +value+ are subject to variable expansion
27
+ # (see Context#expand).
28
+ #
29
+ # For example:
30
+ # set one "uno"
31
+ # set two "${one} + ${one}"
32
+ # echo "${two}"
33
+ # # => this would print 'uno + uno'
34
+ #
35
+ # :category: Action Methods
36
+ def set(name, value)
37
+ @ctx.variables[name] = value
38
+ end
39
+ end