automation_object 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/automation_object/driver/appium_adapter/driver.rb +4 -4
  3. data/lib/automation_object/driver/common_selenium/driver.rb +0 -10
  4. data/lib/automation_object/driver/selenium_adapter/driver.rb +4 -5
  5. data/lib/automation_object/dsl/element.rb +1 -4
  6. data/lib/automation_object/dsl/element_array.rb +1 -4
  7. data/lib/automation_object/dsl/element_hash.rb +1 -4
  8. data/lib/automation_object/dsl/modal.rb +2 -2
  9. data/lib/automation_object/dsl/screen.rb +6 -1
  10. data/lib/automation_object/state/composite/_base.rb +8 -2
  11. data/lib/automation_object/state/composite/_common_element.rb +8 -1
  12. data/lib/automation_object/state/composite/element.rb +3 -1
  13. data/lib/automation_object/state/composite/element_array.rb +3 -3
  14. data/lib/automation_object/state/composite/element_hash.rb +5 -3
  15. data/lib/automation_object/state/composite/helpers/window.rb +22 -4
  16. data/lib/automation_object/state/composite/helpers/window_manager.rb +5 -6
  17. data/lib/automation_object/state/composite/hook.rb +1 -2
  18. data/lib/automation_object/state/composite/hook_action.rb +2 -2
  19. data/lib/automation_object/state/composite/hook_actions/action_loop.rb +18 -9
  20. data/lib/automation_object/state/composite/hook_actions/change_screen.rb +3 -8
  21. data/lib/automation_object/state/composite/hook_actions/change_to_previous_screen.rb +3 -3
  22. data/lib/automation_object/state/composite/hook_actions/new_screen.rb +0 -4
  23. data/lib/automation_object/state/composite/hook_actions/possible_screen_changes.rb +2 -2
  24. data/lib/automation_object/state/composite/hook_actions/show_modal.rb +2 -7
  25. data/lib/automation_object/state/composite/hook_actions/sleep.rb +1 -6
  26. data/lib/automation_object/state/composite/hook_actions/wait_for_elements.rb +1 -3
  27. data/lib/automation_object/state/composite/screen.rb +6 -0
  28. data/lib/automation_object/state/session.rb +14 -0
  29. data/lib/automation_object/step_definitions/element.rb +2 -1
  30. data/lib/automation_object/step_definitions/element_array.rb +7 -6
  31. data/lib/automation_object/step_definitions/element_hash.rb +8 -7
  32. data/lib/automation_object/step_definitions/screen.rb +19 -4
  33. data/lib/automation_object/step_definitions/support/cache.rb +1 -1
  34. data/lib/automation_object/step_definitions/support/minitest.rb +10 -0
  35. data/lib/automation_object/step_definitions/support/parse.rb +7 -7
  36. data/lib/automation_object/version.rb +1 -1
  37. data/lib/automation_object.rb +1 -0
  38. metadata +17 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 752355905e1e3e9177ad9e481b27abd8d0979076
4
- data.tar.gz: e58e752b120609eb53030fc41c3ab5ccaee717b9
3
+ metadata.gz: 9c6397d7cf9b93c229e3184d39b5c97a674fe1b1
4
+ data.tar.gz: dd8e110716616306e04f0c6b31130473b98ababc
5
5
  SHA512:
6
- metadata.gz: a59cd4c3e1b7843e825752e6e8921c45620733a2092305ec6746e04720c2f6bf8bcbf2e8a694769a6ba2e19fcbb341a88fa662eb62068dab4cbd0998fa25e6e1
7
- data.tar.gz: 8adbce64b6b3ac96cde758814d2a643d5c04b2af2d302edd0aff46ebe9a780891721bc320b5865c63a59547fbb846395eccb77a81dfb97b3c7359379c93b3c5c
6
+ metadata.gz: 17a499eb9a9d18f29a0a44ba088a3a15d53f6fae349fb3a6c53615ef5f3e0eb0ee7feecd2bd8bb4c7874130f9a354f133ffe34f06dd8a6fbf0a4cb000d7f6bf5
7
+ data.tar.gz: deb26da5fc8ee5e6f473f3333303c3e3e8880f78e101aded3cee357559963bda93ee8ab24cdcaeba6462fc6d6931cda95fef199d1bf22081d43f95af9d625706
@@ -100,10 +100,10 @@ module AutomationObject
100
100
  # Window Handles Override
101
101
  # @return [Array<String>] array of window handles
102
102
  def window_handles
103
- if @subject.device_is_android? && is_browser?
103
+ if @subject.device_is_android? && browser?
104
104
  window_handles = @subject.window_handles
105
105
  else
106
- return @subject.available_contexts unless is_browser?
106
+ return @subject.available_contexts unless browser?
107
107
 
108
108
  window_handles = []
109
109
  @subject.available_contexts.each do |context|
@@ -117,7 +117,7 @@ module AutomationObject
117
117
  # Get window handle override
118
118
  # @return [String] current window handle
119
119
  def window_handle
120
- return @subject.current_context unless is_browser?
120
+ return @subject.current_context unless browser?
121
121
 
122
122
  return @subject.window_handle if @subject.device_is_android?
123
123
 
@@ -137,7 +137,7 @@ module AutomationObject
137
137
 
138
138
  # @return [Boolean] document is complete
139
139
  def document_complete?
140
- return true unless is_browser? # Skip for non-browser Appium sessions
140
+ return true unless browser? # Skip for non-browser Appium sessions
141
141
  @subject.execute_script('return document.readyState;') == 'complete'
142
142
  end
143
143
 
@@ -6,16 +6,6 @@ module AutomationObject
6
6
  module CommonSelenium
7
7
  # Common Selenium/AppiumMethods
8
8
  module Driver
9
- # Suspend timeout for block running
10
- def suspend_timeout
11
- original_timeout = @subject.manage.timeouts.implicit_wait
12
- @subject.manage.timeouts.implicit_wait = 0
13
-
14
- yield
15
-
16
- @subject.manage.timeouts.implicit_wait = original_timeout
17
- end
18
-
19
9
  # @return [Point] x,y scroll position
20
10
  def scroll_position
21
11
  position = Point.new
@@ -48,11 +48,10 @@ module AutomationObject
48
48
  exists = false
49
49
 
50
50
  begin
51
- suspend_timeout do
52
- element_objects = @subject.find_elements(selector_type, selector_path)
53
- exists = true unless element_objects.empty?
54
- end
55
- rescue StandardError
51
+ element_objects = @subject.find_elements(selector_type, selector_path)
52
+ exists = true unless element_objects.empty?
53
+ rescue StandardError => e
54
+ puts e
56
55
  return false
57
56
  end
58
57
 
@@ -22,10 +22,7 @@ module AutomationObject
22
22
  def method_missing(method, *args, &block)
23
23
  return super if Element.methods.include?(method)
24
24
 
25
- if @subject.is_a?(AutomationObject::Dsl::Element)
26
- # puts "@state.load(:element, #{@name})"
27
- @subject = @state.load(:element, @name)
28
- end
25
+ @subject = @state.load(:element, @name)
29
26
 
30
27
  super
31
28
  end
@@ -22,10 +22,7 @@ module AutomationObject
22
22
  def method_missing(method, *args, &block)
23
23
  return super if ElementArray.methods.include?(method)
24
24
 
25
- if @subject.is_a?(AutomationObject::Dsl::ElementArray)
26
- # puts "@state.load(:element_array, #{@name})"
27
- @subject = @state.load(:element_array, @name)
28
- end
25
+ @subject = @state.load(:element_array, @name)
29
26
 
30
27
  super
31
28
  end
@@ -22,10 +22,7 @@ module AutomationObject
22
22
  def method_missing(method, *args, &block)
23
23
  return super if ElementHash.methods.include?(method)
24
24
 
25
- if @subject.is_a?(AutomationObject::Dsl::ElementHash)
26
- # puts "@state.load(:element_hash, #{@name})"
27
- @subject = @state.load(:element_hash, @name)
28
- end
25
+ @subject = @state.load(:element_hash, @name)
29
26
 
30
27
  super
31
28
  end
@@ -30,8 +30,8 @@ module AutomationObject
30
30
  def method_missing(method, *args, &block)
31
31
  return super if Modal.methods.include?(method)
32
32
 
33
- # Attempt to load screen if composite object contains that child
34
- if @subject.methods.include?(method)
33
+ # Attempt to load modal if composite object contains that child
34
+ if @subject.to_h.include?(method)
35
35
  # puts "@state.load(:modal, #{@name})"
36
36
  @state.load(:modal, @name)
37
37
  end
@@ -33,13 +33,18 @@ module AutomationObject
33
33
  return super if Screen.methods.include?(method)
34
34
 
35
35
  # Attempt to load screen if composite object contains that child
36
- if @subject.methods.include?(method)
36
+ if @subject.to_h.include?(method)
37
37
  # puts "@state.load(:screen, #{@name})"
38
38
  @state.load(:screen, @name)
39
39
  end
40
40
 
41
41
  super
42
42
  end
43
+
44
+ # @return [Boolean]
45
+ def active?
46
+ @state.active?(:screen, @name)
47
+ end
43
48
  end
44
49
  end
45
50
  end
@@ -17,7 +17,7 @@ module AutomationObject
17
17
 
18
18
  # @param session [AutomationObject::State::Session] session
19
19
  # @param driver [AutomationObject::Driver] driver
20
- # @param blue_prints [AutomationObject::BluePrint::Composite] blue print composite
20
+ # @param blue_prints [AutomationObject::BluePrint::Composite::Base] blue print composite
21
21
  # @param name [Symbol] name of composite element
22
22
  # @param parent [Object, nil] parent composite object
23
23
  # @param location [String] string location for error/debugging purposes
@@ -62,13 +62,19 @@ module AutomationObject
62
62
 
63
63
  # Recursive function to reach parent screen
64
64
  # Can return nil if above a screen!
65
- # @return [AutomationObject::State::BluePrintAdapter::Screen,nil]
65
+ # @return [AutomationObject::State::Composite::Screen,nil]
66
66
  def screen
67
67
  return nil if is_a?(Top)
68
68
 
69
69
  # Should recursively call top until parent is nil
70
70
  is_a?(Screen) ? self : parent.screen
71
71
  end
72
+
73
+ # Recursive function to reach top
74
+ # @return [AutomationObject::State::Composite::Top]
75
+ def top
76
+ is_a?(Top) ? self : parent.top
77
+ end
72
78
  end
73
79
  end
74
80
  end
@@ -6,6 +6,12 @@ module AutomationObject
6
6
  module Composite
7
7
  # Helper module for Element composite classes
8
8
  module CommonElement
9
+ attr_accessor :cache
10
+
11
+ def reset
12
+ self.cache = nil
13
+ end
14
+
9
15
  def method_hook?(name)
10
16
  blue_prints.method_hooks.key?(name)
11
17
  end
@@ -16,8 +22,9 @@ module AutomationObject
16
22
 
17
23
  @method_hooks = {}
18
24
  blue_prints.method_hooks.each do |key, blue_prints|
19
- @method_hooks[key] = Hook.new(blue_prints,
25
+ @method_hooks[key] = Hook.new(session,
20
26
  driver,
27
+ blue_prints,
21
28
  key,
22
29
  self,
23
30
  location + "[#{key}]")
@@ -13,8 +13,10 @@ module AutomationObject
13
13
 
14
14
  # @return [AutomationObject::State::Composite::ElementProxy] Selenium proxy
15
15
  def load
16
+ return cache if cache
17
+
16
18
  element = driver.find_element(*blue_prints.selector_params)
17
- ElementProxy.new(self, element)
19
+ self.cache = ElementProxy.new(self, element)
18
20
  end
19
21
  end
20
22
  end
@@ -13,13 +13,13 @@ module AutomationObject
13
13
 
14
14
  # @return [Array<AutomationObject::State::Composite::ElementProxy>] Selenium proxy
15
15
  def load
16
+ return cache if cache
17
+
16
18
  elements = driver.find_elements(*blue_prints.selector_params)
17
19
 
18
- wrapped_elements = elements.map do |element|
20
+ self.cache = elements.map do |element|
19
21
  ElementProxy.new(self, element)
20
22
  end
21
-
22
- wrapped_elements
23
23
  end
24
24
  end
25
25
  end
@@ -13,8 +13,10 @@ module AutomationObject
13
13
 
14
14
  # @return [Hash<String, AutomationObject::State::Composite::ElementProxy>] Selenium proxy
15
15
  def load
16
+ return cache if cache
17
+
16
18
  elements = driver.find_elements(*blue_prints.selector_params)
17
- elements_hash = {}
19
+ self.cache = {}
18
20
 
19
21
  elements.each do |element|
20
22
  # Want to wrap element, before sending for method!
@@ -22,10 +24,10 @@ module AutomationObject
22
24
  wrapped_element = ElementProxy.new(self, element)
23
25
  hash_key = wrapped_element.send(blue_prints.define_elements_by) # Send to wrapped state proxy
24
26
 
25
- elements_hash[hash_key] = wrapped_element
27
+ cache[hash_key] = wrapped_element
26
28
  end
27
29
 
28
- elements_hash
30
+ cache
29
31
  end
30
32
  end
31
33
  end
@@ -6,10 +6,12 @@ module AutomationObject
6
6
  module Composite
7
7
  # Window class
8
8
  class Window
9
- # @param [AutomationObject::Driver::Driver] driver
10
- # @param [String] handle
11
- # @param [Symbol] screen
12
- def initialize(driver, handle, screen)
9
+ # @param window_manager [AutomationObject::State::Composite::WindowManager]
10
+ # @param driver [AutomationObject::Driver::Driver]
11
+ # @param handle [String]
12
+ # @param screen [Symbol]
13
+ def initialize(window_manager, driver, handle, screen)
14
+ @window_manager = window_manager
13
15
  @driver = driver
14
16
  @handle = handle
15
17
 
@@ -18,6 +20,22 @@ module AutomationObject
18
20
  @history = [screen]
19
21
  end
20
22
 
23
+ # @return [Symbol,nil] previous screen name
24
+ def previous
25
+ return nil if @position < 1
26
+ @history[@position - 1]
27
+ end
28
+
29
+ # @param name [Symbol] screen name
30
+ # @return [void]
31
+ def update(name)
32
+ # Reset current screen
33
+ @window_manager.screens[self.name].reset
34
+
35
+ @position += 1
36
+ @history << name
37
+ end
38
+
21
39
  # @return [Symbol] current screen
22
40
  def name
23
41
  @history[@position]
@@ -7,8 +7,6 @@ module AutomationObject
7
7
  module Composite
8
8
  # Collection to manage Window objects
9
9
  module WindowManager
10
- attr_accessor :window
11
-
12
10
  # @param name [Symbol] name of window to use
13
11
  # @return [void]
14
12
  def use(name)
@@ -18,11 +16,12 @@ module AutomationObject
18
16
  next if window.name != name
19
17
  return if window == self.window
20
18
 
21
- self.window = window
22
- self.window.use
19
+ @window = window
20
+ @window.use
23
21
  end
24
22
  end
25
23
 
24
+ # @return [AutomationObject::State::Composite::Window]
26
25
  def window
27
26
  raise AutomationObject::State::Error::NoActiveWindows unless @window
28
27
  @window
@@ -51,8 +50,8 @@ module AutomationObject
51
50
  # Should only have one extra window
52
51
  raise UnexpectedExtraWindowError if diff_handles.length > 1
53
52
 
54
- self.window = Window.new(driver, diff_handles.first, name)
55
- windows << window
53
+ @window = Window.new(self, driver, diff_handles.first, name)
54
+ windows << @window
56
55
  end
57
56
  end
58
57
  end
@@ -16,8 +16,7 @@ module AutomationObject
16
16
  return nil if blue_prints.live?.empty?
17
17
 
18
18
  blue_prints.live?.each do |element_requirement_blueprints|
19
- hook_element_requirement = ElementRequirement.new(element_requirement_blueprints,
20
- driver, self, 1)
19
+ hook_element_requirement = ElementRequirement.new(self, driver, element_requirement_blueprints, 1)
21
20
  return false unless hook_element_requirement.run
22
21
  end
23
22
 
@@ -23,8 +23,8 @@ module AutomationObject
23
23
  hook_action_class = AutomationObject::State::Composite.const_get(hook_name.to_s.pascalize)
24
24
  blue_prints = self.blue_prints.send(hook_name)
25
25
 
26
- hook_action = hook_action_class.new(blue_prints: blue_prints, composite: self)
27
- return false if hook_action.run == false
26
+ hook_action = hook_action_class.new(self, driver, blue_prints)
27
+ return false if hook_action.run == false # Use long form, can return nil!
28
28
  end
29
29
 
30
30
  true
@@ -4,31 +4,40 @@ module AutomationObject
4
4
  module Composite
5
5
  # Composite action loop base class
6
6
  class ActionLoop
7
- attr_accessor :composite, :blue_prints, :loops
7
+ # @return [AutomationObject::State::Composite::Base]
8
+ attr_accessor :composite
9
+ # @return [AutomationObject::Driver::Driver]
10
+ attr_accessor :driver
11
+ # @return [AutomationObject::BluePrint::Composite::Base]
12
+ attr_accessor :blue_prints
13
+ # @return [Integer]
14
+ attr_accessor :loops
8
15
 
9
- def initialize(blue_prints, driver, composite, loops = 30)
10
- self.blue_prints = blue_prints
11
- self.driver = driver
16
+ # @param composite [AutomationObject::State::Composite::Base]
17
+ # @param driver [AutomationObject::Driver::Driver]
18
+ # @param blue_prints [AutomationObject::BluePrint::Composite::Base]
19
+ # @param loops [Integer]
20
+ def initialize(composite, driver, blue_prints, loops = 30)
12
21
  self.composite = composite
22
+ self.driver = driver
23
+ self.blue_prints = blue_prints
13
24
  self.loops = loops
14
25
  end
15
26
 
16
- def driver
17
- composite.driver
18
- end
19
-
20
27
  # @return [Boolean] run success or not
21
28
  def run
22
29
  loops.times do
30
+ # Sub classes implement single run
23
31
  return true if single_run
24
32
  end
25
33
 
26
34
  false
27
35
  end
28
36
 
37
+ # Abstract method, override
29
38
  # @return [Boolean] success or not
30
39
  def single_run
31
- raise 'Abstract Issue'
40
+ raise NotImplementedError
32
41
  end
33
42
  end
34
43
  end
@@ -6,17 +6,12 @@ module AutomationObject
6
6
  module Composite
7
7
  # Change screen hook loop
8
8
  class ChangeScreen < ActionLoop
9
- def initialize(args = {})
10
- super
11
- @new_screen_name = args.fetch :blue_prints
12
- end
13
-
14
9
  def single_run
15
10
  return false unless driver.document_complete?
16
11
 
17
- new_screen = composite.top.screens[@new_screen_name]
18
- if new_screen.load.live?
19
- composite.top.set_screen(@new_screen_name)
12
+ new_screen = composite.top.screens[blue_prints]
13
+ if new_screen.load.live? != false # Need strict
14
+ composite.top.window.update(blue_prints)
20
15
  return true
21
16
  else
22
17
  return false
@@ -9,9 +9,9 @@ module AutomationObject
9
9
  def single_run
10
10
  return false unless driver.document_complete?
11
11
 
12
- new_screen = composite.top.current_window.previous_screen_name
13
- if new_screen.load.live?
14
- composite.top.set_screen(new_screen)
12
+ new_screen = composite.top.window.previous
13
+ if new_screen.load.live? != false
14
+ composite.top.window.update(new_screen)
15
15
  return true
16
16
  else
17
17
  return false
@@ -7,10 +7,6 @@ module AutomationObject
7
7
  module Composite
8
8
  # New screen hook loop
9
9
  class NewScreen < ActionLoop
10
- def initialize(args = {})
11
- super
12
- end
13
-
14
10
  def single_run
15
11
  new_screen_name = blue_prints
16
12
  new_screen = composite.top.screens[new_screen_name]
@@ -8,8 +8,8 @@ module AutomationObject
8
8
  class PossibleScreenChanges < ActionLoop
9
9
  def single_run
10
10
  blue_prints.each do |possible_screen_name|
11
- if possible_screen_name.load.live?
12
- composite.top.set_screen(possible_screen_name)
11
+ if possible_screen_name.load.live? != false
12
+ composite.top.window.update(possible_screen_name)
13
13
  return true
14
14
  end
15
15
  end
@@ -6,16 +6,11 @@ module AutomationObject
6
6
  module Composite
7
7
  # Show modal hook loop
8
8
  class ShowModal < ActionLoop
9
- def initialize(args = {})
10
- super
11
- @new_modal_name = args.fetch :blue_prints
12
- end
13
-
14
9
  def single_run
15
- new_modal = composite.screen.modals[@new_modal_name]
10
+ new_modal = composite.screen.modals[blue_prints]
16
11
 
17
12
  if new_modal.load.live? != false
18
- composite.screen.current_modal = @new_modal_name
13
+ composite.screen.current_modal = blue_prints
19
14
  composite.screen.modal = new_modal
20
15
  return true
21
16
  else
@@ -6,13 +6,8 @@ module AutomationObject
6
6
  module Composite
7
7
  # Sleep hook loop
8
8
  class Sleep < ActionLoop
9
- def initialize(args = {})
10
- super
11
- @time = args.fetch :blue_prints
12
- end
13
-
14
9
  def single_run
15
- sleep(@time)
10
+ sleep(blue_prints)
16
11
  end
17
12
  end
18
13
  end
@@ -8,9 +8,7 @@ module AutomationObject
8
8
  class WaitForElements < ActionLoop
9
9
  def single_run
10
10
  blue_prints.each do |hook_element_requirement|
11
- hook_element_requirement = ElementRequirement.new(blue_prints: hook_element_requirement,
12
- composite: self,
13
- loops: 1)
11
+ hook_element_requirement = ElementRequirement.new(driver, hook_element_requirement, 1)
14
12
  return false unless hook_element_requirement.run
15
13
  end
16
14
 
@@ -43,6 +43,12 @@ module AutomationObject
43
43
  end
44
44
  end
45
45
 
46
+ def reset
47
+ elements.values.map(&:reset)
48
+ element_arrays.values.map(&:reset)
49
+ element_hashes.values.map(&:reset)
50
+ end
51
+
46
52
  # Whether or not modal is active
47
53
  # @return [Boolean]
48
54
  attr_accessor :active
@@ -23,6 +23,8 @@ module AutomationObject
23
23
  self.composite = Composite::Top.new(self, driver, blue_prints)
24
24
  end
25
25
 
26
+ # @param type [Symbol]
27
+ # @param name [Symbol]
26
28
  def load(type, name)
27
29
  case type
28
30
  when :screen
@@ -35,6 +37,18 @@ module AutomationObject
35
37
  raise AutomationObject::State::UndefinedLoadTypeError
36
38
  end
37
39
  end
40
+
41
+ # @param type [Symbol]
42
+ # @param name [Symbol]
43
+ # @return [Boolean]
44
+ def active?(type, name)
45
+ case type
46
+ when :screen
47
+ composite.live_screens.include?(name)
48
+ else
49
+ raise AutomationObject::State::UndefinedLoadTypeError
50
+ end
51
+ end
38
52
  end
39
53
  end
40
54
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative 'support/parse'
3
+ require_relative 'support/minitest'
3
4
 
4
5
  # Description: Provides step definitions related to elements
5
6
 
@@ -18,7 +19,7 @@ end
18
19
  # - I type "blah" into the "home_screen" "text_field" element
19
20
  # - I type "test" in the "home_screen" "text_field" element
20
21
  # - I type "blah" in "home_screen" "text_field" element
21
- When(/^I type "([\w\s]+|%\{[\w\d]+\})" in(?:to)? (?:the )?"(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element$/) do |*args|
22
+ When(/^I type "([^"]+|%\{[\w\d]+\})" in(?:to)? (?:the )?"(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element$/) do |*args|
22
23
  text, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
23
24
  AutomationObject::Framework.get.send(screen).send(element).send_keys(text)
24
25
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative 'support/parse'
3
3
  require_relative 'support/element_array'
4
+ require_relative 'support/minitest'
4
5
 
5
6
  # Description: Provides step definitions related to element arrays
6
7
 
@@ -23,7 +24,7 @@ end
23
24
  # For: Typing into element array field
24
25
  # Examples:
25
26
  # - I type "blah" into the first "home_screen" "text_field" element array
26
- When(%r(^I type "([\w\s]+|%\{[\w\d]+\})" in(?:to| to)? (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$/)) do |*args|
27
+ When(%r(^I type "([\w\s]+|%\{[\w\d]+\})" in(?:to| to)? (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$)) do |*args|
27
28
  text, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
28
29
 
29
30
  AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
@@ -36,7 +37,7 @@ end
36
37
  # For: Scrolling element array item(s) into focus
37
38
  # Examples:
38
39
  # - I scroll to the first "home_screen" "logo_button" element array
39
- When(%r(^I (?:scroll |focus )(?:to |through )(?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$/)) do |*args|
40
+ When(%r(^I (?:scroll |focus )(?:to |through )(?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$)) do |*args|
40
41
  key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
41
42
 
42
43
  AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
@@ -47,7 +48,7 @@ end
47
48
  # For: Saving value from element array for use later
48
49
  # Examples:
49
50
  # - I save "text" as "unique_value" from the first "home_screen" "logo_button" element array
50
- When(%r(^I save "(\w+|%\{[\w\d]+\})" as "([\w\d]+)" from (?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$/)) do |*args|
51
+ When(%r(^I save "(\w+|%\{[\w\d]+\})" as "([\w\d]+)" from (?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array$)) do |*args|
51
52
  method, value_key, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
52
53
 
53
54
  AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
@@ -61,7 +62,7 @@ end
61
62
  # For: Testing the element arrays size
62
63
  # Examples:
63
64
  # - the "home_screen" "title" element array should be greater than 0
64
- Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array should(n't|not)? (?:be )?(larger th[ae]n|greater th[ae]n|less th[ae]n|smaller th[ae]n|equals?) (?:to )?(\d+)$/)) do |*args|
65
+ Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array should(n't|not)? (?:be )?(larger th[ae]n|greater th[ae]n|less th[ae]n|smaller th[ae]n|equals?) (?:to )?(\d+)$)) do |*args|
65
66
  screen, element, negative, comparison, expected_value = AutomationObject::StepDefinitions::Parse.new(args).get
66
67
 
67
68
  element_array = AutomationObject::Framework.get.send(screen).send(element)
@@ -95,7 +96,7 @@ end
95
96
  # - the random "home_screen" "title" element array "text" should not equal "Home"
96
97
  # - the 0..9 "home_screen" "title" element array "text" should equal "Home"
97
98
  # - the all "home_screen" "title" element array "text" should not equal "Home"
98
- Then(%r(^(?:the )?(%\{\w+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array "(\w+|%\{[\w\d]+\})" should?(n't| not)? equal "(\w+|%\{[\w\d]+\})"$/)) do |*args|
99
+ Then(%r(^(?:the )?(%\{\w+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element array "(\w+|%\{[\w\d]+\})" should?(n't| not)? equal "(\w+|%\{[\w\d]+\})"$)) do |*args|
99
100
  key, low_range, high_range, screen, element, method, negative, expected_value = AutomationObject::StepDefinitions::Parse.new(args).get
100
101
 
101
102
  AutomationObject::StepDefinitions::ElementArray.iterate_and_do(
@@ -116,7 +117,7 @@ end
116
117
  # - the "home_screen" "title" element array "text" should be unique
117
118
  # - the "home_screen" "title" element array "text" should not be unique
118
119
  # - the "home_screen" "title" element array "text" shouldn't be unique
119
- Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "([\w\d]+|%\{[\w\d]+\})" element array "([\w\d]+|%\{[\w\d]+\})" should(n't| not)? be unique$/)) do |*args|
120
+ Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "([\w\d]+|%\{[\w\d]+\})" element array "([\w\d]+|%\{[\w\d]+\})" should(n't| not)? be unique$)) do |*args|
120
121
  screen, element, method, negative = AutomationObject::StepDefinitions::Parse.new(args).get
121
122
 
122
123
  element_array = AutomationObject::Framework.get.send(screen).send(element)
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative 'support/parse'
3
3
  require_relative 'support/element_hash'
4
+ require_relative 'support/minitest'
4
5
 
5
6
  # Description: Provides step definitions related to element hashes
6
7
 
7
8
  # For: Calling an element hash method
8
9
  # Examples:
9
10
  # - I click on the first "home_screen" "about_button" element hash
10
- When(%r(^I (\w+|%\{[\w\d]+\})?(?: on| over)?(?: the| a)? (%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash/)) do |*args|
11
+ When(%r(^I (\w+|%\{[\w\d]+\})?(?: on| over)?(?: the| a)? (%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash$)) do |*args|
11
12
  method, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
12
13
 
13
14
  AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
@@ -20,7 +21,7 @@ end
20
21
  # For: Typing into element hash field
21
22
  # Examples:
22
23
  # - I type "blah" into the first "home_screen" "text_field" element hash
23
- When(%r(^I type "([\w\s]+|%\{[\w\d]+\})" in(?:to| to)? (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash/)) do |*args|
24
+ When(%r(^I type "([\w\s]+|%\{[\w\d]+\})" in(?:to| to)? (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash$)) do |*args|
24
25
  text, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
25
26
 
26
27
  AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
@@ -33,7 +34,7 @@ end
33
34
  # For: Scrolling element hash item(s) into focus
34
35
  # Examples:
35
36
  # - I scroll to the first "home_screen" "logo_button" element hash
36
- When(%r(^I (?:scroll |focus )(?:to |through )(?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash/)) do |*args|
37
+ When(%r(^I (?:scroll |focus )(?:to |through )(?:the )?(%\{[\w\d]+\}|all|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash$)) do |*args|
37
38
  key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
38
39
 
39
40
  AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
@@ -44,7 +45,7 @@ end
44
45
  # For: Saving value from element hash for use later
45
46
  # Examples:
46
47
  # - I save "text" as "unique_value" from the first "home_screen" "logo_button" element hash
47
- When(%r(^I save "(\w+|%\{[\w\d]+\})" as "([\w\d]+)" from (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash/)) do |*args|
48
+ When(%r(^I save "(\w+|%\{[\w\d]+\})" as "([\w\d]+)" from (?:the )?(%\{[\w\d]+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash$)) do |*args|
48
49
  method, value_key, key, low_range, high_range, screen, element = AutomationObject::StepDefinitions::Parse.new(args).get
49
50
 
50
51
  AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
@@ -58,7 +59,7 @@ end
58
59
  # For: Testing the element hashes size
59
60
  # Examples:
60
61
  # - the "home_screen" "title" element hash should be greater than 0
61
- Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash should(n't|not)? (?:be )?(larger th[ae]n|greater th[ae]n|less th[ae]n|smaller th[ae]n|equals?) (?:to )?(\d+)$/)) do |*args|
62
+ Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash should(n't|not)? (?:be )?(larger th[ae]n|greater th[ae]n|less th[ae]n|smaller th[ae]n|equals?) (?:to )?(\d+)$)) do |*args|
62
63
  screen, element, negative, comparison, expected_value = AutomationObject::StepDefinitions::Parse.new(args).get
63
64
 
64
65
  element_hash = AutomationObject::Framework.get.send(screen).send(element)
@@ -88,7 +89,7 @@ end
88
89
  # For: Testing if the element hash value equals a given value
89
90
  # Examples:
90
91
  # - the first "home_screen" "title" element hash "text" should equal "Home"
91
- Then(%r(^(?:the )?(%\{\w+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash "(\w+|%\{[\w\d]+\})" should ?(n't |not )?equal "(\w+|%\{[\w\d]+\})"$/)) do |*args|
92
+ Then(%r(^(?:the )?(%\{\w+\}|random|last|first|(\d+)\.\.(\d+)) "(\w+|%\{[\w\d]+\})" "(\w+|%\{[\w\d]+\})" element hash "(\w+|%\{[\w\d]+\})" should ?(n't |not )?equal "(\w+|%\{[\w\d]+\})"$)) do |*args|
92
93
  key, low_range, high_range, screen, element, method, negative, expected_value = AutomationObject::StepDefinitions::Parse.new(args).get
93
94
 
94
95
  AutomationObject::StepDefinitions::ElementHash.iterate_and_do(
@@ -107,7 +108,7 @@ end
107
108
  # For: Testing if the element hashes uniqueness
108
109
  # Examples:
109
110
  # - the "home_screen" "title" element hash "text" should be unique
110
- Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "([\w\d]+|%\{[\w\d]+\})" element hash "([\w\d]+|%\{[\w\d]+\})" should(n't|not)? be unique$/)) do |*args|
111
+ Then(%r(^(?:the )?"([\w\d]+|%\{[\w\d]+\})" "([\w\d]+|%\{[\w\d]+\})" element hash "([\w\d]+|%\{[\w\d]+\})" should(n't|not)? be unique$)) do |*args|
111
112
  screen, element, method, negative = AutomationObject::StepDefinitions::Parse.new(args).get
112
113
 
113
114
  element_hash = AutomationObject::Framework.get.send(screen).send(element)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative 'support/parse'
3
+ require_relative 'support/minitest'
3
4
 
4
5
  # Description: Provides step definitions related to screens
5
6
 
@@ -8,7 +9,7 @@ require_relative 'support/parse'
8
9
  # - I close the "contact" screen
9
10
  # - I close the screen
10
11
  # - I destroy the screen
11
- Then(%r(^I (?:close|destroy) the ("([\w\s]+|%\{[\w\d]+\})")? ?screen$/)) do |*args|
12
+ Then(%r(^I (?:close|destroy) the ("([\w\s]+|%\{[\w\d]+\})")? ?screen$)) do |*args|
12
13
  _unparsed_name, name = AutomationObject::StepDefinitions::Parse.new(args).get
13
14
 
14
15
  if name
@@ -22,7 +23,7 @@ end
22
23
  # Examples:
23
24
  # - I navigate back on the screen
24
25
  # - I navigate back on the "contact" screen
25
- Then(%r(^I (?:navigate|go) back (?:on )?(?:the )?("([\w\s]+|%\{[\w\d]+\})")? ?screen$/)) do
26
+ Then(%r(^I (?:navigate|go) back (?:on )?(?:the )?("([\w\s]+|%\{[\w\d]+\})")? ?screen$)) do
26
27
  _unparsed_name, name = AutomationObject::StepDefinitions::Parse.new(args).get
27
28
 
28
29
  if name
@@ -36,7 +37,7 @@ end
36
37
  # Examples:
37
38
  # - I switch to the "home" screen
38
39
  # - I focus the "contact" screen
39
- Then(%r(^I (?:switch|focus) (?:to )?(?:the )?"([\w\s]+|%\{[\w\d]+\})" screen$/)) do |*args|
40
+ Then(%r(^I (?:switch|focus) (?:to )?(?:the )?"([\w\s]+|%\{[\w\d]+\})" screen$)) do |*args|
40
41
  screen = AutomationObject::StepDefinitions::Parse.new(args).get
41
42
  AutomationObject::Framework.get.focus(screen)
42
43
  end
@@ -47,7 +48,7 @@ end
47
48
  # - I set the "home" screen size to 1000x2000
48
49
  # - I set the screen width to 1000
49
50
  # - I set the screen height to 2000
50
- Then(%r(^I set the ("([\w\s]+|%\{[\w\d]+\})")? ?screen (size|width|height) to (\d+|(\d+)x(\d+))$/)) do |*args|
51
+ Then(%r(^I set the ("([\w\s]+|%\{[\w\d]+\})")? ?screen (size|width|height) to (\d+|(\d+)x(\d+))$)) do |*args|
51
52
  _unparsed_screen, screen, dimension, size, width, height = AutomationObject::StepDefinitions::Parse.new(args).get
52
53
 
53
54
  screen = if screen
@@ -60,3 +61,17 @@ Then(%r(^I set the ("([\w\s]+|%\{[\w\d]+\})")? ?screen (size|width|height) to (\
60
61
  screen.width(size) if dimension == 'width' && size
61
62
  screen.height(size) if dimension == 'height' && size
62
63
  end
64
+
65
+ # For: Test if screen is currently active
66
+ # Examples:
67
+ # - the "home" screen should be active
68
+ # - the "login" screen shouldn't be active
69
+ Then(%r(^the "([\w\s]+|%\{[\w\d]+\})" screen should ?(n't |not )?be active$)) do |*args|
70
+ screen, negative = AutomationObject::StepDefinitions::Parse.new(args).get
71
+
72
+ if negative
73
+ assert_equal false, AutomationObject::Framework.get.send(screen).active?
74
+ else
75
+ assert_equal true, AutomationObject::Framework.get.send(screen).active?
76
+ end
77
+ end
@@ -4,7 +4,7 @@ module AutomationObject
4
4
  module StepDefinitions
5
5
  # Cache module for temporary storage of vars
6
6
  module Cache
7
- module_function
7
+ extend self
8
8
 
9
9
  # Singleton hash, create new if needed
10
10
  # @return [Hash] hash of values saved or new hash
@@ -0,0 +1,10 @@
1
+ module MiniTestAssertions
2
+ def self.extended(base)
3
+ base.extend(MiniTest::Assertions)
4
+ base.assertions = 0
5
+ end
6
+
7
+ attr_accessor :assertions
8
+ end
9
+
10
+ World(MiniTestAssertions)
@@ -22,19 +22,19 @@ module AutomationObject
22
22
  private
23
23
 
24
24
  # Used to parse any embedded variables
25
- # @param string [String] index of arg
25
+ # @param string [String, nil] index of arg
26
26
  # @return [String] parsed string
27
27
  def parse(string)
28
- parsed_string = string
28
+ return string if string.nil?
29
29
 
30
- string.scan(/%\{(\w+)\}/) do |cache_key|
31
- cached_value = AutomationObject::StepDefinitions::Cache.get(cache_key)
32
- next unless cached_value
30
+ string.scan(/%\{[\w\d]+\}/) do |cache_key|
31
+ unwrapped_cache_key = cache_key.gsub(/[%\{\}]/, '')
33
32
 
34
- parsed_string.gsub("%{#{cache_key}}", cached_value)
33
+ cached_value = AutomationObject::StepDefinitions::Cache.get(unwrapped_cache_key)
34
+ return cached_value if cached_value
35
35
  end
36
36
 
37
- parsed_string
37
+ string
38
38
  end
39
39
  end
40
40
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module AutomationObject
3
- VERSION = '0.5.1'
3
+ VERSION = '0.6.0'
4
4
  end
@@ -11,6 +11,7 @@ Kernel.suppress_warnings do
11
11
  require 'appium_lib'
12
12
  require 'selenium-webdriver'
13
13
  require 'colorize'
14
+ require 'pry'
14
15
  end
15
16
 
16
17
  # Local Files
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automation_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Blatter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-07 00:00:00.000000000 Z
11
+ date: 2016-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,61 +151,61 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.8'
153
153
  - !ruby/object:Gem::Dependency
154
- name: minitest
154
+ name: mocha
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '5.9'
159
+ version: '1.1'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '5.9'
166
+ version: '1.1'
167
167
  - !ruby/object:Gem::Dependency
168
- name: minitest-bonus-assertions
168
+ name: fakefs
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '2.0'
173
+ version: '0.9'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '2.0'
180
+ version: '0.9'
181
181
  - !ruby/object:Gem::Dependency
182
- name: mocha
182
+ name: minitest
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '1.1'
188
- type: :development
187
+ version: '5.9'
188
+ type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: '1.1'
194
+ version: '5.9'
195
195
  - !ruby/object:Gem::Dependency
196
- name: fakefs
196
+ name: minitest-bonus-assertions
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '0.9'
202
- type: :development
201
+ version: '2.0'
202
+ type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '0.9'
208
+ version: '2.0'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: colorize
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -433,6 +433,7 @@ files:
433
433
  - lib/automation_object/step_definitions/support/cache.rb
434
434
  - lib/automation_object/step_definitions/support/element_array.rb
435
435
  - lib/automation_object/step_definitions/support/element_hash.rb
436
+ - lib/automation_object/step_definitions/support/minitest.rb
436
437
  - lib/automation_object/step_definitions/support/parse.rb
437
438
  - lib/automation_object/version.rb
438
439
  homepage: https://github.com/mikeblatter/automation_object