bauxite 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/Rakefile +69 -0
- data/bin/bauxite +27 -0
- data/doc/Bauxite/Action.html +1463 -0
- data/doc/Bauxite/ActionModule.html +342 -0
- data/doc/Bauxite/Context.html +1439 -0
- data/doc/Bauxite/Errors/AssertionError.html +107 -0
- data/doc/Bauxite/Errors/FileNotFoundError.html +107 -0
- data/doc/Bauxite/Errors.html +100 -0
- data/doc/Bauxite/Loggers/CompositeLogger.html +325 -0
- data/doc/Bauxite/Loggers/EchoLogger.html +164 -0
- data/doc/Bauxite/Loggers/FileLogger.html +215 -0
- data/doc/Bauxite/Loggers/NullLogger.html +334 -0
- data/doc/Bauxite/Loggers/TerminalLogger.html +586 -0
- data/doc/Bauxite/Loggers/XtermLogger.html +287 -0
- data/doc/Bauxite/Loggers.html +103 -0
- data/doc/Bauxite/Selector.html +422 -0
- data/doc/Bauxite/SelectorModule.html +283 -0
- data/doc/Bauxite.html +98 -0
- data/doc/created.rid +37 -0
- 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/fonts.css +167 -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 +111 -0
- data/doc/js/darkfish.js +140 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +109 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +580 -0
- data/doc/table_of_contents.html +510 -0
- data/lib/bauxite/actions/alias.rb +51 -0
- data/lib/bauxite/actions/assert.rb +49 -0
- data/lib/bauxite/actions/assertv.rb +40 -0
- data/lib/bauxite/actions/break.rb +39 -0
- data/lib/bauxite/actions/click.rb +35 -0
- data/lib/bauxite/actions/debug.rb +99 -0
- data/lib/bauxite/actions/echo.rb +36 -0
- data/lib/bauxite/actions/exec.rb +46 -0
- data/lib/bauxite/actions/js.rb +41 -0
- data/lib/bauxite/actions/load.rb +49 -0
- data/lib/bauxite/actions/open.rb +34 -0
- data/lib/bauxite/actions/params.rb +40 -0
- data/lib/bauxite/actions/replace.rb +37 -0
- data/lib/bauxite/actions/reset.rb +37 -0
- data/lib/bauxite/actions/return.rb +62 -0
- data/lib/bauxite/actions/ruby.rb +58 -0
- data/lib/bauxite/actions/set.rb +39 -0
- data/lib/bauxite/actions/source.rb +44 -0
- data/lib/bauxite/actions/store.rb +38 -0
- data/lib/bauxite/actions/test.rb +61 -0
- data/lib/bauxite/actions/tryload.rb +79 -0
- data/lib/bauxite/actions/wait.rb +38 -0
- data/lib/bauxite/actions/write.rb +40 -0
- data/lib/bauxite/application.rb +150 -0
- data/lib/bauxite/core/Action.rb +205 -0
- data/lib/bauxite/core/Context.rb +575 -0
- data/lib/bauxite/core/Errors.rb +36 -0
- data/lib/bauxite/core/Logger.rb +86 -0
- data/lib/bauxite/core/Selector.rb +156 -0
- data/lib/bauxite/loggers/composite.rb +70 -0
- data/lib/bauxite/loggers/echo.rb +36 -0
- data/lib/bauxite/loggers/file.rb +45 -0
- data/lib/bauxite/loggers/terminal.rb +130 -0
- data/lib/bauxite/loggers/xterm.rb +79 -0
- data/lib/bauxite/selectors/attr.rb +39 -0
- data/lib/bauxite/selectors/default.rb +38 -0
- data/lib/bauxite/selectors/frame.rb +60 -0
- data/lib/bauxite.rb +29 -0
- data/test/alias.bxt +6 -0
- data/test/assertv.bxt +2 -0
- data/test/delay/page.html +5 -0
- data/test/delay.bxt +2 -0
- data/test/exec.bxt +6 -0
- data/test/format/page.html +7 -0
- data/test/format.bxt +17 -0
- data/test/frame/child_frame.html +7 -0
- data/test/frame/grandchild_frame.html +5 -0
- data/test/frame/page.html +5 -0
- data/test/frame.bxt +6 -0
- data/test/js.bxt +5 -0
- data/test/load/child.bxt +13 -0
- data/test/load.bxt +17 -0
- data/test/ruby/custom.rb +5 -0
- data/test/ruby.bxt +2 -0
- data/test/selectors/page.html +7 -0
- data/test/selectors.bxt +7 -0
- data/test/stdin.bxt +1 -0
- data/test/test/test1.bxt +2 -0
- data/test/test/test2.bxt +3 -0
- data/test/test/test3.bxt +2 -0
- data/test/test.bxt.manual +4 -0
- metadata +194 -0
@@ -0,0 +1,1439 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class Bauxite::Context - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<link href="../fonts.css" rel="stylesheet">
|
10
|
+
<link href="../rdoc.css" rel="stylesheet">
|
11
|
+
|
12
|
+
<script type="text/javascript">
|
13
|
+
var rdoc_rel_prefix = "../";
|
14
|
+
</script>
|
15
|
+
|
16
|
+
<script src="../js/jquery.js"></script>
|
17
|
+
<script src="../js/navigation.js"></script>
|
18
|
+
<script src="../js/search_index.js"></script>
|
19
|
+
<script src="../js/search.js"></script>
|
20
|
+
<script src="../js/searcher.js"></script>
|
21
|
+
<script src="../js/darkfish.js"></script>
|
22
|
+
|
23
|
+
|
24
|
+
<body id="top" role="document" class="class">
|
25
|
+
<nav role="navigation">
|
26
|
+
<div id="project-navigation">
|
27
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
28
|
+
<h2>
|
29
|
+
<a href="../index.html" rel="home">Home</a>
|
30
|
+
</h2>
|
31
|
+
|
32
|
+
<div id="table-of-contents-navigation">
|
33
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
34
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
35
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
40
|
+
<form action="#" method="get" accept-charset="utf-8">
|
41
|
+
<div id="search-field-wrapper">
|
42
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
43
|
+
aria-autocomplete="list" aria-controls="search-results"
|
44
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
45
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<ul id="search-results" aria-label="Search Results"
|
49
|
+
aria-busy="false" aria-expanded="false"
|
50
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
51
|
+
</form>
|
52
|
+
</div>
|
53
|
+
|
54
|
+
</div>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
<div id="class-metadata">
|
59
|
+
<div id="sections-section" class="nav-section">
|
60
|
+
<h3>Sections</h3>
|
61
|
+
|
62
|
+
<ul class="link-list" role="directory">
|
63
|
+
|
64
|
+
<li><a href="#5Buntitled-5D"></a></li>
|
65
|
+
|
66
|
+
<li><a href="#Advanced+Helpers">Advanced Helpers</a></li>
|
67
|
+
|
68
|
+
<li><a href="#Metadata">Metadata</a></li>
|
69
|
+
|
70
|
+
<li><a href="#Variable+manipulation+methods">Variable manipulation methods</a></li>
|
71
|
+
|
72
|
+
</ul>
|
73
|
+
</div>
|
74
|
+
|
75
|
+
<div id="parent-class-section" class="nav-section">
|
76
|
+
<h3>Parent</h3>
|
77
|
+
|
78
|
+
|
79
|
+
<p class="link">Object
|
80
|
+
|
81
|
+
</div>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<!-- Method Quickref -->
|
86
|
+
<div id="method-list-section" class="nav-section">
|
87
|
+
<h3>Methods</h3>
|
88
|
+
|
89
|
+
<ul class="link-list" role="directory">
|
90
|
+
|
91
|
+
<li ><a href="#method-c-action_args">::action_args</a>
|
92
|
+
|
93
|
+
<li ><a href="#method-c-actions">::actions</a>
|
94
|
+
|
95
|
+
<li ><a href="#method-c-load_logger">::load_logger</a>
|
96
|
+
|
97
|
+
<li ><a href="#method-c-loggers">::loggers</a>
|
98
|
+
|
99
|
+
<li ><a href="#method-c-max_action_name_size">::max_action_name_size</a>
|
100
|
+
|
101
|
+
<li ><a href="#method-c-new">::new</a>
|
102
|
+
|
103
|
+
<li ><a href="#method-c-parse_args">::parse_args</a>
|
104
|
+
|
105
|
+
<li ><a href="#method-c-selectors">::selectors</a>
|
106
|
+
|
107
|
+
<li ><a href="#method-c-wait">::wait</a>
|
108
|
+
|
109
|
+
<li ><a href="#method-i-debug">#debug</a>
|
110
|
+
|
111
|
+
<li ><a href="#method-i-exec_action">#exec_action</a>
|
112
|
+
|
113
|
+
<li ><a href="#method-i-expand">#expand</a>
|
114
|
+
|
115
|
+
<li ><a href="#method-i-find">#find</a>
|
116
|
+
|
117
|
+
<li ><a href="#method-i-get_value">#get_value</a>
|
118
|
+
|
119
|
+
<li ><a href="#method-i-handle_errors">#handle_errors</a>
|
120
|
+
|
121
|
+
<li ><a href="#method-i-parse_file">#parse_file</a>
|
122
|
+
|
123
|
+
<li ><a href="#method-i-reset_driver">#reset_driver</a>
|
124
|
+
|
125
|
+
<li ><a href="#method-i-start">#start</a>
|
126
|
+
|
127
|
+
<li ><a href="#method-i-stop">#stop</a>
|
128
|
+
|
129
|
+
<li ><a href="#method-i-with_timeout">#with_timeout</a>
|
130
|
+
|
131
|
+
<li ><a href="#method-i-with_vars">#with_vars</a>
|
132
|
+
|
133
|
+
</ul>
|
134
|
+
</div>
|
135
|
+
|
136
|
+
</div>
|
137
|
+
</nav>
|
138
|
+
|
139
|
+
<main role="main" aria-labelledby="class-Bauxite::Context">
|
140
|
+
<h1 id="class-Bauxite::Context" class="class">
|
141
|
+
class Bauxite::Context
|
142
|
+
</h1>
|
143
|
+
|
144
|
+
<section class="description">
|
145
|
+
|
146
|
+
<p>The Main test context. This class includes state and helper functions used
|
147
|
+
by clients execute tests and by actions and selectors to interact with the
|
148
|
+
test engine (i.e. Selenium WebDriver).</p>
|
149
|
+
|
150
|
+
</section>
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
<section class="attribute-method-details" class="method-section">
|
164
|
+
<header>
|
165
|
+
<h3>Attributes</h3>
|
166
|
+
</header>
|
167
|
+
|
168
|
+
|
169
|
+
<div id="attribute-i-aliases" class="method-detail">
|
170
|
+
<div class="method-heading attribute-method-heading">
|
171
|
+
<span class="method-name">aliases</span><span
|
172
|
+
class="attribute-access-type">[RW]</span>
|
173
|
+
</div>
|
174
|
+
|
175
|
+
<div class="method-description">
|
176
|
+
|
177
|
+
<p><a href="Action.html">Action</a> aliases.</p>
|
178
|
+
|
179
|
+
</div>
|
180
|
+
</div>
|
181
|
+
|
182
|
+
<div id="attribute-i-driver" class="method-detail">
|
183
|
+
<div class="method-heading attribute-method-heading">
|
184
|
+
<span class="method-name">driver</span><span
|
185
|
+
class="attribute-access-type">[R]</span>
|
186
|
+
</div>
|
187
|
+
|
188
|
+
<div class="method-description">
|
189
|
+
|
190
|
+
<p>Test engine driver instance (Selenium WebDriver).</p>
|
191
|
+
|
192
|
+
</div>
|
193
|
+
</div>
|
194
|
+
|
195
|
+
<div id="attribute-i-logger" class="method-detail">
|
196
|
+
<div class="method-heading attribute-method-heading">
|
197
|
+
<span class="method-name">logger</span><span
|
198
|
+
class="attribute-access-type">[R]</span>
|
199
|
+
</div>
|
200
|
+
|
201
|
+
<div class="method-description">
|
202
|
+
|
203
|
+
<p>Logger instance.</p>
|
204
|
+
|
205
|
+
</div>
|
206
|
+
</div>
|
207
|
+
|
208
|
+
<div id="attribute-i-options" class="method-detail">
|
209
|
+
<div class="method-heading attribute-method-heading">
|
210
|
+
<span class="method-name">options</span><span
|
211
|
+
class="attribute-access-type">[R]</span>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
<div class="method-description">
|
215
|
+
|
216
|
+
<p>Test options.</p>
|
217
|
+
|
218
|
+
</div>
|
219
|
+
</div>
|
220
|
+
|
221
|
+
<div id="attribute-i-tests" class="method-detail">
|
222
|
+
<div class="method-heading attribute-method-heading">
|
223
|
+
<span class="method-name">tests</span><span
|
224
|
+
class="attribute-access-type">[RW]</span>
|
225
|
+
</div>
|
226
|
+
|
227
|
+
<div class="method-description">
|
228
|
+
|
229
|
+
<p>Test containers.</p>
|
230
|
+
|
231
|
+
</div>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
<div id="attribute-i-variables" class="method-detail">
|
235
|
+
<div class="method-heading attribute-method-heading">
|
236
|
+
<span class="method-name">variables</span><span
|
237
|
+
class="attribute-access-type">[RW]</span>
|
238
|
+
</div>
|
239
|
+
|
240
|
+
<div class="method-description">
|
241
|
+
|
242
|
+
<p><a href="Context.html">Context</a> variables.</p>
|
243
|
+
|
244
|
+
</div>
|
245
|
+
</div>
|
246
|
+
|
247
|
+
</section>
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
252
|
+
<header>
|
253
|
+
<h3>Public Class Methods</h3>
|
254
|
+
</header>
|
255
|
+
|
256
|
+
|
257
|
+
<div id="method-c-new" class="method-detail ">
|
258
|
+
|
259
|
+
<div class="method-heading">
|
260
|
+
<span class="method-name">new</span><span
|
261
|
+
class="method-args">(options)</span>
|
262
|
+
|
263
|
+
<span class="method-click-advice">click to toggle source</span>
|
264
|
+
|
265
|
+
</div>
|
266
|
+
|
267
|
+
|
268
|
+
<div class="method-description">
|
269
|
+
|
270
|
+
<p>Constructs a new test context instance.</p>
|
271
|
+
|
272
|
+
<p><code>options</code> is a hash with the following values:</p>
|
273
|
+
<dl class="rdoc-list label-list"><dt>:driver
|
274
|
+
<dd>
|
275
|
+
<p>selenium driver symbol (defaults to <code>:firefox</code>)</p>
|
276
|
+
</dd><dt>:timeout
|
277
|
+
<dd>
|
278
|
+
<p>selector timeout in seconds (defaults to <code>10s</code>)</p>
|
279
|
+
</dd><dt>:logger
|
280
|
+
<dd>
|
281
|
+
<p>logger implementation name without the 'Logger' suffix (defaults to
|
282
|
+
'null' for <a
|
283
|
+
href="Loggers/NullLogger.html">Loggers::NullLogger</a>).</p>
|
284
|
+
</dd><dt>:verbose
|
285
|
+
<dd>
|
286
|
+
<p>if <code>true</code>, show verbose error information (e.g. backtraces) if
|
287
|
+
an error occurs (defaults to <code>false</code>)</p>
|
288
|
+
</dd><dt>:debug
|
289
|
+
<dd>
|
290
|
+
<p>if <code>true</code>, break into the <a
|
291
|
+
href="Context.html#method-i-debug">debug</a> console if an error occurs
|
292
|
+
(defaults to <code>false</code>)</p>
|
293
|
+
</dd><dt>:wait
|
294
|
+
<dd>
|
295
|
+
<p>if <code>true</code>, call <a href="Context.html#method-c-wait">::wait</a>
|
296
|
+
before stopping the test engine with <a
|
297
|
+
href="Context.html#method-i-stop">stop</a> (defaults to <code>false</code>)</p>
|
298
|
+
</dd></dl>
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
<div class="method-source-code" id="new-source">
|
304
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 69</span>
|
305
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>)
|
306
|
+
<span class="ruby-ivar">@options</span> = <span class="ruby-identifier">options</span>
|
307
|
+
<span class="ruby-ivar">@driver_name</span> = (<span class="ruby-identifier">options</span>[<span class="ruby-value">:driver</span>] <span class="ruby-operator">||</span> <span class="ruby-value">:firefox</span>).<span class="ruby-identifier">to_sym</span>
|
308
|
+
<span class="ruby-ivar">@variables</span> = {
|
309
|
+
<span class="ruby-string">'__TIMEOUT__'</span> =<span class="ruby-operator">></span> (<span class="ruby-identifier">options</span>[<span class="ruby-value">:timeout</span>] <span class="ruby-operator">||</span> <span class="ruby-value">10</span>).<span class="ruby-identifier">to_i</span>
|
310
|
+
}
|
311
|
+
<span class="ruby-ivar">@aliases</span> = {}
|
312
|
+
<span class="ruby-ivar">@tests</span> = []
|
313
|
+
|
314
|
+
<span class="ruby-identifier">handle_errors</span> <span class="ruby-keyword">do</span>
|
315
|
+
<span class="ruby-ivar">@logger</span> = <span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">load_logger</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:logger</span>], <span class="ruby-identifier">options</span>[<span class="ruby-value">:logger_opt</span>])
|
316
|
+
<span class="ruby-keyword">end</span>
|
317
|
+
<span class="ruby-keyword">end</span></pre>
|
318
|
+
</div>
|
319
|
+
|
320
|
+
</div>
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
</div>
|
326
|
+
|
327
|
+
|
328
|
+
</section>
|
329
|
+
|
330
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
331
|
+
<header>
|
332
|
+
<h3>Public Instance Methods</h3>
|
333
|
+
</header>
|
334
|
+
|
335
|
+
|
336
|
+
<div id="method-i-debug" class="method-detail ">
|
337
|
+
|
338
|
+
<div class="method-heading">
|
339
|
+
<span class="method-name">debug</span><span
|
340
|
+
class="method-args">()</span>
|
341
|
+
|
342
|
+
<span class="method-click-advice">click to toggle source</span>
|
343
|
+
|
344
|
+
</div>
|
345
|
+
|
346
|
+
|
347
|
+
<div class="method-description">
|
348
|
+
|
349
|
+
<p>Breaks into the debug console.</p>
|
350
|
+
|
351
|
+
<p>For example:</p>
|
352
|
+
|
353
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">debug</span>
|
354
|
+
<span class="ruby-comment"># => this breaks into the debug console</span>
|
355
|
+
</pre>
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
<div class="method-source-code" id="debug-source">
|
361
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 171</span>
|
362
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">debug</span>
|
363
|
+
<span class="ruby-identifier">exec_action</span>(<span class="ruby-string">'debug'</span>, <span class="ruby-keyword">false</span>)
|
364
|
+
<span class="ruby-keyword">end</span></pre>
|
365
|
+
</div>
|
366
|
+
|
367
|
+
</div>
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
</div>
|
373
|
+
|
374
|
+
|
375
|
+
<div id="method-i-find" class="method-detail ">
|
376
|
+
|
377
|
+
<div class="method-heading">
|
378
|
+
<span class="method-name">find</span><span
|
379
|
+
class="method-args">(selector) { |element| ... }</span>
|
380
|
+
|
381
|
+
<span class="method-click-advice">click to toggle source</span>
|
382
|
+
|
383
|
+
</div>
|
384
|
+
|
385
|
+
|
386
|
+
<div class="method-description">
|
387
|
+
|
388
|
+
<p>Finds an element by <code>selector</code>.</p>
|
389
|
+
|
390
|
+
<p>The element found is yielded to the given <code>block</code> (if any) and
|
391
|
+
returned.</p>
|
392
|
+
|
393
|
+
<p>Note that the recommeneded way to call this method is by passing a
|
394
|
+
<code>block</code>. This is because the method ensures that the element
|
395
|
+
context is maintained for the duration of the <code>block</code> but it
|
396
|
+
makes no guarantees after the <code>block</code> completes (the same
|
397
|
+
applies if no <code>block</code> was given).</p>
|
398
|
+
|
399
|
+
<p>For example:</p>
|
400
|
+
|
401
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">find</span>(<span class="ruby-string">'css=.my_button'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">click</span> }
|
402
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">find</span>(<span class="ruby-string">'css=.my_button'</span>).<span class="ruby-identifier">click</span>
|
403
|
+
</pre>
|
404
|
+
|
405
|
+
<p>For example (where using a <code>block</code> is mandatory):</p>
|
406
|
+
|
407
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">find</span>(<span class="ruby-string">'frame=|myframe|css=.my_button'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">click</span> }
|
408
|
+
<span class="ruby-comment"># => .my_button clicked</span>
|
409
|
+
|
410
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">find</span>(<span class="ruby-string">'frame=|myframe|css=.my_button'</span>).<span class="ruby-identifier">click</span>
|
411
|
+
<span class="ruby-comment"># => error, cannot click .my_button (no longer in myframe scope)</span>
|
412
|
+
</pre>
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
<div class="method-source-code" id="find-source">
|
418
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 160</span>
|
419
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">find</span>(<span class="ruby-identifier">selector</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># yields: element</span>
|
420
|
+
<span class="ruby-identifier">with_timeout</span> <span class="ruby-constant">Selenium</span><span class="ruby-operator">::</span><span class="ruby-constant">WebDriver</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span><span class="ruby-operator">::</span><span class="ruby-constant">NoSuchElementError</span> <span class="ruby-keyword">do</span>
|
421
|
+
<span class="ruby-constant">Selector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>).<span class="ruby-identifier">find</span>(<span class="ruby-identifier">selector</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
422
|
+
<span class="ruby-keyword">end</span>
|
423
|
+
<span class="ruby-keyword">end</span></pre>
|
424
|
+
</div>
|
425
|
+
|
426
|
+
</div>
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
</div>
|
432
|
+
|
433
|
+
|
434
|
+
<div id="method-i-get_value" class="method-detail ">
|
435
|
+
|
436
|
+
<div class="method-heading">
|
437
|
+
<span class="method-name">get_value</span><span
|
438
|
+
class="method-args">(element)</span>
|
439
|
+
|
440
|
+
<span class="method-click-advice">click to toggle source</span>
|
441
|
+
|
442
|
+
</div>
|
443
|
+
|
444
|
+
|
445
|
+
<div class="method-description">
|
446
|
+
|
447
|
+
<p>Returns the value of the specified <code>element</code>.</p>
|
448
|
+
|
449
|
+
<p>This method takes into account the type of element and selectively returns
|
450
|
+
the inner text or the value of the <code>value</code> attribute.</p>
|
451
|
+
|
452
|
+
<p>For example:</p>
|
453
|
+
|
454
|
+
<pre class="ruby"><span class="ruby-comment"># assuming <input type='text' value='Hello' /></span>
|
455
|
+
<span class="ruby-comment"># <span id='label'>World!</span></span>
|
456
|
+
|
457
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">get_value</span>(<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">find</span>(<span class="ruby-string">'css=input[type=text]'</span>))
|
458
|
+
<span class="ruby-comment"># => returns 'Hello'</span>
|
459
|
+
|
460
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">get_value</span>(<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">find</span>(<span class="ruby-string">'label'</span>))
|
461
|
+
<span class="ruby-comment"># => returns 'World!'</span>
|
462
|
+
</pre>
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
<div class="method-source-code" id="get_value-source">
|
468
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 190</span>
|
469
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_value</span>(<span class="ruby-identifier">element</span>)
|
470
|
+
<span class="ruby-keyword">if</span> [<span class="ruby-string">'input'</span>,<span class="ruby-string">'select'</span>,<span class="ruby-string">'textarea'</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">tag_name</span>.<span class="ruby-identifier">downcase</span>
|
471
|
+
<span class="ruby-identifier">element</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">'value'</span>)
|
472
|
+
<span class="ruby-keyword">else</span>
|
473
|
+
<span class="ruby-identifier">element</span>.<span class="ruby-identifier">text</span>
|
474
|
+
<span class="ruby-keyword">end</span>
|
475
|
+
<span class="ruby-keyword">end</span></pre>
|
476
|
+
</div>
|
477
|
+
|
478
|
+
</div>
|
479
|
+
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
</div>
|
484
|
+
|
485
|
+
|
486
|
+
<div id="method-i-reset_driver" class="method-detail ">
|
487
|
+
|
488
|
+
<div class="method-heading">
|
489
|
+
<span class="method-name">reset_driver</span><span
|
490
|
+
class="method-args">()</span>
|
491
|
+
|
492
|
+
<span class="method-click-advice">click to toggle source</span>
|
493
|
+
|
494
|
+
</div>
|
495
|
+
|
496
|
+
|
497
|
+
<div class="method-description">
|
498
|
+
|
499
|
+
<p>Stops the test engine and starts a new engine with the same provider.</p>
|
500
|
+
|
501
|
+
<p>For example:</p>
|
502
|
+
|
503
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">reset_driver</span>
|
504
|
+
=<span class="ruby-operator">></span> <span class="ruby-identifier">closes</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">browser</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">opens</span> <span class="ruby-identifier">a</span> <span class="ruby-identifier">new</span> <span class="ruby-identifier">one</span>
|
505
|
+
</pre>
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
<div class="method-source-code" id="reset_driver-source">
|
511
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 115</span>
|
512
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">reset_driver</span>
|
513
|
+
<span class="ruby-ivar">@driver</span>.<span class="ruby-identifier">quit</span>
|
514
|
+
<span class="ruby-identifier">_load_driver</span>
|
515
|
+
<span class="ruby-keyword">end</span></pre>
|
516
|
+
</div>
|
517
|
+
|
518
|
+
</div>
|
519
|
+
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
</div>
|
524
|
+
|
525
|
+
|
526
|
+
<div id="method-i-start" class="method-detail ">
|
527
|
+
|
528
|
+
<div class="method-heading">
|
529
|
+
<span class="method-name">start</span><span
|
530
|
+
class="method-args">(actions = [])</span>
|
531
|
+
|
532
|
+
<span class="method-click-advice">click to toggle source</span>
|
533
|
+
|
534
|
+
</div>
|
535
|
+
|
536
|
+
|
537
|
+
<div class="method-description">
|
538
|
+
|
539
|
+
<p>Starts the test engine and executes the actions specified. If no action was
|
540
|
+
specified, returns without stopping the test engine (see <a
|
541
|
+
href="Context.html#method-i-stop">stop</a>).</p>
|
542
|
+
|
543
|
+
<p>For example:</p>
|
544
|
+
|
545
|
+
<pre class="ruby"><span class="ruby-identifier">lines</span> = [
|
546
|
+
<span class="ruby-string">'open "http://www.ruby-lang.org"'</span>,
|
547
|
+
<span class="ruby-string">'write "name=q" "ljust"'</span>,
|
548
|
+
<span class="ruby-string">'click "name=sa"'</span>,
|
549
|
+
<span class="ruby-string">'break'</span>
|
550
|
+
]
|
551
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">lines</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">parse_action</span>(<span class="ruby-identifier">l</span>) })
|
552
|
+
<span class="ruby-comment"># => navigates to www.ruby-lang.org, types ljust in the search box</span>
|
553
|
+
<span class="ruby-comment"># and clicks the "Search" button.</span>
|
554
|
+
</pre>
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
<div class="method-source-code" id="start-source">
|
560
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 97</span>
|
561
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">start</span>(<span class="ruby-identifier">actions</span> = [])
|
562
|
+
<span class="ruby-identifier">_load_driver</span>
|
563
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">actions</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
564
|
+
<span class="ruby-keyword">begin</span>
|
565
|
+
<span class="ruby-identifier">actions</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">action</span><span class="ruby-operator">|</span>
|
566
|
+
<span class="ruby-identifier">exec_action</span>(<span class="ruby-identifier">action</span>)
|
567
|
+
<span class="ruby-keyword">end</span>
|
568
|
+
<span class="ruby-keyword">ensure</span>
|
569
|
+
<span class="ruby-identifier">stop</span>
|
570
|
+
<span class="ruby-keyword">end</span>
|
571
|
+
<span class="ruby-keyword">end</span></pre>
|
572
|
+
</div>
|
573
|
+
|
574
|
+
</div>
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
</div>
|
580
|
+
|
581
|
+
|
582
|
+
<div id="method-i-stop" class="method-detail ">
|
583
|
+
|
584
|
+
<div class="method-heading">
|
585
|
+
<span class="method-name">stop</span><span
|
586
|
+
class="method-args">()</span>
|
587
|
+
|
588
|
+
<span class="method-click-advice">click to toggle source</span>
|
589
|
+
|
590
|
+
</div>
|
591
|
+
|
592
|
+
|
593
|
+
<div class="method-description">
|
594
|
+
|
595
|
+
<p>Stops the test engine.</p>
|
596
|
+
|
597
|
+
<p>Calling this method at the end of the test is mandatory if <a
|
598
|
+
href="Context.html#method-i-start">start</a> was called without
|
599
|
+
<code>actions</code>.</p>
|
600
|
+
|
601
|
+
<p>Note that the recommeneded way of executing tests is by passing a list of
|
602
|
+
<code>actions</code> to <a href="Context.html#method-i-start">start</a>
|
603
|
+
instead of using the <a href="Context.html#method-i-start">start</a> / <a
|
604
|
+
href="Context.html#method-i-stop">stop</a> pattern.</p>
|
605
|
+
|
606
|
+
<p>For example:</p>
|
607
|
+
|
608
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">start</span>(:<span class="ruby-identifier">firefox</span>) <span class="ruby-comment"># => opens firefox</span>
|
609
|
+
|
610
|
+
<span class="ruby-comment"># test stuff goes here</span>
|
611
|
+
|
612
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">stop</span> <span class="ruby-comment"># => closes firefox</span>
|
613
|
+
</pre>
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
<div class="method-source-code" id="stop-source">
|
619
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 135</span>
|
620
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">stop</span>
|
621
|
+
<span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">wait</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value">:wait</span>]
|
622
|
+
<span class="ruby-ivar">@driver</span>.<span class="ruby-identifier">quit</span>
|
623
|
+
<span class="ruby-keyword">end</span></pre>
|
624
|
+
</div>
|
625
|
+
|
626
|
+
</div>
|
627
|
+
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
</div>
|
632
|
+
|
633
|
+
|
634
|
+
</section>
|
635
|
+
|
636
|
+
</section>
|
637
|
+
|
638
|
+
|
639
|
+
|
640
|
+
<section id="Advanced+Helpers" class="documentation-section">
|
641
|
+
|
642
|
+
<header class="documentation-section-title">
|
643
|
+
<h2>
|
644
|
+
Advanced Helpers
|
645
|
+
</h2>
|
646
|
+
<span class="section-click-top">
|
647
|
+
<a href="#top">↑ top</a>
|
648
|
+
</span>
|
649
|
+
</header>
|
650
|
+
|
651
|
+
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
<section id="public-class-Advanced+Helpers-method-details" class="method-section">
|
660
|
+
<header>
|
661
|
+
<h3>Public Class Methods</h3>
|
662
|
+
</header>
|
663
|
+
|
664
|
+
|
665
|
+
<div id="method-c-load_logger" class="method-detail ">
|
666
|
+
|
667
|
+
<div class="method-heading">
|
668
|
+
<span class="method-name">load_logger</span><span
|
669
|
+
class="method-args">(name, options)</span>
|
670
|
+
|
671
|
+
<span class="method-click-advice">click to toggle source</span>
|
672
|
+
|
673
|
+
</div>
|
674
|
+
|
675
|
+
|
676
|
+
<div class="method-description">
|
677
|
+
|
678
|
+
<p>Constructs a Logger instance using <code>name</code> as a hint for the
|
679
|
+
logger type.</p>
|
680
|
+
|
681
|
+
|
682
|
+
|
683
|
+
|
684
|
+
<div class="method-source-code" id="load_logger-source">
|
685
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 365</span>
|
686
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">load_logger</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>)
|
687
|
+
<span class="ruby-identifier">log_name</span> = (<span class="ruby-identifier">name</span> <span class="ruby-operator">||</span> <span class="ruby-string">'null'</span>).<span class="ruby-identifier">downcase</span>
|
688
|
+
|
689
|
+
<span class="ruby-identifier">class_name</span> = <span class="ruby-node">"#{log_name.capitalize}Logger"</span>
|
690
|
+
|
691
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-constant">Loggers</span>.<span class="ruby-identifier">const_defined?</span> <span class="ruby-identifier">class_name</span>.<span class="ruby-identifier">to_sym</span>
|
692
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">NameError</span>,
|
693
|
+
<span class="ruby-node">"Invalid logger '#{log_name}'"</span>
|
694
|
+
<span class="ruby-keyword">end</span>
|
695
|
+
|
696
|
+
<span class="ruby-constant">Loggers</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">class_name</span>).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>)
|
697
|
+
<span class="ruby-keyword">end</span></pre>
|
698
|
+
</div>
|
699
|
+
|
700
|
+
</div>
|
701
|
+
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
</div>
|
706
|
+
|
707
|
+
|
708
|
+
<div id="method-c-parse_args" class="method-detail ">
|
709
|
+
|
710
|
+
<div class="method-heading">
|
711
|
+
<span class="method-name">parse_args</span><span
|
712
|
+
class="method-args">(line)</span>
|
713
|
+
|
714
|
+
<span class="method-click-advice">click to toggle source</span>
|
715
|
+
|
716
|
+
</div>
|
717
|
+
|
718
|
+
|
719
|
+
<div class="method-description">
|
720
|
+
|
721
|
+
<p>Parses a line of action text into an array. The input <code>line</code>
|
722
|
+
should be a space-separated list of values, surrounded by optional quotes
|
723
|
+
(“).</p>
|
724
|
+
|
725
|
+
<p>The first element in <code>line</code> will be interpreted as an action
|
726
|
+
name. Valid action names are retuned by <a
|
727
|
+
href="Context.html#method-c-actions">::actions</a>.</p>
|
728
|
+
|
729
|
+
<p>The other elements in <code>line</code> will be interpreted as action
|
730
|
+
arguments.</p>
|
731
|
+
|
732
|
+
<p>For example:</p>
|
733
|
+
|
734
|
+
<pre class="ruby"><span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">parse_args</span>(<span class="ruby-string">'echo "Hello World!"'</span>)
|
735
|
+
<span class="ruby-comment"># => ' ["echo", "Hello World!"]</span>
|
736
|
+
</pre>
|
737
|
+
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
<div class="method-source-code" id="parse_args-source">
|
742
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 267</span>
|
743
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">parse_args</span>(<span class="ruby-identifier">line</span>)
|
744
|
+
<span class="ruby-comment"># col_sep must be a regex because String.split has a special case for</span>
|
745
|
+
<span class="ruby-comment"># a single space char (' ') that produced unexpected results (i.e.</span>
|
746
|
+
<span class="ruby-comment"># if line is '"a b"' the resulting array contains ["a b"]).</span>
|
747
|
+
<span class="ruby-comment">#</span>
|
748
|
+
<span class="ruby-comment"># ...but... </span>
|
749
|
+
<span class="ruby-comment">#</span>
|
750
|
+
<span class="ruby-comment"># CSV expects col_sep to be a string so we need to work some dark magic</span>
|
751
|
+
<span class="ruby-comment"># here. Basically we proxy the StringIO received by CSV to returns</span>
|
752
|
+
<span class="ruby-comment"># strings for which the split method does not fold the whitespaces.</span>
|
753
|
+
<span class="ruby-comment">#</span>
|
754
|
+
<span class="ruby-keyword">return</span> [] <span class="ruby-keyword">if</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">strip</span> <span class="ruby-operator">==</span> <span class="ruby-string">''</span>
|
755
|
+
<span class="ruby-constant">CSV</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">StringIOProxy</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">line</span>), { <span class="ruby-value">:col_sep</span> =<span class="ruby-operator">></span> <span class="ruby-string">' '</span> })
|
756
|
+
.<span class="ruby-identifier">shift</span>
|
757
|
+
.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span> }
|
758
|
+
<span class="ruby-keyword">end</span></pre>
|
759
|
+
</div>
|
760
|
+
|
761
|
+
</div>
|
762
|
+
|
763
|
+
|
764
|
+
|
765
|
+
|
766
|
+
</div>
|
767
|
+
|
768
|
+
|
769
|
+
<div id="method-c-wait" class="method-detail ">
|
770
|
+
|
771
|
+
<div class="method-heading">
|
772
|
+
<span class="method-name">wait</span><span
|
773
|
+
class="method-args">()</span>
|
774
|
+
|
775
|
+
<span class="method-click-advice">click to toggle source</span>
|
776
|
+
|
777
|
+
</div>
|
778
|
+
|
779
|
+
|
780
|
+
<div class="method-description">
|
781
|
+
|
782
|
+
<p>Prompts the user to press ENTER before resuming execution.</p>
|
783
|
+
|
784
|
+
<p>For example:</p>
|
785
|
+
|
786
|
+
<pre class="ruby"><span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">wait</span>
|
787
|
+
<span class="ruby-comment"># => echoes "Press ENTER to continue" and waits for user input</span>
|
788
|
+
</pre>
|
789
|
+
|
790
|
+
|
791
|
+
|
792
|
+
|
793
|
+
<div class="method-source-code" id="wait-source">
|
794
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 358</span>
|
795
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">wait</span>
|
796
|
+
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>(<span class="ruby-string">"Press ENTER to continue\n"</span>)
|
797
|
+
<span class="ruby-keyword">end</span></pre>
|
798
|
+
</div>
|
799
|
+
|
800
|
+
</div>
|
801
|
+
|
802
|
+
|
803
|
+
|
804
|
+
|
805
|
+
</div>
|
806
|
+
|
807
|
+
|
808
|
+
</section>
|
809
|
+
|
810
|
+
<section id="public-instance-Advanced+Helpers-method-details" class="method-section">
|
811
|
+
<header>
|
812
|
+
<h3>Public Instance Methods</h3>
|
813
|
+
</header>
|
814
|
+
|
815
|
+
|
816
|
+
<div id="method-i-exec_action" class="method-detail ">
|
817
|
+
|
818
|
+
<div class="method-heading">
|
819
|
+
<span class="method-name">exec_action</span><span
|
820
|
+
class="method-args">(action, log = true)</span>
|
821
|
+
|
822
|
+
<span class="method-click-advice">click to toggle source</span>
|
823
|
+
|
824
|
+
</div>
|
825
|
+
|
826
|
+
|
827
|
+
<div class="method-description">
|
828
|
+
|
829
|
+
<p>Executes the specified action handling errors, logging and debug history.
|
830
|
+
Actions can be obtained by calling parse_action.</p>
|
831
|
+
|
832
|
+
<p>If <code>log</code> is <code>true</code>, log the action execution (default
|
833
|
+
behavior).</p>
|
834
|
+
|
835
|
+
<p>For example:</p>
|
836
|
+
|
837
|
+
<pre class="ruby"><span class="ruby-identifier">action</span> = <span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">parse_action</span>(<span class="ruby-string">'open "http://www.ruby-lang.org"'</span>)
|
838
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">exec_action</span> <span class="ruby-identifier">action</span>
|
839
|
+
<span class="ruby-comment"># => navigates to www.ruby-lang.org</span>
|
840
|
+
</pre>
|
841
|
+
|
842
|
+
|
843
|
+
|
844
|
+
|
845
|
+
<div class="method-source-code" id="exec_action-source">
|
846
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 212</span>
|
847
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">exec_action</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">log</span> = <span class="ruby-keyword">true</span>)
|
848
|
+
<span class="ruby-keyword">if</span> (<span class="ruby-identifier">action</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>)
|
849
|
+
<span class="ruby-identifier">action</span> = { <span class="ruby-value">:text</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">action</span>, <span class="ruby-value">:file</span> =<span class="ruby-operator">></span> <span class="ruby-string">'<unknown>'</span>, <span class="ruby-value">:line</span> =<span class="ruby-operator">></span> <span class="ruby-value">0</span> }
|
850
|
+
<span class="ruby-keyword">end</span>
|
851
|
+
|
852
|
+
<span class="ruby-identifier">ret</span> = <span class="ruby-identifier">handle_errors</span>(<span class="ruby-keyword">true</span>) <span class="ruby-keyword">do</span>
|
853
|
+
|
854
|
+
<span class="ruby-identifier">action</span> = <span class="ruby-identifier">_load_action</span>(<span class="ruby-identifier">action</span>)
|
855
|
+
|
856
|
+
<span class="ruby-comment"># Inject built-in variables</span>
|
857
|
+
<span class="ruby-identifier">file</span> = <span class="ruby-identifier">action</span>.<span class="ruby-identifier">file</span>
|
858
|
+
<span class="ruby-identifier">dir</span> = (<span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">file</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">file</span>) <span class="ruby-operator">:</span> <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">pwd</span>
|
859
|
+
<span class="ruby-ivar">@variables</span>[<span class="ruby-string">'__FILE__'</span>] = <span class="ruby-identifier">file</span>
|
860
|
+
<span class="ruby-ivar">@variables</span>[<span class="ruby-string">'__DIR__'</span>] = <span class="ruby-constant">File</span>.<span class="ruby-identifier">absolute_path</span>(<span class="ruby-identifier">dir</span>)
|
861
|
+
|
862
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">log</span>
|
863
|
+
<span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">log_cmd</span>(<span class="ruby-identifier">action</span>) <span class="ruby-keyword">do</span>
|
864
|
+
<span class="ruby-constant">Readline</span><span class="ruby-operator">::</span><span class="ruby-constant">HISTORY</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">action</span>.<span class="ruby-identifier">text</span>
|
865
|
+
<span class="ruby-identifier">action</span>.<span class="ruby-identifier">execute</span>
|
866
|
+
<span class="ruby-keyword">end</span>
|
867
|
+
<span class="ruby-keyword">else</span>
|
868
|
+
<span class="ruby-identifier">action</span>.<span class="ruby-identifier">execute</span>
|
869
|
+
<span class="ruby-keyword">end</span>
|
870
|
+
<span class="ruby-keyword">end</span>
|
871
|
+
<span class="ruby-identifier">ret</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">ret</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value">:call</span> <span class="ruby-comment"># delayed actions (after log_cmd)</span>
|
872
|
+
<span class="ruby-keyword">end</span></pre>
|
873
|
+
</div>
|
874
|
+
|
875
|
+
</div>
|
876
|
+
|
877
|
+
|
878
|
+
|
879
|
+
|
880
|
+
</div>
|
881
|
+
|
882
|
+
|
883
|
+
<div id="method-i-handle_errors" class="method-detail ">
|
884
|
+
|
885
|
+
<div class="method-heading">
|
886
|
+
<span class="method-name">handle_errors</span><span
|
887
|
+
class="method-args">(break_into_debug = false, exit_on_error = true) { || ... }</span>
|
888
|
+
|
889
|
+
<span class="method-click-advice">click to toggle source</span>
|
890
|
+
|
891
|
+
</div>
|
892
|
+
|
893
|
+
|
894
|
+
<div class="method-description">
|
895
|
+
|
896
|
+
<p>Executes the <code>block</code> inside a rescue block applying standard
|
897
|
+
criteria of error handling.</p>
|
898
|
+
|
899
|
+
<p>The default behavior is to print the exception message and exit.</p>
|
900
|
+
|
901
|
+
<p>If the <code>:verbose</code> option is set, the exception backtrace will
|
902
|
+
also be printed.</p>
|
903
|
+
|
904
|
+
<p>If the <code>break_into_debug</code> argument is <code>true</code> and the
|
905
|
+
<code>:debug</code> option is set, the handler will break into the debug
|
906
|
+
console instead of exiting.</p>
|
907
|
+
|
908
|
+
<p>If the <code>exit_on_error</code> argument is <code>false</code> the
|
909
|
+
handler will not exit after printing the error message.</p>
|
910
|
+
|
911
|
+
<p>For example:</p>
|
912
|
+
|
913
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span> = <span class="ruby-constant">Context</span>.<span class="ruby-identifier">new</span>({ :<span class="ruby-identifier">debug</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span> })
|
914
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">handle_errors</span>(<span class="ruby-keyword">true</span>) { <span class="ruby-identifier">raise</span> <span class="ruby-string">'break into debug now!'</span> }
|
915
|
+
<span class="ruby-comment"># => this breaks into the debug console</span>
|
916
|
+
</pre>
|
917
|
+
|
918
|
+
|
919
|
+
|
920
|
+
|
921
|
+
<div class="method-source-code" id="handle_errors-source">
|
922
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 303</span>
|
923
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">handle_errors</span>(<span class="ruby-identifier">break_into_debug</span> = <span class="ruby-keyword">false</span>, <span class="ruby-identifier">exit_on_error</span> = <span class="ruby-keyword">true</span>)
|
924
|
+
<span class="ruby-keyword">yield</span>
|
925
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">StandardError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
926
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@logger</span>
|
927
|
+
<span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">log</span> <span class="ruby-node">"#{e.message}\n"</span>, <span class="ruby-value">:error</span>
|
928
|
+
<span class="ruby-keyword">else</span>
|
929
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
930
|
+
<span class="ruby-keyword">end</span>
|
931
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value">:verbose</span>]
|
932
|
+
<span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span>
|
933
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>
|
934
|
+
<span class="ruby-keyword">end</span>
|
935
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">break_into_debug</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value">:debug</span>]
|
936
|
+
<span class="ruby-identifier">debug</span>
|
937
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">exit_on_error</span>
|
938
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@variables</span>[<span class="ruby-string">'__RAISE_ERROR__'</span>]
|
939
|
+
<span class="ruby-identifier">raise</span>
|
940
|
+
<span class="ruby-keyword">else</span>
|
941
|
+
<span class="ruby-identifier">exit</span> <span class="ruby-keyword">false</span>
|
942
|
+
<span class="ruby-keyword">end</span>
|
943
|
+
<span class="ruby-keyword">end</span>
|
944
|
+
<span class="ruby-keyword">end</span></pre>
|
945
|
+
</div>
|
946
|
+
|
947
|
+
</div>
|
948
|
+
|
949
|
+
|
950
|
+
|
951
|
+
|
952
|
+
</div>
|
953
|
+
|
954
|
+
|
955
|
+
<div id="method-i-parse_file" class="method-detail ">
|
956
|
+
|
957
|
+
<div class="method-heading">
|
958
|
+
<span class="method-name">parse_file</span><span
|
959
|
+
class="method-args">(file)</span>
|
960
|
+
|
961
|
+
<span class="method-click-advice">click to toggle source</span>
|
962
|
+
|
963
|
+
</div>
|
964
|
+
|
965
|
+
|
966
|
+
<div class="method-description">
|
967
|
+
|
968
|
+
<p>Parses the specified text into a test action array.</p>
|
969
|
+
|
970
|
+
<p>See parse_action for more details.</p>
|
971
|
+
|
972
|
+
<p>For example:</p>
|
973
|
+
|
974
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">parse_file</span>(<span class="ruby-string">'file'</span>)
|
975
|
+
<span class="ruby-comment"># => [ { :cmd => 'echo', ... } ]</span>
|
976
|
+
</pre>
|
977
|
+
|
978
|
+
|
979
|
+
|
980
|
+
|
981
|
+
<div class="method-source-code" id="parse_file-source">
|
982
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 247</span>
|
983
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">parse_file</span>(<span class="ruby-identifier">file</span>)
|
984
|
+
<span class="ruby-keyword">if</span> (<span class="ruby-identifier">file</span> <span class="ruby-operator">==</span> <span class="ruby-string">'stdin'</span>)
|
985
|
+
<span class="ruby-identifier">_parse_file</span>(<span class="ruby-identifier">$stdin</span>, <span class="ruby-identifier">file</span>)
|
986
|
+
<span class="ruby-keyword">else</span>
|
987
|
+
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">file</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">io</span><span class="ruby-operator">|</span> <span class="ruby-identifier">_parse_file</span>(<span class="ruby-identifier">io</span>, <span class="ruby-identifier">file</span>) }
|
988
|
+
<span class="ruby-keyword">end</span>
|
989
|
+
<span class="ruby-keyword">end</span></pre>
|
990
|
+
</div>
|
991
|
+
|
992
|
+
</div>
|
993
|
+
|
994
|
+
|
995
|
+
|
996
|
+
|
997
|
+
</div>
|
998
|
+
|
999
|
+
|
1000
|
+
<div id="method-i-with_timeout" class="method-detail ">
|
1001
|
+
|
1002
|
+
<div class="method-heading">
|
1003
|
+
<span class="method-name">with_timeout</span><span
|
1004
|
+
class="method-args">(*error_types) { || ... }</span>
|
1005
|
+
|
1006
|
+
<span class="method-click-advice">click to toggle source</span>
|
1007
|
+
|
1008
|
+
</div>
|
1009
|
+
|
1010
|
+
|
1011
|
+
<div class="method-description">
|
1012
|
+
|
1013
|
+
<p>Executes the given block retrying for at most <code>${__TIMEOUT__}</code>
|
1014
|
+
seconds. Note that this method does not take into account the time it takes
|
1015
|
+
to execute the block itself.</p>
|
1016
|
+
|
1017
|
+
<p>For example</p>
|
1018
|
+
|
1019
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">with_timeout</span> <span class="ruby-constant">StandardError</span> <span class="ruby-keyword">do</span>
|
1020
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">find</span> (<span class="ruby-string">'element_with_delay'</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
|
1021
|
+
<span class="ruby-comment"># do something with e</span>
|
1022
|
+
<span class="ruby-keyword">end</span>
|
1023
|
+
<span class="ruby-keyword">end</span>
|
1024
|
+
</pre>
|
1025
|
+
|
1026
|
+
|
1027
|
+
|
1028
|
+
|
1029
|
+
<div class="method-source-code" id="with_timeout-source">
|
1030
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 337</span>
|
1031
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">with_timeout</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">error_types</span>)
|
1032
|
+
<span class="ruby-identifier">stime</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>
|
1033
|
+
<span class="ruby-identifier">timeout</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">stime</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@variables</span>[<span class="ruby-string">'__TIMEOUT__'</span>]
|
1034
|
+
<span class="ruby-keyword">yield</span>
|
1035
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-operator">*</span><span class="ruby-identifier">error_types</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
1036
|
+
<span class="ruby-identifier">t</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>
|
1037
|
+
<span class="ruby-identifier">rem</span> = <span class="ruby-identifier">timeout</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">t</span>
|
1038
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">rem</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>
|
1039
|
+
|
1040
|
+
<span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">progress</span>(<span class="ruby-identifier">rem</span>.<span class="ruby-identifier">round</span>)
|
1041
|
+
|
1042
|
+
<span class="ruby-identifier">sleep</span>(<span class="ruby-value">1.0</span><span class="ruby-operator">/</span><span class="ruby-value">10.0</span>) <span class="ruby-keyword">if</span> (<span class="ruby-identifier">t</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">stime</span>).<span class="ruby-identifier">to_i</span> <span class="ruby-operator"><</span> <span class="ruby-value">1</span>
|
1043
|
+
<span class="ruby-keyword">retry</span>
|
1044
|
+
<span class="ruby-keyword">end</span></pre>
|
1045
|
+
</div>
|
1046
|
+
|
1047
|
+
</div>
|
1048
|
+
|
1049
|
+
|
1050
|
+
|
1051
|
+
|
1052
|
+
</div>
|
1053
|
+
|
1054
|
+
|
1055
|
+
</section>
|
1056
|
+
|
1057
|
+
</section>
|
1058
|
+
|
1059
|
+
|
1060
|
+
|
1061
|
+
<section id="Metadata" class="documentation-section">
|
1062
|
+
|
1063
|
+
<header class="documentation-section-title">
|
1064
|
+
<h2>
|
1065
|
+
Metadata
|
1066
|
+
</h2>
|
1067
|
+
<span class="section-click-top">
|
1068
|
+
<a href="#top">↑ top</a>
|
1069
|
+
</span>
|
1070
|
+
</header>
|
1071
|
+
|
1072
|
+
|
1073
|
+
|
1074
|
+
|
1075
|
+
|
1076
|
+
|
1077
|
+
|
1078
|
+
|
1079
|
+
|
1080
|
+
<section id="public-class-Metadata-method-details" class="method-section">
|
1081
|
+
<header>
|
1082
|
+
<h3>Public Class Methods</h3>
|
1083
|
+
</header>
|
1084
|
+
|
1085
|
+
|
1086
|
+
<div id="method-c-action_args" class="method-detail ">
|
1087
|
+
|
1088
|
+
<div class="method-heading">
|
1089
|
+
<span class="method-name">action_args</span><span
|
1090
|
+
class="method-args">(action)</span>
|
1091
|
+
|
1092
|
+
<span class="method-click-advice">click to toggle source</span>
|
1093
|
+
|
1094
|
+
</div>
|
1095
|
+
|
1096
|
+
|
1097
|
+
<div class="method-description">
|
1098
|
+
|
1099
|
+
<p>Returns an array with the names of the arguments of the specified action.</p>
|
1100
|
+
|
1101
|
+
<p>For example:</p>
|
1102
|
+
|
1103
|
+
<pre class="ruby"><span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">action_args</span> <span class="ruby-string">'assert'</span>
|
1104
|
+
<span class="ruby-comment"># => [ "selector", "text" ]</span>
|
1105
|
+
</pre>
|
1106
|
+
|
1107
|
+
|
1108
|
+
|
1109
|
+
|
1110
|
+
<div class="method-source-code" id="action_args-source">
|
1111
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 398</span>
|
1112
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">action_args</span>(<span class="ruby-identifier">action</span>)
|
1113
|
+
<span class="ruby-identifier">action</span> <span class="ruby-operator">+=</span> <span class="ruby-string">'_action'</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">_action_methods</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">action</span>
|
1114
|
+
<span class="ruby-constant">Action</span>.<span class="ruby-identifier">public_instance_method</span>(<span class="ruby-identifier">action</span>).<span class="ruby-identifier">parameters</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">att</span>, <span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span> }
|
1115
|
+
<span class="ruby-keyword">end</span></pre>
|
1116
|
+
</div>
|
1117
|
+
|
1118
|
+
</div>
|
1119
|
+
|
1120
|
+
|
1121
|
+
|
1122
|
+
|
1123
|
+
</div>
|
1124
|
+
|
1125
|
+
|
1126
|
+
<div id="method-c-actions" class="method-detail ">
|
1127
|
+
|
1128
|
+
<div class="method-heading">
|
1129
|
+
<span class="method-name">actions</span><span
|
1130
|
+
class="method-args">()</span>
|
1131
|
+
|
1132
|
+
<span class="method-click-advice">click to toggle source</span>
|
1133
|
+
|
1134
|
+
</div>
|
1135
|
+
|
1136
|
+
|
1137
|
+
<div class="method-description">
|
1138
|
+
|
1139
|
+
<p>Returns an array with the names of every action available.</p>
|
1140
|
+
|
1141
|
+
<p>For example:</p>
|
1142
|
+
|
1143
|
+
<pre class="ruby"><span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">actions</span>
|
1144
|
+
<span class="ruby-comment"># => [ "assert", "break", ... ]</span>
|
1145
|
+
</pre>
|
1146
|
+
|
1147
|
+
|
1148
|
+
|
1149
|
+
|
1150
|
+
<div class="method-source-code" id="actions-source">
|
1151
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 388</span>
|
1152
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">actions</span>
|
1153
|
+
<span class="ruby-identifier">_action_methods</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/_action$/</span>, <span class="ruby-string">''</span>) }
|
1154
|
+
<span class="ruby-keyword">end</span></pre>
|
1155
|
+
</div>
|
1156
|
+
|
1157
|
+
</div>
|
1158
|
+
|
1159
|
+
|
1160
|
+
|
1161
|
+
|
1162
|
+
</div>
|
1163
|
+
|
1164
|
+
|
1165
|
+
<div id="method-c-loggers" class="method-detail ">
|
1166
|
+
|
1167
|
+
<div class="method-heading">
|
1168
|
+
<span class="method-name">loggers</span><span
|
1169
|
+
class="method-args">()</span>
|
1170
|
+
|
1171
|
+
<span class="method-click-advice">click to toggle source</span>
|
1172
|
+
|
1173
|
+
</div>
|
1174
|
+
|
1175
|
+
|
1176
|
+
<div class="method-description">
|
1177
|
+
|
1178
|
+
<p>Returns an array with the names of every logger available.</p>
|
1179
|
+
|
1180
|
+
<p>For example:</p>
|
1181
|
+
|
1182
|
+
<pre class="ruby"><span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">loggers</span>
|
1183
|
+
<span class="ruby-comment"># => [ "null", "bash", ... ]</span>
|
1184
|
+
</pre>
|
1185
|
+
|
1186
|
+
|
1187
|
+
|
1188
|
+
|
1189
|
+
<div class="method-source-code" id="loggers-source">
|
1190
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 427</span>
|
1191
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">loggers</span>
|
1192
|
+
<span class="ruby-constant">Loggers</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">l</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/logger$/</span>, <span class="ruby-string">''</span>) }
|
1193
|
+
<span class="ruby-keyword">end</span></pre>
|
1194
|
+
</div>
|
1195
|
+
|
1196
|
+
</div>
|
1197
|
+
|
1198
|
+
|
1199
|
+
|
1200
|
+
|
1201
|
+
</div>
|
1202
|
+
|
1203
|
+
|
1204
|
+
<div id="method-c-max_action_name_size" class="method-detail ">
|
1205
|
+
|
1206
|
+
<div class="method-heading">
|
1207
|
+
<span class="method-name">max_action_name_size</span><span
|
1208
|
+
class="method-args">()</span>
|
1209
|
+
|
1210
|
+
<span class="method-click-advice">click to toggle source</span>
|
1211
|
+
|
1212
|
+
</div>
|
1213
|
+
|
1214
|
+
|
1215
|
+
<div class="method-description">
|
1216
|
+
|
1217
|
+
<p>Returns the maximum size in characters of an action name.</p>
|
1218
|
+
|
1219
|
+
<p>This method is useful to pretty print lists of actions</p>
|
1220
|
+
|
1221
|
+
<p>For example:</p>
|
1222
|
+
|
1223
|
+
<pre class="ruby"><span class="ruby-comment"># assuming actions = [ "echo", "assert", "tryload" ]</span>
|
1224
|
+
<span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">max_action_name_size</span>
|
1225
|
+
<span class="ruby-comment"># => 7</span>
|
1226
|
+
</pre>
|
1227
|
+
|
1228
|
+
|
1229
|
+
|
1230
|
+
|
1231
|
+
<div class="method-source-code" id="max_action_name_size-source">
|
1232
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 439</span>
|
1233
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">max_action_name_size</span>
|
1234
|
+
<span class="ruby-identifier">actions</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">0</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span>,<span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-identifier">s</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">s</span> }
|
1235
|
+
<span class="ruby-keyword">end</span></pre>
|
1236
|
+
</div>
|
1237
|
+
|
1238
|
+
</div>
|
1239
|
+
|
1240
|
+
|
1241
|
+
|
1242
|
+
|
1243
|
+
</div>
|
1244
|
+
|
1245
|
+
|
1246
|
+
<div id="method-c-selectors" class="method-detail ">
|
1247
|
+
|
1248
|
+
<div class="method-heading">
|
1249
|
+
<span class="method-name">selectors</span><span
|
1250
|
+
class="method-args">(include_standard_selectors = true)</span>
|
1251
|
+
|
1252
|
+
<span class="method-click-advice">click to toggle source</span>
|
1253
|
+
|
1254
|
+
</div>
|
1255
|
+
|
1256
|
+
|
1257
|
+
<div class="method-description">
|
1258
|
+
|
1259
|
+
<p>Returns an array with the names of every selector available.</p>
|
1260
|
+
|
1261
|
+
<p>If <code>include_standard_selectors</code> is <code>true</code> (default
|
1262
|
+
behavior) both standard and custom selector are returned, otherwise only
|
1263
|
+
custom selectors are returned.</p>
|
1264
|
+
|
1265
|
+
<p>For example:</p>
|
1266
|
+
|
1267
|
+
<pre class="ruby"><span class="ruby-constant">Context</span><span class="ruby-operator">::</span><span class="ruby-identifier">selectors</span>
|
1268
|
+
<span class="ruby-comment"># => [ "class", "id", ... ]</span>
|
1269
|
+
</pre>
|
1270
|
+
|
1271
|
+
|
1272
|
+
|
1273
|
+
|
1274
|
+
<div class="method-source-code" id="selectors-source">
|
1275
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 413</span>
|
1276
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">selectors</span>(<span class="ruby-identifier">include_standard_selectors</span> = <span class="ruby-keyword">true</span>)
|
1277
|
+
<span class="ruby-identifier">ret</span> = <span class="ruby-constant">Selector</span>.<span class="ruby-identifier">public_instance_methods</span>(<span class="ruby-keyword">false</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/_selector$/</span>, <span class="ruby-string">''</span>) }
|
1278
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">include_standard_selectors</span>
|
1279
|
+
<span class="ruby-identifier">ret</span> <span class="ruby-operator">+=</span> <span class="ruby-constant">Selenium</span><span class="ruby-operator">::</span><span class="ruby-constant">WebDriver</span><span class="ruby-operator">::</span><span class="ruby-constant">SearchContext</span><span class="ruby-operator">::</span><span class="ruby-constant">FINDERS</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span> }
|
1280
|
+
<span class="ruby-keyword">end</span>
|
1281
|
+
<span class="ruby-identifier">ret</span>
|
1282
|
+
<span class="ruby-keyword">end</span></pre>
|
1283
|
+
</div>
|
1284
|
+
|
1285
|
+
</div>
|
1286
|
+
|
1287
|
+
|
1288
|
+
|
1289
|
+
|
1290
|
+
</div>
|
1291
|
+
|
1292
|
+
|
1293
|
+
</section>
|
1294
|
+
|
1295
|
+
</section>
|
1296
|
+
|
1297
|
+
|
1298
|
+
|
1299
|
+
<section id="Variable+manipulation+methods" class="documentation-section">
|
1300
|
+
|
1301
|
+
<header class="documentation-section-title">
|
1302
|
+
<h2>
|
1303
|
+
Variable manipulation methods
|
1304
|
+
</h2>
|
1305
|
+
<span class="section-click-top">
|
1306
|
+
<a href="#top">↑ top</a>
|
1307
|
+
</span>
|
1308
|
+
</header>
|
1309
|
+
|
1310
|
+
|
1311
|
+
|
1312
|
+
|
1313
|
+
|
1314
|
+
|
1315
|
+
|
1316
|
+
|
1317
|
+
|
1318
|
+
<section id="public-instance-Variable+manipulation+methods-method-details" class="method-section">
|
1319
|
+
<header>
|
1320
|
+
<h3>Public Instance Methods</h3>
|
1321
|
+
</header>
|
1322
|
+
|
1323
|
+
|
1324
|
+
<div id="method-i-expand" class="method-detail ">
|
1325
|
+
|
1326
|
+
<div class="method-heading">
|
1327
|
+
<span class="method-name">expand</span><span
|
1328
|
+
class="method-args">(s)</span>
|
1329
|
+
|
1330
|
+
<span class="method-click-advice">click to toggle source</span>
|
1331
|
+
|
1332
|
+
</div>
|
1333
|
+
|
1334
|
+
|
1335
|
+
<div class="method-description">
|
1336
|
+
|
1337
|
+
<p>Recursively replaces occurencies of variable expansions in <code>s</code>
|
1338
|
+
with the corresponding variable value.</p>
|
1339
|
+
|
1340
|
+
<p>The variable expansion expression format is:</p>
|
1341
|
+
|
1342
|
+
<pre>'${variable_name}'</pre>
|
1343
|
+
|
1344
|
+
<p>For example:</p>
|
1345
|
+
|
1346
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">variables</span> = { <span class="ruby-string">'a'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'1'</span>, <span class="ruby-string">'b'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'2'</span>, <span class="ruby-string">'c'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'a'</span> }
|
1347
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">expand</span> <span class="ruby-string">'${a}'</span> <span class="ruby-comment"># => '1'</span>
|
1348
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">expand</span> <span class="ruby-string">'${b}'</span> <span class="ruby-comment"># => '2'</span>
|
1349
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">expand</span> <span class="ruby-string">'${c}'</span> <span class="ruby-comment"># => 'a'</span>
|
1350
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">expand</span> <span class="ruby-string">'${${c}}'</span> <span class="ruby-comment"># => '1'</span>
|
1351
|
+
</pre>
|
1352
|
+
|
1353
|
+
|
1354
|
+
|
1355
|
+
|
1356
|
+
<div class="method-source-code" id="expand-source">
|
1357
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 460</span>
|
1358
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">expand</span>(<span class="ruby-identifier">s</span>)
|
1359
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-ivar">@variables</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-identifier">s</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s</span>,<span class="ruby-identifier">kv</span><span class="ruby-operator">|</span>
|
1360
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-identifier">s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-node">/\$\{#{kv[0]}\}/</span>, <span class="ruby-identifier">kv</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_s</span>)
|
1361
|
+
<span class="ruby-keyword">end</span>
|
1362
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">expand</span>(<span class="ruby-identifier">result</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">result</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">s</span>
|
1363
|
+
<span class="ruby-identifier">result</span>
|
1364
|
+
<span class="ruby-keyword">end</span></pre>
|
1365
|
+
</div>
|
1366
|
+
|
1367
|
+
</div>
|
1368
|
+
|
1369
|
+
|
1370
|
+
|
1371
|
+
|
1372
|
+
</div>
|
1373
|
+
|
1374
|
+
|
1375
|
+
<div id="method-i-with_vars" class="method-detail ">
|
1376
|
+
|
1377
|
+
<div class="method-heading">
|
1378
|
+
<span class="method-name">with_vars</span><span
|
1379
|
+
class="method-args">(vars) { || ... }</span>
|
1380
|
+
|
1381
|
+
<span class="method-click-advice">click to toggle source</span>
|
1382
|
+
|
1383
|
+
</div>
|
1384
|
+
|
1385
|
+
|
1386
|
+
<div class="method-description">
|
1387
|
+
|
1388
|
+
<p>Temporarily alter the value of context variables.</p>
|
1389
|
+
|
1390
|
+
<p>This method alters the value of the variables specified in the
|
1391
|
+
<code>vars</code> hash for the duration of the given <code>block</code>.
|
1392
|
+
When the <code>block</code> completes, the original value of the context
|
1393
|
+
variables is restored.</p>
|
1394
|
+
|
1395
|
+
<p>For example:</p>
|
1396
|
+
|
1397
|
+
<pre class="ruby"><span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">variables</span> = { <span class="ruby-string">'a'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'1'</span>, <span class="ruby-string">'b'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'2'</span>, <span class="ruby-identifier">c</span> =<span class="ruby-operator">></span> <span class="ruby-string">'a'</span> }
|
1398
|
+
<span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">with_vars</span>({ <span class="ruby-string">'a'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'10'</span>, <span class="ruby-identifier">d</span> =<span class="ruby-operator">></span> <span class="ruby-string">'20'</span> }) <span class="ruby-keyword">do</span>
|
1399
|
+
<span class="ruby-identifier">p</span> <span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">variables</span>
|
1400
|
+
<span class="ruby-comment"># => {"a"=>"10", "b"=>"2", "c"=>"a", "d"=>"20"}</span>
|
1401
|
+
<span class="ruby-keyword">end</span>
|
1402
|
+
<span class="ruby-identifier">p</span> <span class="ruby-identifier">ctx</span>.<span class="ruby-identifier">variables</span>
|
1403
|
+
<span class="ruby-comment"># => {"a"=>"1", "b"=>"2", "c"=>"a"}</span>
|
1404
|
+
</pre>
|
1405
|
+
|
1406
|
+
|
1407
|
+
|
1408
|
+
|
1409
|
+
<div class="method-source-code" id="with_vars-source">
|
1410
|
+
<pre><span class="ruby-comment"># File lib/bauxite/core/Context.rb, line 483</span>
|
1411
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">with_vars</span>(<span class="ruby-identifier">vars</span>)
|
1412
|
+
<span class="ruby-identifier">current</span> = <span class="ruby-ivar">@variables</span>
|
1413
|
+
<span class="ruby-ivar">@variables</span> = <span class="ruby-ivar">@variables</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">vars</span>)
|
1414
|
+
<span class="ruby-keyword">yield</span>
|
1415
|
+
<span class="ruby-keyword">ensure</span>
|
1416
|
+
<span class="ruby-ivar">@variables</span> = <span class="ruby-identifier">current</span>
|
1417
|
+
<span class="ruby-keyword">end</span></pre>
|
1418
|
+
</div>
|
1419
|
+
|
1420
|
+
</div>
|
1421
|
+
|
1422
|
+
|
1423
|
+
|
1424
|
+
|
1425
|
+
</div>
|
1426
|
+
|
1427
|
+
|
1428
|
+
</section>
|
1429
|
+
|
1430
|
+
</section>
|
1431
|
+
</main>
|
1432
|
+
|
1433
|
+
|
1434
|
+
<footer id="validator-badges" role="contentinfo">
|
1435
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
1436
|
+
<p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.1.
|
1437
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
1438
|
+
</footer>
|
1439
|
+
|