bauxite 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -143,7 +143,8 @@ module Bauxite
143
143
  @variables = {
144
144
  '__TIMEOUT__' => (options[:timeout] || 10).to_i,
145
145
  '__DEBUG__' => false,
146
- '__SELECTOR__' => options[:selector] || 'sid'
146
+ '__SELECTOR__' => options[:selector] || 'sid',
147
+ '__OUTPUT__' => options[:output]
147
148
  }
148
149
  @aliases = {}
149
150
  @tests = []
@@ -155,9 +156,7 @@ module Bauxite
155
156
 
156
157
  _load_extensions(options[:extensions] || [])
157
158
 
158
- handle_errors do
159
- @logger = Context::load_logger(options[:logger], options[:logger_opt])
160
- end
159
+ @logger = Context::load_logger(options[:logger], options[:logger_opt])
161
160
 
162
161
  @parser = Parser.new(self)
163
162
  end
@@ -181,7 +180,13 @@ module Bauxite
181
180
  return unless actions.size > 0
182
181
  begin
183
182
  actions.each do |action|
184
- exec_action(action)
183
+ begin
184
+ exec_action(action)
185
+ rescue StandardError => e
186
+ print_error(e)
187
+ raise unless @options[:debug]
188
+ debug
189
+ end
185
190
  end
186
191
  ensure
187
192
  stop
@@ -310,78 +315,29 @@ module Bauxite
310
315
  # Executes the specified action handling errors, logging and debug
311
316
  # history.
312
317
  #
318
+ # If +log+ is +true+, log the action execution (default behavior).
319
+ #
313
320
  # This method if part of the action execution chain and is intended
314
321
  # for advanced use (e.g. in complex actions). To execute an Action
315
322
  # directly, the #exec_action method is preferred.
316
323
  #
317
- # If +log+ is +true+, log the action execution (default behavior).
318
- #
319
324
  # For example:
320
325
  # ctx.exec_action 'open "http://www.ruby-lang.org"'
321
326
  # # => navigates to www.ruby-lang.org
322
327
  #
323
328
  def exec_parsed_action(action, args, log = true, text = nil, file = nil, line = nil)
324
- ret = handle_errors(true) do
325
-
326
- action = get_action(action, args, text, file, line)
327
-
328
- if log
329
- @logger.log_cmd(action) do
330
- Readline::HISTORY << action.text
331
- exec_action_object(action)
332
- end
333
- else
334
- exec_action_object(action)
329
+ action = get_action(action, args, text, file, line)
330
+ ret = nil
331
+ if log
332
+ @logger.log_cmd(action) do
333
+ Readline::HISTORY << action.text
334
+ ret = exec_action_object(action)
335
335
  end
336
- end
337
- handle_errors(true) do
338
- ret.call if ret.respond_to? :call # delayed actions (after log_cmd)
339
- end
340
- end
341
-
342
-
343
- # Executes the +block+ inside a rescue block applying standard criteria of
344
- # error handling.
345
- #
346
- # The default behavior is to print the exception message and exit.
347
- #
348
- # If the +:verbose+ option is set, the exception backtrace will also be
349
- # printed.
350
- #
351
- # If the +break_into_debug+ argument is +true+ and the +:debug+ option is
352
- # set, the handler will break into the debug console instead of exiting.
353
- #
354
- # If the +exit_on_error+ argument is +false+ the handler will not exit
355
- # after printing the error message.
356
- #
357
- # For example:
358
- # ctx = Context.new({ :debug => true })
359
- # ctx.handle_errors(true) { raise 'break into debug now!' }
360
- # # => this breaks into the debug console
361
- #
362
- def handle_errors(break_into_debug = false, exit_on_error = true)
363
- yield
364
- rescue StandardError => e
365
- if @logger
366
- @logger.log "#{e.message}\n", :error
367
336
  else
368
- puts e.message
369
- end
370
- if @options[:verbose]
371
- p e
372
- puts e.backtrace
373
- end
374
- unless @variables['__DEBUG__']
375
- if break_into_debug and @options[:debug]
376
- debug
377
- elsif exit_on_error
378
- if @variables['__RAISE_ERROR__']
379
- raise
380
- else
381
- exit false
382
- end
383
- end
337
+ ret = exec_action_object(action)
384
338
  end
339
+
340
+ ret.call if ret.respond_to? :call # delayed actions (after log_cmd)
385
341
  end
386
342
 
387
343
  # Executes the given block retrying for at most <tt>${__TIMEOUT__}</tt>
@@ -556,35 +512,28 @@ module Bauxite
556
512
  action.execute
557
513
  end
558
514
 
559
- # Executes the specified +action+ and returns +true+ if the action
560
- # succeeds and +false+ otherwise.
515
+ # Prints the specified +error+ using the Logger configured and
516
+ # handling the verbose option.
561
517
  #
562
- # This method is intended to simplify conditional actions that execute
563
- # different code depending on the outcome of an action execution.
564
- #
565
518
  # For example:
566
- # if ctx.try_exec_action(action, args)
567
- # # => when action succeeds...
568
- # else
569
- # # => when action fails...
519
+ # begin
520
+ # # => some code here
521
+ # rescue StandardError => e
522
+ # @ctx.print_error e
523
+ # # => additional error handling code here
570
524
  # end
571
525
  #
572
- def try_exec_action(action, args)
573
- action = get_action(action, args)
574
-
575
- with_timeout Bauxite::Errors::AssertionError do
576
- with_vars({ '__TIMEOUT__' => 0}) do
577
- begin
578
- ret = exec_action_object(action)
579
- ret.call if ret.respond_to? :call
580
- true
581
- rescue Bauxite::Errors::AssertionError
582
- false
583
- end
584
- end
526
+ def print_error(e)
527
+ if @logger
528
+ @logger.log "#{e.message}\n", :error
529
+ else
530
+ puts e.message
531
+ end
532
+ if @options[:verbose]
533
+ p e
534
+ puts e.backtrace
585
535
  end
586
536
  end
587
-
588
537
 
589
538
  # ======================================================================= #
590
539
  # :section: Metadata
data/lib/bauxite.rb CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  #--
24
24
  module Bauxite
25
- VERSION = "0.5.0"
25
+ VERSION = "0.6.0"
26
26
  end
27
27
  #++
28
28
 
@@ -0,0 +1 @@
1
+ capture
@@ -0,0 +1,7 @@
1
+ <html>
2
+ <body>
3
+ <div class="parent">
4
+ <input id="random_prefix_by_id" class="by_class" by_attr="attr_value">
5
+ </div>
6
+ </body>
7
+ </html>
@@ -0,0 +1,20 @@
1
+ open "file://${__DIR__}/capture/page.html"
2
+ write by_id hello
3
+
4
+ # Seq 0
5
+ capture
6
+
7
+ # Seq 1
8
+ capture
9
+
10
+ # Seq 2
11
+ capture
12
+
13
+ # With name
14
+ capture with_name.png
15
+
16
+ # With test name
17
+ test "capture/my_test.bxt"
18
+
19
+ # With named test name
20
+ test "capture/my_test.bxt" named_test
@@ -0,0 +1 @@
1
+ assertv true false
@@ -1,5 +1,6 @@
1
1
  <html>
2
- <body>
2
+ <body onload="setTimeout(function() { document.getElementById('label').innerHTML = 'done!'; }, 3000);">
3
+ <div id="label">not yet!</div>
3
4
  <input id="hello" value="world" />
4
5
  </body>
5
6
  </html>
data/test/failif.bxt CHANGED
@@ -1,4 +1,5 @@
1
1
  open "file://${__DIR__}/failif/page.html"
2
+ failif assert label "not yet!"
2
3
  failif assertv true false
3
4
  assert hello world
4
5
  failif assert hello universe
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bauxite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Zavolinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-03 00:00:00.000000000 Z
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -120,6 +120,7 @@ files:
120
120
  - lib/bauxite/actions/assert.rb
121
121
  - lib/bauxite/actions/assertv.rb
122
122
  - lib/bauxite/actions/break.rb
123
+ - lib/bauxite/actions/capture.rb
123
124
  - lib/bauxite/actions/click.rb
124
125
  - lib/bauxite/actions/debug.rb
125
126
  - lib/bauxite/actions/doif.rb
@@ -165,6 +166,10 @@ files:
165
166
  - lib/bauxite/selectors/smart.rb
166
167
  - test/alias.bxt
167
168
  - test/assertv.bxt
169
+ - test/capture.bxt.manual
170
+ - test/capture/my_test.bxt
171
+ - test/capture/page.html
172
+ - test/debug.bxt.manual
168
173
  - test/default_selector.bxt.manual
169
174
  - test/default_selector/page.html
170
175
  - test/default_selector_var.bxt