Class: Screen
Overview
The Screen class is a delegator which passes any methods it does not define–such as ‘fail’ and ‘log’–through to the Test Case instance.
Instance Method Summary collapse
-
#displayed?(args = {}) ⇒ Boolean
Public: Checks if the current screen is displayed.
-
#initialize(dut) ⇒ Screen
constructor
Public: Initializes a Screen.
-
#nav_to(args = {}) ⇒ Object
Public: Navigates to this screen.
-
#nav_to?(args = {}) ⇒ Boolean
Public: Navigates to this screen and verifies it.
-
#nav_to_key(key, start_key: nil, reset: false) ⇒ Object
Public: This function is used to navigate to the given key on the virtual keyboard.
-
#navigate(args = {}) ⇒ Object
Public: Navigates to this screen.
-
#navigate?(args = {}) ⇒ Boolean
Public: Navigates to this screen and verifies it.
-
#type_keys(*text, start_key: nil, delay_between_keys: 3000, reset: false) ⇒ Object
Public: This function is used to write the given text on the virtual keyboard.
-
#type_keys?(*text, start_key: nil, verify_roi: nil, delay_between_keys: 3000, reset: false) ⇒ Boolean
Public: This function is used to write the given text on the virtual keyboard.
Constructor Details
#initialize(dut) ⇒ Screen
Public: Initializes a Screen. NOT FOR USE IN TESTS.
dut - Platform (or subclass) instance for this Screen.
Returns nothing.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/screen/screen.rb', line 14 def initialize(dut) super(dut.send(:test_case)) @keyboards = [] @dut = dut instance_eval do @navigate = method(:navigate) def _navigate(args={}) sleep_time = args.fetch(:sleep_time, 0) logger.info("Navigating to #{this_screen_symbol}") unless displayed? @navigate.call(args) end sleep(sleep_time) if sleep_time > 0 end alias navigate _navigate class << self private :_navigate end end end |
Instance Method Details
#displayed?(args = {}) ⇒ Boolean
Public: Checks if the current screen is displayed.
timeout - Integer total milliseconds to check before timing out (default: 0.sec).
Returns a Boolean true if the screen is displayed, otherwise false.
92 93 94 |
# File 'lib/screen/screen.rb', line 92 def displayed?(args={}) raise "#{self.class}.#{__method__} is not implemented!" end |
#nav_to(args = {}) ⇒ Object
Public: Navigates to this screen. This is a wrapper for ‘navigate’.
sleep_time - Integer total milliseconds to sleep after performing the navigation (default: 0).
Returns nothing.
110 111 112 |
# File 'lib/screen/screen.rb', line 110 def nav_to(args={}) navigate(args) end |
#nav_to?(args = {}) ⇒ Boolean
Public: Navigates to this screen and verifies it. This is a wrapper for ‘navigate?’.
timeout - Integer total milliseconds to wait for the screen to display after navigation (default: 10.sec).
Returns a Boolean true if the navigation was successful, otherwise false.
130 131 132 |
# File 'lib/screen/screen.rb', line 130 def nav_to?(args={}) navigate?(args) end |
#nav_to_key(key, start_key: nil, reset: false) ⇒ Object
Public: This function is used to navigate to the given key on the virtual keyboard.
key - String key to navigate on the virtual keyboard. start_key - String non-default start key (default: nil). reset - Boolean indicating whether to reset the keyboard state before navigating (default: false).
Returns nothing.
81 82 83 84 85 |
# File 'lib/screen/screen.rb', line 81 def nav_to_key(key, start_key: nil, reset: false) unless current_keyboard(reset: reset).type?(key, :start_key => start_key, :nav_only => true) raise "Failed to navigate to key '#{key}'" end end |
#navigate(args = {}) ⇒ Object
Public: Navigates to this screen.
sleep_time - Integer total milliseconds to sleep after performing the navigation (default: 0).
Returns nothing.
101 102 103 |
# File 'lib/screen/screen.rb', line 101 def navigate(args={}) raise("Navigation not defined! #{this_screen_symbol}.navigate must be implemented.") end |
#navigate?(args = {}) ⇒ Boolean
Public: Navigates to this screen and verifies it.
timeout - Integer total milliseconds to wait for the screen to display after navigation (default: 10.sec).
Returns a Boolean true if the navigation was successful, otherwise false.
119 120 121 122 123 |
# File 'lib/screen/screen.rb', line 119 def navigate?(args={}) timeout = args.fetch(:timeout, 10.sec) navigate(:sleep_time => 0) displayed?(:timeout => timeout) end |
#type_keys(*text, start_key: nil, delay_between_keys: 3000, reset: false) ⇒ Object
Public: This function is used to write the given text on the virtual keyboard.
text - String or Splat Array of String key(s) to write on the virtual keyboard. start_key - String non-default start key (default: nil). delay_between_keys - Delay between key presses in ms min 3000 (default: 3000) reset - Boolean indicating whether to reset the keyboard state before typing (default: false).
Returns nothing.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/screen/screen.rb', line 62 def type_keys(*text, start_key: nil, delay_between_keys: 3000, reset: false) args = text.last.is_a?(Hash) ? text.pop : {} args.update(start_key: start_key) unless start_key.nil? args.update(delay_between_keys: delay_between_keys) if current_keyboard(reset: reset).type?(text, args) return true if args[:verify] else return false if args[:verify] raise 'Failed to type text!' end end |
#type_keys?(*text, start_key: nil, verify_roi: nil, delay_between_keys: 3000, reset: false) ⇒ Boolean
Public: This function is used to write the given text on the virtual keyboard.
text - String or Splat Array of String key(s) to write on the virtual keyboard. start_key - String non-default start key (default: nil). verify_roi - Roi object to verify the typed text (default: nil). delay_between_keys - Delay between key presses in ms min 3000 (default: 3000) reset - Boolean indicating whether to reset the keyboard state before typing (default: false).
Returns Boolean true if successfully able to write the given text. Else, returns false.
44 45 46 47 48 49 50 51 52 |
# File 'lib/screen/screen.rb', line 44 def type_keys?(*text, start_key: nil, verify_roi: nil, delay_between_keys:3000, reset: false) arg = {verify: true, verify_roi: verify_roi} if text.last.is_a?(Hash) text.last.update(arg) else text << arg end type_keys(*text, start_key: start_key, delay_between_keys: delay_between_keys, reset: reset) end |