automation_object 0.0.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/automation_object.rb +14 -72
- data/lib/automation_object/blue_print.rb +37 -100
- data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +28 -0
- data/lib/automation_object/blue_print/composite/base.rb +18 -0
- data/lib/automation_object/blue_print/composite/custom_method.rb +23 -0
- data/lib/automation_object/blue_print/composite/element.rb +20 -0
- data/lib/automation_object/blue_print/composite/element_array.rb +21 -0
- data/lib/automation_object/blue_print/composite/element_hash.rb +26 -0
- data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +33 -0
- data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +18 -0
- data/lib/automation_object/blue_print/composite/hook.rb +31 -0
- data/lib/automation_object/blue_print/composite/hook_action.rb +84 -0
- data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +39 -0
- data/lib/automation_object/blue_print/composite/modal.rb +56 -0
- data/lib/automation_object/blue_print/composite/screen.rb +61 -0
- data/lib/automation_object/blue_print/composite/top.rb +51 -0
- data/lib/automation_object/blue_print/composite/view.rb +48 -0
- data/lib/automation_object/blue_print/hash_adapter.rb +17 -0
- data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/composite.rb +93 -0
- data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +30 -0
- data/lib/automation_object/blue_print/hash_adapter/element.rb +34 -0
- data/lib/automation_object/blue_print/hash_adapter/element_array.rb +36 -0
- data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +43 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +59 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +26 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +99 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +23 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +31 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +55 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +39 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +54 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +36 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +55 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +52 -0
- data/lib/automation_object/blue_print/hash_adapter/hook.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +134 -0
- data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +64 -0
- data/lib/automation_object/blue_print/hash_adapter/modal.rb +52 -0
- data/lib/automation_object/blue_print/hash_adapter/screen.rb +91 -0
- data/lib/automation_object/blue_print/hash_adapter/top.rb +63 -0
- data/lib/automation_object/blue_print/hash_adapter/view.rb +29 -0
- data/lib/automation_object/blue_print/helpers/file_helper.rb +38 -0
- data/lib/automation_object/blue_print/yaml_adapter.rb +50 -0
- data/lib/automation_object/driver.rb +44 -0
- data/lib/automation_object/driver/appium_adapter/driver.rb +150 -0
- data/lib/automation_object/driver/appium_adapter/element.rb +118 -0
- data/lib/automation_object/driver/base.rb +11 -0
- data/lib/automation_object/driver/driver.rb +69 -245
- data/lib/automation_object/driver/element.rb +51 -210
- data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +41 -0
- data/lib/automation_object/driver/helpers/selenium_element_helper.rb +138 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +83 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +66 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/form.rb +29 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +52 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +115 -0
- data/lib/automation_object/driver/nokogiri_adapter/driver.rb +104 -0
- data/lib/automation_object/driver/nokogiri_adapter/element.rb +85 -0
- data/lib/automation_object/driver/nokogiri_adapter/error.rb +17 -0
- data/lib/automation_object/driver/selenium_adapter/driver.rb +143 -0
- data/lib/automation_object/driver/selenium_adapter/element.rb +116 -0
- data/lib/automation_object/dsl.rb +33 -0
- data/lib/automation_object/dsl/blue_print_adapter.rb +16 -0
- data/lib/automation_object/dsl/blue_print_adapter/composite.rb +54 -0
- data/lib/automation_object/dsl/blue_print_adapter/element.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/modal.rb +23 -0
- data/lib/automation_object/dsl/blue_print_adapter/screen.rb +26 -0
- data/lib/automation_object/dsl/blue_print_adapter/top.rb +19 -0
- data/lib/automation_object/dsl/models.rb +18 -0
- data/lib/automation_object/dsl/proxies/element.rb +16 -0
- data/lib/automation_object/dsl/proxies/element_array.rb +16 -0
- data/lib/automation_object/dsl/proxies/element_hash.rb +16 -0
- data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +74 -0
- data/lib/automation_object/dsl/proxies/modal.rb +17 -0
- data/lib/automation_object/dsl/proxies/screen.rb +17 -0
- data/lib/automation_object/dsl/proxies/top.rb +17 -0
- data/lib/automation_object/framework.rb +79 -386
- data/lib/automation_object/helpers/composite.rb +95 -0
- data/lib/automation_object/helpers/composite_hook.rb +46 -0
- data/lib/automation_object/helpers/hash.rb +15 -0
- data/lib/automation_object/helpers/reflection_helper.rb +28 -0
- data/lib/automation_object/helpers/string.rb +27 -0
- data/lib/automation_object/proxies/mutex_proxy.rb +63 -0
- data/lib/automation_object/proxies/proxy.rb +20 -0
- data/lib/automation_object/proxies/throttle_proxy.rb +57 -0
- data/lib/automation_object/state.rb +37 -0
- data/lib/automation_object/state/blue_print_adapter.rb +16 -0
- data/lib/automation_object/state/blue_print_adapter/composite.rb +65 -0
- data/lib/automation_object/state/blue_print_adapter/element.rb +20 -0
- data/lib/automation_object/state/blue_print_adapter/element_array.rb +25 -0
- data/lib/automation_object/state/blue_print_adapter/element_hash.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +28 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/element_helper.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +137 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +39 -0
- data/lib/automation_object/state/blue_print_adapter/hook.rb +56 -0
- data/lib/automation_object/state/blue_print_adapter/hook_action.rb +33 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +35 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/change_screen.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/change_to_previous_screen.rb +21 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +19 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +34 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +37 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/possible_screen_changes.rb +21 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +18 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/show_modal.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/sleep.rb +18 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/wait_for_elements.rb +20 -0
- data/lib/automation_object/state/blue_print_adapter/modal.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/screen.rb +32 -0
- data/lib/automation_object/state/blue_print_adapter/top.rb +45 -0
- data/lib/automation_object/state/error.rb +24 -0
- data/lib/automation_object/state/session.rb +38 -0
- data/lib/automation_object/step_definitions.rb +14 -0
- data/lib/automation_object/step_definitions/action.rb +21 -0
- data/lib/automation_object/step_definitions/cache.rb +23 -0
- data/lib/automation_object/step_definitions/element/actions.rb +87 -0
- data/lib/automation_object/step_definitions/element/regex.rb +24 -0
- data/lib/automation_object/step_definitions/element/steps.rb +67 -0
- data/lib/automation_object/step_definitions/parse.rb +39 -0
- data/lib/automation_object/version.rb +1 -1
- metadata +194 -110
- data/lib/automation_object/blue_print_validation/base_validation.rb +0 -44
- data/lib/automation_object/blue_print_validation/common_methods.rb +0 -106
- data/lib/automation_object/blue_print_validation/element_validation.rb +0 -198
- data/lib/automation_object/blue_print_validation/formatted_errors.rb +0 -41
- data/lib/automation_object/blue_print_validation/hook_validation.rb +0 -393
- data/lib/automation_object/blue_print_validation/key_value_constants.rb +0 -75
- data/lib/automation_object/blue_print_validation/modal_validation.rb +0 -37
- data/lib/automation_object/blue_print_validation/screen_modal_common_methods.rb +0 -119
- data/lib/automation_object/blue_print_validation/screen_validation.rb +0 -21
- data/lib/automation_object/blue_print_validation/validation_object.rb +0 -32
- data/lib/automation_object/driver/anonymous.rb +0 -27
- data/lib/automation_object/element/element.rb +0 -145
- data/lib/automation_object/element/element_array.rb +0 -12
- data/lib/automation_object/element/element_cell.rb +0 -126
- data/lib/automation_object/element/element_group.rb +0 -33
- data/lib/automation_object/element/element_hash.rb +0 -25
- data/lib/automation_object/element/element_helpers.rb +0 -29
- data/lib/automation_object/element/element_methods.rb +0 -134
- data/lib/automation_object/element/elements_helpers.rb +0 -204
- data/lib/automation_object/framework/events.rb +0 -8
- data/lib/automation_object/framework/helpers.rb +0 -101
- data/lib/automation_object/framework/print_objects.rb +0 -67
- data/lib/automation_object/framework/screen_monitor.rb +0 -55
- data/lib/automation_object/framework/screen_routing.rb +0 -310
- data/lib/automation_object/framework/window_helpers.rb +0 -181
- data/lib/automation_object/hash.rb +0 -6
- data/lib/automation_object/hook_helpers.rb +0 -27
- data/lib/automation_object/logger.rb +0 -179
- data/lib/automation_object/object.rb +0 -22
- data/lib/automation_object/screen/modal.rb +0 -8
- data/lib/automation_object/screen/screen.rb +0 -209
- data/lib/automation_object/screen/screen_hook_helpers.rb +0 -319
- data/lib/automation_object/screen/screen_modal_helpers.rb +0 -101
- data/lib/automation_object/screen/screen_prompt_helpers.rb +0 -21
- data/lib/automation_object/screen/screen_window_helpers.rb +0 -149
@@ -0,0 +1,118 @@
|
|
1
|
+
require_relative '../helpers/selenium_element_helper'
|
2
|
+
|
3
|
+
module AutomationObject
|
4
|
+
module Driver
|
5
|
+
module AppiumAdapter
|
6
|
+
#Element proxy for Appium
|
7
|
+
#Conform Appium element interface to what's expected of the Driver Port
|
8
|
+
class Element < AutomationObject::Proxies::Proxy
|
9
|
+
include AutomationObject::Driver::SeleniumElementHelper
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
@driver = args.fetch :driver
|
13
|
+
@subject = args.fetch :element
|
14
|
+
end
|
15
|
+
|
16
|
+
# Set or Get attribute
|
17
|
+
# @param key [String] key of element
|
18
|
+
# @param value [String, nil] set value or leave blank
|
19
|
+
# @return [String, nil]
|
20
|
+
def attribute(key, value = nil)
|
21
|
+
@subject.attribute(key, value)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] id of element
|
25
|
+
def id
|
26
|
+
@subject.id
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String] href of element
|
30
|
+
def href
|
31
|
+
@subject.attribute('href')
|
32
|
+
end
|
33
|
+
|
34
|
+
# Text of element
|
35
|
+
# @return [String, nil]
|
36
|
+
def text
|
37
|
+
@subject.text
|
38
|
+
end
|
39
|
+
|
40
|
+
# Type into an element
|
41
|
+
# @return [void]
|
42
|
+
def send_keys(string)
|
43
|
+
@subject.send_keys(string)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Clear the element field
|
47
|
+
# @return [void]
|
48
|
+
def clear
|
49
|
+
@subject.clear
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Boolean]
|
53
|
+
def visible?
|
54
|
+
@subject.displayed?
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean]
|
58
|
+
def invisible?
|
59
|
+
!@subject.displayed?
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get the location
|
63
|
+
# @return [Point]
|
64
|
+
def location
|
65
|
+
@subject.location
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get the size of an element
|
69
|
+
# @return [Dimension]
|
70
|
+
def size
|
71
|
+
@subject.size
|
72
|
+
end
|
73
|
+
|
74
|
+
# Perform a submit action on an element
|
75
|
+
# @return [void]
|
76
|
+
def submit
|
77
|
+
@subject.submit
|
78
|
+
end
|
79
|
+
|
80
|
+
# Scroll the element into view
|
81
|
+
# @return [void]
|
82
|
+
def scroll_into_view
|
83
|
+
@subject.location_once_scrolled_into_view
|
84
|
+
|
85
|
+
#Only scroll better if this is a browser and not an app
|
86
|
+
return unless @driver.is_browser?
|
87
|
+
|
88
|
+
element_center = self.element_center
|
89
|
+
window_height = self.inner_window_height
|
90
|
+
scroll_position = @driver.scroll_position
|
91
|
+
|
92
|
+
if element_center[:y] < (window_height/2)
|
93
|
+
ideal_y_position = (scroll_position[:y] + element_center[:y] - (window_height.to_f / 2.0)).abs
|
94
|
+
else
|
95
|
+
ideal_y_position = (scroll_position[:y] - element_center[:y] + (window_height.to_f / 2.0)).abs
|
96
|
+
end
|
97
|
+
|
98
|
+
@driver.execute_script("window.scroll(#{element_center[:x]},#{ideal_y_position});")
|
99
|
+
#Just in case in close to the top or bottom bounds of the window
|
100
|
+
element_location = @subject.location_once_scrolled_into_view
|
101
|
+
|
102
|
+
if element_location[:y] < 0
|
103
|
+
scroll_position = @driver.scroll_position
|
104
|
+
scroll_y_position = scroll_position[:y] + element_location[:y]
|
105
|
+
@driver.execute_script("window.scroll(#{element_location[:x]},#{scroll_y_position});")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Perform a click action on the element
|
110
|
+
# @return [void]
|
111
|
+
def click
|
112
|
+
self.scroll_into_view if @driver.is_browser?
|
113
|
+
@subject.click
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -1,280 +1,104 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
|
+
require_relative 'element'
|
3
|
+
|
2
4
|
module AutomationObject
|
3
5
|
module Driver
|
4
|
-
|
5
|
-
|
6
|
-
attr_accessor :mutex_object
|
7
|
-
|
8
|
-
attr_accessor :is_browser, :is_mobile, :supports_contexts
|
9
|
-
|
10
|
-
@@throttle_methods = {
|
11
|
-
'navigate' => 2,
|
12
|
-
'close' => 2,
|
13
|
-
'manage' => 1
|
14
|
-
}
|
15
|
-
|
16
|
-
@@minimum_speed = 0 #0.01 #Speed it up to see where faults may lay
|
17
|
-
|
18
|
-
@@implicit_wait_timeout = 30
|
19
|
-
@@script_timeout = 500
|
20
|
-
@@page_load_timeout = 500
|
21
|
-
|
22
|
-
def self.throttle_methods
|
23
|
-
@@throttle_methods
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.throttle_methods=(value)
|
27
|
-
@@throttle_methods = value
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.minimum_speed
|
31
|
-
@@minimum_speed
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.minimum_speed=(value)
|
35
|
-
@@minimum_speed = value
|
36
|
-
end
|
37
|
-
|
38
|
-
def initialize(driver_object)
|
39
|
-
@driver_object = driver_object
|
40
|
-
self.mutex_object = Mutex.new
|
41
|
-
|
42
|
-
return if self.is_mobile?
|
6
|
+
Point = Struct.new(:x, :y)
|
7
|
+
Dimension = Struct.new(:width, :height)
|
43
8
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
9
|
+
#Driver adapter interface
|
10
|
+
#Adapters should meet this interface standard
|
11
|
+
class Driver < Base
|
12
|
+
# Navigates current window to a given url
|
13
|
+
# @param url [String] navigate to the following url
|
14
|
+
# @return [void]
|
15
|
+
def get(url)
|
16
|
+
self.adapter.get(url)
|
49
17
|
end
|
50
18
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def method_missing(method_symbol, *arguments, &block)
|
59
|
-
anonymous_object = nil
|
60
|
-
start_time = Time.new.to_f
|
61
|
-
|
62
|
-
self.mutex_object.synchronize do
|
63
|
-
#For Appium because it's under driver method
|
64
|
-
if @driver_object.respond_to?(:driver) and not @driver_object.respond_to?(method_symbol)
|
65
|
-
driver_return = @driver_object.driver.send(method_symbol, *arguments, &block)
|
66
|
-
else
|
67
|
-
driver_return = @driver_object.send(method_symbol, *arguments, &block)
|
68
|
-
end
|
69
|
-
|
70
|
-
self.throttle_speed(method_symbol, start_time)
|
71
|
-
|
72
|
-
total_time_taken = (Time.new.to_f-start_time)
|
73
|
-
AutomationObject::Logger::add_driver_message(total_time_taken, caller_locations, method_symbol, *arguments, &block)
|
74
|
-
|
75
|
-
@@anonymous_skip_classes.each { |skip_class|
|
76
|
-
if driver_return.is_a?(skip_class)
|
77
|
-
return driver_return
|
78
|
-
end
|
79
|
-
}
|
80
|
-
|
81
|
-
anonymous_object = AutomationObject::Driver::Anonymous.new(self, driver_return)
|
82
|
-
end
|
83
|
-
|
84
|
-
return anonymous_object
|
19
|
+
# Set timeout wait
|
20
|
+
# @param timeout [Integer] the timeout in seconds
|
21
|
+
# @return [void]
|
22
|
+
def set_wait(timeout = nil)
|
23
|
+
self.adapter.set_wait(timeout)
|
85
24
|
end
|
86
25
|
|
26
|
+
# @param selector_type [Symbol] selector type (:css, :xpath, etc...)
|
27
|
+
# @param selector_path [String] path to element
|
28
|
+
# @return [Boolean] exists or not
|
87
29
|
def exists?(selector_type, selector_path)
|
88
|
-
|
89
|
-
|
90
|
-
self.mutex_object.synchronize do
|
91
|
-
if @driver_object.respond_to?(:exists) #Appium
|
92
|
-
exists = @driver_object.exists { @driver_object.find_element(selector_type, selector_path) }
|
93
|
-
else
|
94
|
-
begin
|
95
|
-
@driver_object.manage.timeouts.implicit_wait = 0
|
96
|
-
element_objects = @driver_object.find_elements(selector_type, selector_path)
|
97
|
-
@driver_object.manage.timeouts.implicit_wait = @@implicit_wait_timeout
|
98
|
-
if element_objects.length == 0
|
99
|
-
exists = false
|
100
|
-
else
|
101
|
-
exists = true
|
102
|
-
end
|
103
|
-
rescue
|
104
|
-
exists = false
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
self.throttle_speed(:exists?, start_time)
|
109
|
-
|
110
|
-
total_time_taken = (Time.new.to_f-start_time)
|
111
|
-
AutomationObject::Logger::add_driver_message(total_time_taken, caller_locations, :exists?, [selector_type, selector_path])
|
112
|
-
|
113
|
-
return exists
|
114
|
-
end
|
30
|
+
self.adapter.exists?(selector_type, selector_path)
|
115
31
|
end
|
116
32
|
|
33
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
34
|
+
# @param selector_path [String] path to element
|
35
|
+
# @return [AutomationObject::Driver::Element] element
|
117
36
|
def find_element(selector_type, selector_path)
|
118
|
-
|
119
|
-
|
120
|
-
self.mutex_object.synchronize do
|
121
|
-
element_object = @driver_object.find_element(selector_type, selector_path)
|
122
|
-
|
123
|
-
self.throttle_speed(:find_element, start_time)
|
124
|
-
|
125
|
-
total_time_taken = (Time.new.to_f-start_time)
|
126
|
-
AutomationObject::Logger::add_driver_message(total_time_taken, caller_locations, :find_element, [selector_type, selector_path])
|
127
|
-
|
128
|
-
return AutomationObject::Driver::Element.new(self, element_object)
|
129
|
-
end
|
37
|
+
self.adapter.find_element(selector_type, selector_path)
|
130
38
|
end
|
131
39
|
|
40
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
41
|
+
# @param selector_path [String] path to element
|
42
|
+
# @return [Array<AutomationObject::Driver::Element>] elements
|
132
43
|
def find_elements(selector_type, selector_path)
|
133
|
-
|
134
|
-
|
135
|
-
self.mutex_object.synchronize do
|
136
|
-
element_objects = @driver_object.find_elements(selector_type, selector_path)
|
137
|
-
|
138
|
-
parsed_element_objects = Array.new
|
139
|
-
element_objects.each { |element_object|
|
140
|
-
parsed_element_objects.push(AutomationObject::Driver::Element.new(self, element_object))
|
141
|
-
}
|
142
|
-
|
143
|
-
self.throttle_speed(:find_elements, start_time)
|
144
|
-
|
145
|
-
total_time_taken = (Time.new.to_f-start_time)
|
146
|
-
AutomationObject::Logger::add_driver_message(total_time_taken, caller_locations, :find_elements, [selector_type, selector_path])
|
147
|
-
|
148
|
-
return parsed_element_objects
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def throttle_speed(method_symbol, start_time)
|
153
|
-
method_string = method_symbol.to_s
|
154
|
-
|
155
|
-
throttle_time_minimum = @@minimum_speed
|
156
|
-
if @@throttle_methods.is_a?(Hash)
|
157
|
-
if @@throttle_methods.has_key?(method_string)
|
158
|
-
throttle_time_minimum = @@throttle_methods[method_string].to_f
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
time_difference = Time.new.to_f - start_time
|
163
|
-
|
164
|
-
if time_difference < throttle_time_minimum
|
165
|
-
sleep((throttle_time_minimum-time_difference))
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def screenshot(path)
|
170
|
-
start_time = Time.new.to_f
|
171
|
-
|
172
|
-
if self.driver_object.respond_to?(:screenshot)
|
173
|
-
driver_return = self.driver_object.screenshot(path)
|
174
|
-
else
|
175
|
-
driver_return = self.driver_object.save_screenshot(path)
|
176
|
-
end
|
177
|
-
|
178
|
-
self.throttle_speed(:find_elements, start_time)
|
179
|
-
|
180
|
-
total_time_taken = (Time.new.to_f-start_time)
|
181
|
-
AutomationObject::Logger::add_driver_message(total_time_taken, caller_locations, :screenshot, [path])
|
182
|
-
|
183
|
-
return driver_return
|
44
|
+
self.adapter.find_elements(selector_type, selector_path)
|
184
45
|
end
|
185
46
|
|
47
|
+
#Accept prompt either in browser or mobile
|
186
48
|
def accept_prompt
|
187
|
-
|
188
|
-
|
189
|
-
if self.driver_object.respond_to?(:alert_accept)
|
190
|
-
self.driver_object.alert_accept
|
191
|
-
else
|
192
|
-
alert = self.driver_object.switch_to.alert
|
193
|
-
alert.accept
|
194
|
-
end
|
195
|
-
|
196
|
-
self.throttle_speed(:accept_prompt, start_time)
|
197
|
-
return nil
|
49
|
+
self.adapter.accept_prompt
|
198
50
|
end
|
199
51
|
|
52
|
+
#Dismiss the prompt
|
200
53
|
def dismiss_prompt
|
201
|
-
|
202
|
-
|
203
|
-
begin
|
204
|
-
@driver_object.alert_dismiss
|
205
|
-
rescue NoMethodError
|
206
|
-
alert = @driver_object.switch_to.alert
|
207
|
-
alert.dismiss
|
208
|
-
@driver_object.switch_to.default_content
|
209
|
-
end
|
210
|
-
|
211
|
-
self.throttle_speed(:dismiss_prompt, start_time)
|
212
|
-
return nil
|
213
|
-
end
|
214
|
-
|
215
|
-
def is_mobile?
|
216
|
-
if self.is_mobile == nil
|
217
|
-
self.is_mobile = self.supports_contexts?
|
218
|
-
end
|
219
|
-
|
220
|
-
return self.is_mobile
|
54
|
+
self.adapter.dismiss_prompt
|
221
55
|
end
|
222
56
|
|
57
|
+
# Check if browser, more useful for Appium but can be generic here
|
58
|
+
# @return [Boolean] whether or not browser is being used
|
223
59
|
def is_browser?
|
224
|
-
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
#If Selenium the yeah we are using a browser
|
229
|
-
if self.supports_window_handles?
|
230
|
-
self.is_browser = true
|
231
|
-
return self.is_browser
|
232
|
-
end
|
60
|
+
self.adapter.is_browser?
|
61
|
+
end
|
233
62
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
self.supports_contexts = true
|
63
|
+
#Window Handles
|
64
|
+
# @return [Array<String>] array of window handle ids
|
65
|
+
def window_handles
|
66
|
+
self.adapter.window_handles
|
67
|
+
end
|
240
68
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
}
|
69
|
+
#Current window handle
|
70
|
+
# @return [String] handle id
|
71
|
+
def window_handle
|
72
|
+
self.adapter.window_handle
|
73
|
+
end
|
247
74
|
|
248
|
-
|
249
|
-
|
75
|
+
#Set current window handle to, will switch windows
|
76
|
+
# @param handle_value [String] window handle value
|
77
|
+
def window_handle=(handle_value)
|
78
|
+
self.adapter.window_handle(handle_value)
|
250
79
|
end
|
251
80
|
|
252
|
-
#
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
@driver_object.window_handles
|
257
|
-
end
|
258
|
-
return true
|
259
|
-
rescue NoMethodError, Selenium::WebDriver::Error::UnknownError
|
260
|
-
return false
|
261
|
-
end
|
81
|
+
# Run script in browser to check if document in JS is complete
|
82
|
+
# @return [Boolean] document is complete
|
83
|
+
def document_complete?
|
84
|
+
self.adapter.document_complete?
|
262
85
|
end
|
263
86
|
|
264
|
-
#
|
265
|
-
|
266
|
-
|
87
|
+
# Wait till the document is complete
|
88
|
+
# @return [void]
|
89
|
+
def document_complete_wait
|
90
|
+
self.adapter.document_complete_wait
|
91
|
+
end
|
267
92
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
self.supports_contexts = false
|
274
|
-
end
|
275
|
-
end
|
93
|
+
# @param script [String] JS to run
|
94
|
+
# @return [Object, nil]
|
95
|
+
def execute_script(script)
|
96
|
+
self.adapter.execute_script(script)
|
97
|
+
end
|
276
98
|
|
277
|
-
|
99
|
+
# Destroy the driver
|
100
|
+
def quit
|
101
|
+
self.adapter.quit
|
278
102
|
end
|
279
103
|
end
|
280
104
|
end
|