Module: Selenium
Overview
Webdriver defines all the Webdriver methods in a module so that they can be included by other classes
Instance Method Summary collapse
-
#back?(args = {}) ⇒ Boolean
Public: Presses device Back button.
-
#element(attrs = {}) ⇒ Object
Public: Gets exactly one element matching the search criteria.
-
#element?(attrs = {}) ⇒ Boolean
Public: Checks if exactly one element matched the search criteria.
-
#elements(attrs = {}) ⇒ Object
Public: Gets all elements matching the search criteria.
-
#elements?(attrs = {}) ⇒ Boolean
Public: Check if any elements matched the search criteria.
-
#time_to_element(attrs = {}) ⇒ Object
Public: Measures time to find exactly one matching element.
-
#time_to_elements(attrs = {}) ⇒ Object
Public: Measures time to find any matching elements.
-
#type?(keys, args = {}) ⇒ Boolean
Public: Types on the device.
Instance Method Details
#back?(args = {}) ⇒ Boolean
Public: Presses device Back button.
sleep_time - Integer total milliseconds to wait after pressing Back (default: 0).
Returns a Boolean true if successfully pressed Back, otherwise false.
365 366 367 368 369 |
# File 'lib/selenium/selenium.rb', line 365 def back?(args={}) ret = selenium_post('back', {}) sleep(args.fetch(:sleep_time, 0.sec)) !ret.nil? end |
#element(attrs = {}) ⇒ Object
Public: Gets exactly one element matching the search criteria.
For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.
name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).
Corresponds to Android 'content-desc' and Ios 'label'.
selector - String automation selector (default: nil). index - Integer index of element to use among all matching elements (default: nil).
By default, exactly one element must match.
is_visible - Boolean indicating whether the element is visible (default: nil).
Corresponds to Ios 'visible'. Always true for Android.
is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).
Corresponds to Android 'clickable'. Android only.
is_password - Boolean indicating whether the element is a password field (default: nil).
Corresponds to Android 'password'. Android only.
is_enabled - Boolean indicating whether the element is enabled (default: nil).
Corresponds to Android and Ios 'enabled'.
is_checked - Boolean indicating whether the element is checked (default: nil).
Corresponds to Android 'checked'. Android only.
is_selected - Boolean indicating whether the element is selected (default: nil).
Corresponds to Android 'selected'.
is_checkable - Boolean indicating whether the element can be checked (default: nil).
Corresponds to Android 'checkable'. Android only.
is_focusable - Boolean indicating whether the element can be focused (default: nil).
Corresponds to Android 'focusable'. Android only.
is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).
Corresponds to Android 'long-clickable'. Android only.
is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).
Corresponds to Android 'scrollable'. Android only.
is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). info - Array of Symbols specifying attributes to retrieve (default: []).
By default, all attributes will be retrieved.
min - Integer minimum number of matching elements to require (default: 0).
By default, no restriction is imposed.
max - Integer maximum number of matching elements to require (default: nil).
By default, no restriction is imposed.
timeout - Integer total milliseconds to allow for element search (default: 30.sec).
Returns the matching Element, or nil if exactly one matching element was not found.
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/selenium/selenium.rb', line 234 def element(attrs={}) elem = selenium_post('element', attrs) if elem.nil? nil elsif attrs.fetch(:info, []).count == 1 Element.new(elem)[attrs[:info].first] else Element.new(elem) end end |
#element?(attrs = {}) ⇒ Boolean
Public: Checks if exactly one element matched the search criteria.
For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.
name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).
Corresponds to Android 'content-desc' and Ios 'label'.
selector - String automation selector (default: nil). index - Integer index of element to use among all matching elements (default: nil).
By default, exactly one element must match.
is_visible - Boolean indicating whether the element is visible (default: nil).
Corresponds to Ios 'visible'. Always true for Android.
is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).
Corresponds to Android 'clickable'. Android only.
is_password - Boolean indicating whether the element is a password field (default: nil).
Corresponds to Android 'password'. Android only.
is_enabled - Boolean indicating whether the element is enabled (default: nil).
Corresponds to Android and Ios 'enabled'.
is_checked - Boolean indicating whether the element is checked (default: nil).
Corresponds to Android 'checked'. Android only.
is_selected - Boolean indicating whether the element is selected (default: nil).
Corresponds to Android 'selected'.
is_checkable - Boolean indicating whether the element can be checked (default: nil).
Corresponds to Android 'checkable'. Android only.
is_focusable - Boolean indicating whether the element can be focused (default: nil).
Corresponds to Android 'focusable'. Android only.
is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).
Corresponds to Android 'long-clickable'. Android only.
is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).
Corresponds to Android 'scrollable'. Android only.
is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). info - Array of Symbols specifying attributes to retrieve (default: []).
By default, all attributes will be retrieved.
min - Integer minimum number of matching elements to require (default: 0).
By default, no restriction is imposed.
max - Integer maximum number of matching elements to require (default: nil).
By default, no restriction is imposed.
timeout - Integer total milliseconds to allow for element search (default: 30.sec).
Returns a Boolean true if exactly one element matched, otherwise false.
295 296 297 298 |
# File 'lib/selenium/selenium.rb', line 295 def element?(attrs={}) attrs[:info] = [] !element(attrs).nil? end |
#elements(attrs = {}) ⇒ Object
Public: Gets all elements matching the search criteria.
For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.
name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).
Corresponds to Android 'content-desc' and Ios 'label'.
selector - String automation selector (default: nil). is_visible - Boolean indicating whether the element is visible (default: nil).
Corresponds to Ios 'visible'. Always true for Android.
is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).
Corresponds to Android 'clickable'. Android only.
is_password - Boolean indicating whether the element is a password field (default: nil).
Corresponds to Android 'password'. Android only.
is_enabled - Boolean indicating whether the element is enabled (default: nil).
Corresponds to Android and Ios 'enabled'.
is_checked - Boolean indicating whether the element is checked (default: nil).
Corresponds to Android 'checked'. Android only.
is_selected - Boolean indicating whether the element is selected (default: nil).
Corresponds to Android 'selected'.
is_checkable - Boolean indicating whether the element can be checked (default: nil).
Corresponds to Android 'checkable'. Android only.
is_focusable - Boolean indicating whether the element can be focused (default: nil).
Corresponds to Android 'focusable'. Android only.
is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).
Corresponds to Android 'long-clickable'. Android only.
is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).
Corresponds to Android 'scrollable'. Android only.
is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). info - Array of Symbols specifying attributes to retrieve (default: []).
By default, all attributes will be retrieved.
min - Integer minimum number of matching elements to require (default: 0).
By default, no restriction is imposed.
max - Integer maximum number of matching elements to require (default: nil).
By default, no restriction is imposed.
timeout - Integer total milliseconds to allow for element search (default: 30.sec).
Returns an Array of matching Elements, or nil if no elements matched.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/selenium/selenium.rb', line 62 def elements(attrs={}) elems = (selenium_post('elements', attrs) || {})['elements'] if elems.nil? nil elsif attrs.fetch(:info, []).count == 1 elems.map {|e| Element.new(e)[attrs[:info].first]} else elems.map {|e| Element.new(e)} end end |
#elements?(attrs = {}) ⇒ Boolean
Public: Check if any elements matched the search criteria.
For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.
name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).
Corresponds to Android 'content-desc' and Ios 'label'.
selector - String automation selector (default: nil). is_visible - Boolean indicating whether the element is visible (default: nil).
Corresponds to Ios 'visible'. Always true for Android.
is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).
Corresponds to Android 'clickable'. Android only.
is_password - Boolean indicating whether the element is a password field (default: nil).
Corresponds to Android 'password'. Android only.
is_enabled - Boolean indicating whether the element is enabled (default: nil).
Corresponds to Android and Ios 'enabled'.
is_checked - Boolean indicating whether the element is checked (default: nil).
Corresponds to Android 'checked'. Android only.
is_selected - Boolean indicating whether the element is selected (default: nil).
Corresponds to Android 'selected'.
is_checkable - Boolean indicating whether the element can be checked (default: nil).
Corresponds to Android 'checkable'. Android only.
is_focusable - Boolean indicating whether the element can be focused (default: nil).
Corresponds to Android 'focusable'. Android only.
is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).
Corresponds to Android 'long-clickable'. Android only.
is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).
Corresponds to Android 'scrollable'. Android only.
is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). info - Array of Symbols specifying attributes to retrieve (default: []).
By default, all attributes will be retrieved.
min - Integer minimum number of matching elements to require (default: 0).
By default, no restriction is imposed.
max - Integer maximum number of matching elements to require (default: nil).
By default, no restriction is imposed.
timeout - Integer total milliseconds to allow for element search (default: 30.sec).
Returns a Boolean true if any elements matched, otherwise false.
121 122 123 124 125 |
# File 'lib/selenium/selenium.rb', line 121 def elements?(attrs={}) attrs[:info] = [] elems = elements(attrs) elems.nil? ? false : elems.size > 0 end |
#time_to_element(attrs = {}) ⇒ Object
Public: Measures time to find exactly one matching element.
For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.
name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).
Corresponds to Android 'content-desc' and Ios 'label'.
selector - String automation selector (default: nil). index - Integer index of element to use among all matching elements (default: nil).
By default, exactly one element must match.
is_visible - Boolean indicating whether the element is visible (default: nil).
Corresponds to Ios 'visible'. Always true for Android.
is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).
Corresponds to Android 'clickable'. Android only.
is_password - Boolean indicating whether the element is a password field (default: nil).
Corresponds to Android 'password'. Android only.
is_enabled - Boolean indicating whether the element is enabled (default: nil).
Corresponds to Android and Ios 'enabled'.
is_checked - Boolean indicating whether the element is checked (default: nil).
Corresponds to Android 'checked'. Android only.
is_selected - Boolean indicating whether the element is selected (default: nil).
Corresponds to Android 'selected'.
is_checkable - Boolean indicating whether the element can be checked (default: nil).
Corresponds to Android 'checkable'. Android only.
is_focusable - Boolean indicating whether the element can be focused (default: nil).
Corresponds to Android 'focusable'. Android only.
is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).
Corresponds to Android 'long-clickable'. Android only.
is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).
Corresponds to Android 'scrollable'. Android only.
is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). info - Array of Symbols specifying attributes to retrieve (default: []).
By default, all attributes will be retrieved.
min - Integer minimum number of matching elements to require (default: 0).
By default, no restriction is imposed.
max - Integer maximum number of matching elements to require (default: nil).
By default, no restriction is imposed.
timeout - Integer total milliseconds to allow for element search (default: 30.sec).
Returns the Integer total milliseconds to match exactly one element,
or nil if exactly one matching element was not found.
351 352 353 354 355 356 357 358 |
# File 'lib/selenium/selenium.rb', line 351 def time_to_element(attrs={}) start_time = Time.now if element?(attrs) ((Time.now - start_time) * 1000).round else nil end end |
#time_to_elements(attrs = {}) ⇒ Object
Public: Measures time to find any matching elements.
For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.
name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).
Corresponds to Android 'content-desc' and Ios 'label'.
selector - String automation selector (default: nil). is_visible - Boolean indicating whether the element is visible (default: nil).
Corresponds to Ios 'visible'. Always true for Android.
is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).
Corresponds to Android 'clickable'. Android only.
is_password - Boolean indicating whether the element is a password field (default: nil).
Corresponds to Android 'password'. Android only.
is_enabled - Boolean indicating whether the element is enabled (default: nil).
Corresponds to Android and Ios 'enabled'.
is_checked - Boolean indicating whether the element is checked (default: nil).
Corresponds to Android 'checked'. Android only.
is_selected - Boolean indicating whether the element is selected (default: nil).
Corresponds to Android 'selected'.
is_checkable - Boolean indicating whether the element can be checked (default: nil).
Corresponds to Android 'checkable'. Android only.
is_focusable - Boolean indicating whether the element can be focused (default: nil).
Corresponds to Android 'focusable'. Android only.
is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).
Corresponds to Android 'long-clickable'. Android only.
is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).
Corresponds to Android 'scrollable'. Android only.
is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). info - Array of Symbols specifying attributes to retrieve (default: []).
By default, all attributes will be retrieved.
min - Integer minimum number of matching elements to require (default: 0).
By default, no restriction is imposed.
max - Integer maximum number of matching elements to require (default: nil).
By default, no restriction is imposed.
timeout - Integer total milliseconds to allow for element search (default: 30.sec).
Returns the Integer total milliseconds to match any elements, or nil if no elements matched.
175 176 177 178 179 180 181 182 |
# File 'lib/selenium/selenium.rb', line 175 def time_to_elements(attrs={}) start_time = Time.now if elements?(attrs) ((Time.now - start_time) * 1000).round else nil end end |
#type?(keys, args = {}) ⇒ Boolean
Public: Types on the device. The keys will be typed into the selected/focused element.
keys - String or Array of String keys to type. touch - Boolean indicating whether to simulate physical key presses (default: false). sleep_time - Integer total milliseconds to sleep after typing (default: 0).
Returns a Boolean true if successfully typed, otherwise false.
378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/selenium/selenium.rb', line 378 def type?(keys, args={}) unless keys.is_a?(Hash) keys = {:keys => keys} end args = keys.merge(args) args[:touch] ||= false unless args[:keys].is_a?(Array) args[:keys] = args[:keys].split('') end ret = selenium_post('type', args) sleep(args.fetch(:sleep_time, 0.sec)) !ret.nil? end |