bauxite 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -292,7 +292,7 @@ module Bauxite
292
292
  #
293
293
  def exec_action(text, log = true, file = '<unknown>', line = 0)
294
294
  data = Context::parse_action_default(text, file, line)
295
- _exec_parsed_action(data[:action], data[:args], text, log, file, line)
295
+ exec_parsed_action(data[:action], data[:args], log, text, file, line)
296
296
  end
297
297
 
298
298
  # Executes the specified +file+.
@@ -303,9 +303,42 @@ module Bauxite
303
303
  #
304
304
  def exec_file(file)
305
305
  @parser.parse(file) do |action, args, text, file, line|
306
- _exec_parsed_action(action, args, text, true, file, line)
306
+ exec_parsed_action(action, args, true, text, file, line)
307
307
  end
308
308
  end
309
+
310
+ # Executes the specified action handling errors, logging and debug
311
+ # history.
312
+ #
313
+ # This method if part of the action execution chain and is intended
314
+ # for advanced use (e.g. in complex actions). To execute an Action
315
+ # directly, the #exec_action method is preferred.
316
+ #
317
+ # If +log+ is +true+, log the action execution (default behavior).
318
+ #
319
+ # For example:
320
+ # ctx.exec_action 'open "http://www.ruby-lang.org"'
321
+ # # => navigates to www.ruby-lang.org
322
+ #
323
+ 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)
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
+
309
342
 
310
343
  # Executes the +block+ inside a rescue block applying standard criteria of
311
344
  # error handling.
@@ -474,7 +507,7 @@ module Bauxite
474
507
  # for advanced use (e.g. in complex actions). To execute an Action
475
508
  # directly, the #exec_action method is preferred.
476
509
  #
477
- def get_action(action, args, text, file, line)
510
+ def get_action(action, args, text = nil, file = nil, line = nil)
478
511
  while (alias_action = @aliases[action])
479
512
  action = alias_action[:action]
480
513
  args = alias_action[:args].map do |a|
@@ -495,6 +528,8 @@ module Bauxite
495
528
  end
496
529
 
497
530
  text = ([action] + args.map { |a| '"'+a.gsub('"', '""')+'"' }).join(' ') unless text
531
+ file = @variables['__FILE__'] unless file
532
+ line = @variables['__LINE__'] unless line
498
533
 
499
534
  Action.new(self, action, args, text, file, line)
500
535
  end
@@ -521,6 +556,35 @@ module Bauxite
521
556
  action.execute
522
557
  end
523
558
 
559
+ # Executes the specified +action+ and returns +true+ if the action
560
+ # succeeds and +false+ otherwise.
561
+ #
562
+ # This method is intended to simplify conditional actions that execute
563
+ # different code depending on the outcome of an action execution.
564
+ #
565
+ # For example:
566
+ # if ctx.try_exec_action(action, args)
567
+ # # => when action succeeds...
568
+ # else
569
+ # # => when action fails...
570
+ # end
571
+ #
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
585
+ end
586
+ end
587
+
524
588
 
525
589
  # ======================================================================= #
526
590
  # :section: Metadata
@@ -668,25 +732,6 @@ module Bauxite
668
732
  end
669
733
  end
670
734
 
671
- def _exec_parsed_action(action, args, text, log, file, line)
672
- ret = handle_errors(true) do
673
-
674
- action = get_action(action, args, text, file, line)
675
-
676
- if log
677
- @logger.log_cmd(action) do
678
- Readline::HISTORY << action.text
679
- exec_action_object(action)
680
- end
681
- else
682
- exec_action_object(action)
683
- end
684
- end
685
- handle_errors(true) do
686
- ret.call if ret.respond_to? :call # delayed actions (after log_cmd)
687
- end
688
- end
689
-
690
735
  # ======================================================================= #
691
736
  # Hacks required to overcome the String#split(' ') behavior of folding the
692
737
  # space characters, coupled with CSV not supporting a regex as :col_sep.
data/lib/bauxite.rb CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  #--
24
24
  module Bauxite
25
- VERSION = "0.4.6"
25
+ VERSION = "0.5.0"
26
26
  end
27
27
  #++
28
28
 
data/test/doif.bxt ADDED
@@ -0,0 +1,6 @@
1
+ set first john
2
+ set last doe
3
+ doif john ${first} assertv doe ${last}
4
+ doif john ${first} set is_john true
5
+ assertv true ${is_john}
6
+ doif smith ${last} load smith_specific_text.bxt
data/test/setif.bxt ADDED
@@ -0,0 +1,3 @@
1
+ set name john
2
+ setif is_john true assertv "/John/i" "${name}"
3
+ assertv true ${is_john}
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.4.6
4
+ version: 0.5.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-01-31 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -122,6 +122,7 @@ files:
122
122
  - lib/bauxite/actions/break.rb
123
123
  - lib/bauxite/actions/click.rb
124
124
  - lib/bauxite/actions/debug.rb
125
+ - lib/bauxite/actions/doif.rb
125
126
  - lib/bauxite/actions/echo.rb
126
127
  - lib/bauxite/actions/exec.rb
127
128
  - lib/bauxite/actions/failif.rb
@@ -135,6 +136,7 @@ files:
135
136
  - lib/bauxite/actions/ruby.rb
136
137
  - lib/bauxite/actions/select.rb
137
138
  - lib/bauxite/actions/set.rb
139
+ - lib/bauxite/actions/setif.rb
138
140
  - lib/bauxite/actions/source.rb
139
141
  - lib/bauxite/actions/store.rb
140
142
  - lib/bauxite/actions/submit.rb
@@ -168,6 +170,7 @@ files:
168
170
  - test/default_selector_var.bxt
169
171
  - test/delay.bxt
170
172
  - test/delay/page.html
173
+ - test/doif.bxt
171
174
  - test/exec.bxt
172
175
  - test/extension.bxt.manual
173
176
  - test/extension/custom.rb
@@ -193,6 +196,7 @@ files:
193
196
  - test/select/page.html
194
197
  - test/selectors.bxt
195
198
  - test/selectors/page.html
199
+ - test/setif.bxt
196
200
  - test/smart_selector.bxt
197
201
  - test/smart_selector/page.html
198
202
  - test/stdin.bxt