bauxite 0.4.0 → 0.4.1

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.
data/doc/index.html CHANGED
@@ -55,12 +55,23 @@
55
55
  </div>
56
56
 
57
57
  <div id="project-metadata">
58
-
58
+ <div id="fileindex-section" class="nav-section">
59
+ <h3>Pages</h3>
60
+
61
+ <ul class="link-list">
62
+
63
+ <li><a href="./README_md.html">README</a>
64
+
65
+ </ul>
66
+ </div>
67
+
59
68
  <div id="classindex-section" class="nav-section">
60
69
  <h3>Class and Module Index</h3>
61
70
 
62
71
  <ul class="link-list">
63
72
 
73
+ <li><a href="./Bauxite.html">Bauxite</a>
74
+
64
75
  <li><a href="./Bauxite/Action.html">Bauxite::Action</a>
65
76
 
66
77
  <li><a href="./Bauxite/ActionModule.html">Bauxite::ActionModule</a>
@@ -91,6 +102,8 @@
91
102
 
92
103
  <li><a href="./Bauxite/Loggers/XtermLogger.html">Bauxite::Loggers::XtermLogger</a>
93
104
 
105
+ <li><a href="./Bauxite/Parser.html">Bauxite::Parser</a>
106
+
94
107
  <li><a href="./Bauxite/ParserModule.html">Bauxite::ParserModule</a>
95
108
 
96
109
  <li><a href="./Bauxite/Selector.html">Bauxite::Selector</a>
@@ -104,14 +117,353 @@
104
117
  </nav>
105
118
 
106
119
  <main role="main">
107
- <p>This is the API documentation for RDoc Documentation.
120
+
121
+
122
+ <h1 id="label-bauxite">bauxite<span><a href="#label-bauxite">&para;</a> <a href="#documentation">&uarr;</a></span></h1>
123
+
124
+ <p><a href="Bauxite.html">Bauxite</a> is a façade over Selenium intended for
125
+ non-developers</p>
126
+
127
+ <p>The idea behind this project was to create a tool that allows
128
+ non-developers to write web tests in a human-readable language. Another
129
+ major requirement is to be able to easily extend the test language to
130
+ create functional abstractions over technical details.</p>
131
+
132
+ <p>Take a look at the following Ruby excerpt from <a
133
+ href="http://code.google.com/p/selenium/wiki/RubyBindings">code.google.com/p/selenium/wiki/RubyBindings</a>:</p>
134
+
135
+ <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;selenium-webdriver&quot;</span>
136
+
137
+ <span class="ruby-identifier">driver</span> = <span class="ruby-constant">Selenium</span><span class="ruby-operator">::</span><span class="ruby-constant">WebDriver</span>.<span class="ruby-identifier">for</span> :<span class="ruby-identifier">firefox</span>
138
+ <span class="ruby-identifier">driver</span>.<span class="ruby-identifier">navigate</span>.<span class="ruby-identifier">to</span> <span class="ruby-string">&quot;http://google.com&quot;</span>
139
+
140
+ <span class="ruby-identifier">element</span> = <span class="ruby-identifier">driver</span>.<span class="ruby-identifier">find_element</span>(:<span class="ruby-identifier">name</span>, <span class="ruby-string">&#39;q&#39;</span>)
141
+ <span class="ruby-identifier">element</span>.<span class="ruby-identifier">send_keys</span> <span class="ruby-string">&quot;Hello WebDriver!&quot;</span>
142
+ <span class="ruby-identifier">element</span>.<span class="ruby-identifier">submit</span>
143
+
144
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">driver</span>.<span class="ruby-identifier">title</span>
145
+
146
+ <span class="ruby-identifier">driver</span>.<span class="ruby-identifier">quit</span>
147
+ </pre>
148
+
149
+ <p>While developers might find that code expressive enough, non-developers
150
+ might be a bit shocked.</p>
151
+
152
+ <p>The equivalent <a href="Bauxite.html">Bauxite</a> test is easier on the
153
+ eyes:</p>
154
+
155
+ <pre>open &quot;http://google.com&quot;
156
+ write &quot;name=q&quot; &quot;Hello WebDriver!&quot;
157
+ click &quot;gbqfb&quot;</pre>
158
+
159
+ <h2 id="label-Installation">Installation<span><a href="#label-Installation">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
160
+
161
+ <p>In a nutshell:</p>
162
+
163
+ <pre>gem install bauxite</pre>
164
+
165
+ <p>If you don&#39;t have Ruby 2.x yet, check the <a
166
+ href="#installing-ruby">Installing Ruby</a> section below.</p>
167
+
168
+ <p>Remember you should probably install <a
169
+ href="http://www.mozilla.org">Firefox</a> (unless you want to use other
170
+ browsers or Selenium server by specifying the <code>-p</code> switch to the
171
+ <code>bauxite</code> executable).</p>
172
+
173
+ <h2 id="label-Hello+World">Hello World<span><a href="#label-Hello+World">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
174
+
175
+ <p>Paste the following text into <code>hello.bxt</code>:</p>
176
+
177
+ <pre>open &quot;http://www.gnu.org/fun/jokes/helloworld.html&quot;</pre>
178
+
179
+ <p>Launch a terminal/command prompt and type:</p>
180
+
181
+ <pre>bauxite hello.bxt</pre>
182
+
183
+ <h2 id="label-Command-line+Interface">Command-line Interface<span><a href="#label-Command-line+Interface">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
184
+
185
+ <p>The <code>bauxite</code> command-line program supports several
186
+ configuration options.</p>
187
+
188
+ <p>Refer to the <a
189
+ href="http://pzavolinsky.github.io/bauxite/Bauxite/Application.html">RDoc
190
+ documentation</a> for more details.</p>
191
+
192
+ <h2 id="label-The+Bauxite+Language">The <a href="Bauxite.html">Bauxite</a> Language<span><a href="#label-The+Bauxite+Language">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
193
+
194
+ <p>The <a href="Bauxite.html">Bauxite</a> language is composed of two elements
195
+ <code>Actions</code> and <code>Selectors</code>: Actions are testing
196
+ operations such as “open this page”, “click this button”, “write this text
197
+ into that textbox”, etc. Selectors are ways of locating interesting
198
+ elements of a page such as a button, a textbox, a label, etc.</p>
199
+
200
+ <p>A typical <a href="Bauxite.html">Bauxite</a> test is a plain text file that
201
+ contains a series of Actions (one per line). Depending on the Action, a few
202
+ action arguments might need to be specified as well. For example in:</p>
203
+
204
+ <pre>open &quot;http://google.com&quot;
205
+ write &quot;name=q&quot; &quot;Hello WebDriver!&quot;
206
+ click &quot;gbqfb&quot;</pre>
207
+
208
+ <p><code>open</code>, <code>write</code> and <code>click</code> are Actions: -
209
+ <code>open</code> takes a single URL argument
210
+ (<code>&quot;http://google.com&quot;</code>) and opens that URL in the
211
+ browser. - <code>write</code> takes two arguments, a Selector
212
+ (<code>name=q</code>, more on this in a bit) and a text (<code>&quot;Hello
213
+ WebDriver!&quot;</code>), and writes the text into the element specified by
214
+ the Selector. - <code>click</code> takes a single Selector argument
215
+ (<code>gbqfb</code>) and clicks the element specified by the Selector.</p>
216
+
217
+ <p>In general, Action arguments can be surrounded by optional double quote
218
+ characters (<code>&quot;</code>). If an argument contains a space
219
+ character, the quotes are mandatory (this is the case for the second
220
+ argument to <code>write</code> in the example above).</p>
221
+
222
+ <p>Some Actions operate on page elements (e.g. <code>write</code>,
223
+ <code>click</code>, etc.). In order to locate these elements, <a
224
+ href="Bauxite.html">Bauxite</a> uses Selectors.</p>
225
+
226
+ <p>The trivial Selector is just a text that matches the last portion of the
227
+ <code>id</code> attribute of the target element.</p>
228
+
229
+ <p>For example, in this HTML fragment:</p>
230
+
231
+ <pre>&lt;input type=&quot;submit&quot; id=&quot;gbqfb&quot; value=&quot;Search&quot; /&gt;</pre>
232
+
233
+ <p>If we want to click the “Search” button we can do the following:</p>
234
+
235
+ <pre>click &quot;gbqfb&quot;</pre>
236
+
237
+ <p><a href="Bauxite.html">Bauxite</a> supports several other Selectors such as
238
+ <code>name=</code> in the example above. The <code>name</code> Selector
239
+ finds elements whose <code>name</code> attribute matches the text following
240
+ the <code>=</code> sign.</p>
241
+
242
+ <p>For example, in this HTML fragment:</p>
243
+
244
+ <pre>&lt;input type=&quot;text&quot; name=&quot;q&quot; /&gt;</pre>
245
+
246
+ <p>If we want to type the text “Hello WebDriver!” in textbox we can do the
247
+ following:</p>
248
+
249
+ <pre>write &quot;name=q&quot; &quot;Hello WebDriver!&quot;</pre>
250
+
251
+ <p>This section presented a brief introduction into the basic <a
252
+ href="Bauxite.html">Bauxite</a> concepts. For more details and a list of
253
+ every Action and Selector available, refer to the RDoc generated
254
+ documentation in:</p>
255
+ <ul><li>
256
+ <p><a
257
+ href="http://pzavolinsky.github.io/bauxite/Bauxite/Action.html#Action+Methods">Available
258
+ Actions</a></p>
259
+ </li><li>
260
+ <p><a
261
+ href="http://pzavolinsky.github.io/bauxite/Bauxite/Selector.html#Selector+Methods">Available
262
+ Bauxite Selectors</a></p>
263
+ </li><li>
264
+ <p><a
265
+ href="http://pzavolinsky.github.io/bauxite/Bauxite/Selector.html#class-Bauxite::Selector-label-Standard+Selenium+Selectors">Selenium
266
+ Standard Selectors</a></p>
267
+ </li><li>
268
+ <p><a href="http://pzavolinsky.github.io/bauxite/Bauxite/Action.html">Creating
269
+ new Actions</a></p>
270
+ </li><li>
271
+ <p><a
272
+ href="http://pzavolinsky.github.io/bauxite/Bauxite/Selector.html">Creating
273
+ new Selectors</a></p>
274
+ </li></ul>
275
+
276
+ <h2 id="label-Installing+Ruby">Installing Ruby<span><a href="#label-Installing+Ruby">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
277
+
278
+ <p>I won&#39;t cover all the details of installing Ruby on your system (Google
279
+ knows best), but the following should probably work.</p>
280
+
281
+ <p>In GNU/Linux, you can install <a href="http://rvm.io/">RVM</a>, then Ruby:</p>
282
+
283
+ <pre>curl -sSL https://get.rvm.io | bash -s stable
284
+ source ~/.rvm/scripts/rvm
285
+ rvm install ruby-2.1.0</pre>
286
+
287
+ <p>In Windows, you can install Ruby 2.x with <a
288
+ href="http://rubyinstaller.org/downloads/">RubyInstaller</a>. After
289
+ everything is installed, launch the <code>Start Command Prompt with
290
+ Ruby</code> option in your start menu.</p>
291
+
292
+ <p>Regadless of your OS, you should be able to install <a
293
+ href="Bauxite.html">Bauxite</a> with:</p>
294
+
295
+ <pre>gem install bauxite</pre>
296
+
297
+ <h2 id="label-Implementation">Implementation<span><a href="#label-Implementation">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
298
+
299
+ <p><a href="Bauxite.html">Bauxite</a> is both a command-line program and a
300
+ library. You can use the program to run <a href="Bauxite.html">Bauxite</a>
301
+ tests directly from a terminal, or you can embed the library in your own
302
+ application.</p>
303
+
304
+ <p>The command-line program is called <code>bauxite</code> and has several
305
+ command-line options, refer to the <a
306
+ href="http://pzavolinsky.github.io/bauxite/Bauxite/Application.html">RDoc
307
+ documentation</a> for more details.</p>
308
+
309
+ <p>If you are looking to embed <a href="Bauxite.html">Bauxite</a> in your
310
+ application take a look a the code in
311
+ <code>lib/bauxite/application.rb</code>, that should give you a full
312
+ example of how to create a <a href="Bauxite.html">Bauxite</a> Context and
313
+ execute some actions.</p>
314
+
315
+ <h2 id="label-Extending+Bauxite">Extending <a href="Bauxite.html">Bauxite</a><span><a href="#label-Extending+Bauxite">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
316
+
317
+ <p><a href="Bauxite.html">Bauxite</a> supports two types of extensions:
318
+ functional extensions and coded plugins.</p>
319
+
320
+ <h3 id="label-Functional+extensions">Functional extensions<span><a href="#label-Functional+extensions">&para;</a> <a href="#documentation">&uarr;</a></span></h3>
321
+
322
+ <p>Functional extensions are composite constructs created using existing <a
323
+ href="Bauxite.html">Bauxite</a> actions to convey functional meaning. For
324
+ example, imagine a login form:</p>
325
+
326
+ <pre>&lt;!-- http://hostname/login.html --&gt;
327
+ &lt;form&gt;
328
+ &lt;input id=&quot;username&quot; name=&quot;username&quot; type=&quot;text&quot; /&gt;
329
+ &lt;input id=&quot;password&quot; name=&quot;password&quot; type=&quot;password&quot; /&gt;
330
+ &lt;input id=&quot;login&quot; type=&quot;submit&quot; value=&quot;Login&quot;/&gt;
331
+ &lt;/form&gt;</pre>
332
+
333
+ <p>The <a href="Bauxite.html">Bauxite</a> code to login into this site would
334
+ be:</p>
335
+
336
+ <pre>open &quot;http://hostname/login.html&quot;
337
+ write &quot;username&quot; &quot;jdoe&quot;
338
+ write &quot;password&quot; &quot;hello world!&quot;
339
+ click &quot;login&quot;</pre>
340
+
341
+ <p>If we were creating a suite of automated web tests for our
342
+ <em>hostname</em> site, we&#39;ll probably need to login into the site
343
+ several times. This would mean copy/pasting the four lines above into every
344
+ test in our suite.</p>
345
+
346
+ <p>Of course we can do better. We can split <a href="Bauxite.html">Bauxite</a>
347
+ tests into many files and include one test into another with the
348
+ <code>load</code> action.</p>
349
+
350
+ <pre># my_test.bxt (by the way, this is a comment)
351
+ load other_test_fragment.bxt
352
+ ...</pre>
353
+
354
+ <p>Back to our login example, first we can package the login part of our tests
355
+ into a separate <a href="Bauxite.html">Bauxite</a> file:</p>
356
+
357
+ <pre># login.bxt
358
+ open &quot;http://hostname/login.html&quot;
359
+ write &quot;username&quot; &quot;jdoe&quot;
360
+ write &quot;password&quot; &quot;hello world!&quot;
361
+ click &quot;login&quot;</pre>
362
+
363
+ <p>Of course we would like to be able to login with different
364
+ username/password combinations, so we can replace the literals in
365
+ <code>login.bxt</code> with variables:</p>
366
+
367
+ <pre># login.bxt
368
+ open &quot;http://hostname/login.html&quot;
369
+ write &quot;username&quot; &quot;${username}&quot;
370
+ write &quot;password&quot; &quot;${password}&quot;
371
+ click &quot;login&quot;</pre>
372
+
373
+ <p>Now, we would like to assert that both <code>username</code> and
374
+ <code>password</code> variables are set before calling our test (just in
375
+ case someone forgets). We can do this with <code>params</code></p>
376
+
377
+ <pre># login.bxt
378
+ params username password
379
+ open &quot;http://hostname/login.html&quot;
380
+ write &quot;username&quot; &quot;${username}&quot;
381
+ write &quot;password&quot; &quot;${password}&quot;
382
+ click &quot;login&quot;</pre>
383
+
384
+ <p>In our main test we can load <code>login.bxt</code> and specify the
385
+ variables required using this code:</p>
386
+
387
+ <pre># main_test.bxt
388
+ load &quot;login.bxt&quot; &quot;username=jdoe&quot; &quot;password=hello world!&quot;
389
+
390
+ # additional actions go here</pre>
391
+
392
+ <p>We could improve this even further by creating an <code>alias</code> to
393
+ simplify the login process. To do this, lets create an new file called
394
+ <code>alias.bxt</code>:</p>
395
+
396
+ <pre># alias.bxt
397
+ alias &quot;login&quot; &quot;load&quot; &quot;login.bxt&quot; &quot;username=${1}&quot; &quot;password=${2}&quot;</pre>
398
+
399
+ <p>Note that the <code>alias</code> action supports positional arguments.</p>
400
+
401
+ <p>Now we can change our main test to use our alias:</p>
402
+
403
+ <pre># main_test.bxt
404
+ load &quot;alias.bxt&quot;
405
+
406
+ login &quot;jdoe&quot; &quot;hello world!&quot;
407
+
408
+ # additional actions go here</pre>
409
+
410
+ <p>That was a bit of work but the resulting test is purely functional (minus
411
+ the load alias part, of course).</p>
412
+
413
+ <h3 id="label-Coded+plugins">Coded plugins<span><a href="#label-Coded+plugins">&para;</a> <a href="#documentation">&uarr;</a></span></h3>
414
+
415
+ <p>Coded plugins are Ruby files that extend the <a
416
+ href="Bauxite.html">Bauxite</a> language by providing additional language
417
+ elements. Coded plugins can be used to create <a
418
+ href="Bauxite.html">Bauxite</a> actions, selectors and loggers.</p>
419
+
420
+ <p>For example lets assume that throughout a web application input elements
421
+ were identified using a custom HTML attribute instead of <code>id</code>.
422
+ For example:</p>
423
+
424
+ <pre>&lt;form&gt;
425
+ &lt;input custom-attr=&quot;username&quot; type=&quot;text&quot; /&gt;
426
+ &lt;input custom-attr=&quot;password&quot; type=&quot;password&quot; /&gt;
427
+ &lt;input custom-attr=&quot;login&quot; type=&quot;submit&quot; value=&quot;Login&quot;/&gt;
428
+ &lt;/form&gt;</pre>
429
+
430
+ <p>Using standard <a href="Bauxite.html">Bauxite</a> language we could select
431
+ these elements using:</p>
432
+
433
+ <pre># === my_test.bxt === #
434
+ write &quot;attr=custom-attr:username&quot; &quot;jdoe&quot;
435
+ write &quot;attr=custom-attr:password&quot; &quot;hello world!&quot;
436
+ click &quot;attr=custom-attr:login&quot;</pre>
437
+
438
+ <p>But we can improve the overall readability of our test by using a coded
439
+ plugin:</p>
440
+
441
+ <pre class="ruby"><span class="ruby-comment"># === plugins/custom_selector.rb === #</span>
442
+ <span class="ruby-keyword">class</span> <span class="ruby-constant">Bauxite</span><span class="ruby-operator">::</span><span class="ruby-constant">Selector</span>
443
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">custom</span>(<span class="ruby-identifier">value</span>)
444
+ <span class="ruby-identifier">attr</span> <span class="ruby-node">&quot;custom-attr:#{value}&quot;</span>
445
+ <span class="ruby-keyword">end</span>
446
+ <span class="ruby-keyword">end</span>
447
+ </pre>
448
+
449
+ <p>Now we can change our test to look like this:</p>
450
+
451
+ <pre># === my_test.bxt === #
452
+ write &quot;custom=username&quot; &quot;jdoe&quot;
453
+ write &quot;custom=password&quot; &quot;hello world!&quot;
454
+ click &quot;custom=login&quot;</pre>
455
+
456
+ <p>Finally, to execute <a href="Bauxite.html">Bauxite</a> loading our plugin
457
+ we can type:</p>
458
+
459
+ <pre>bauxite -e plugins my_test.bxt</pre>
108
460
  </main>
109
461
 
110
462
 
111
463
 
112
464
  <footer id="validator-badges" role="contentinfo">
113
465
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
114
- <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.0.
466
+ <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.1.
115
467
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
116
468
  </footer>
117
469