automation_object 0.0.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,83 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
|
|
4
|
+
require_relative 'session'
|
|
5
|
+
require_relative 'element'
|
|
6
|
+
require_relative 'helpers/driver_element_helper'
|
|
7
|
+
|
|
8
|
+
module AutomationObject::Driver::NokogiriAdapter
|
|
9
|
+
#Driver proxy for Nokogiri(XML)
|
|
10
|
+
#Create driver interface that conforms to Driver port
|
|
11
|
+
#Works differently than Appium/Selenium, not a proxy, but creates the functionality of the driver
|
|
12
|
+
class Driver
|
|
13
|
+
include DriverElementHelper
|
|
14
|
+
|
|
15
|
+
attr_accessor :current_url
|
|
16
|
+
|
|
17
|
+
def initialize(*args)
|
|
18
|
+
@session = Session.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def navigate
|
|
22
|
+
self
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to(url)
|
|
26
|
+
@session.get(url)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def back
|
|
30
|
+
@session.back
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def quit
|
|
34
|
+
@session.quit
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def close
|
|
38
|
+
@session.close
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def current_url
|
|
42
|
+
@session.current_url
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def window_handles
|
|
46
|
+
@session.window_handles
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def window_handle
|
|
50
|
+
@session.window_handle
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def window_handle=(handle_value)
|
|
54
|
+
@session.window_handle = handle_value
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def new_window
|
|
58
|
+
@session.new_window
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def xml
|
|
62
|
+
@session.xml
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def title
|
|
66
|
+
title = ''
|
|
67
|
+
title_element = self.find_element(:xpath, '//title')
|
|
68
|
+
if title_element
|
|
69
|
+
title = title_element.text
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
return title
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def get(url, params = {})
|
|
76
|
+
@session.get(url, params)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def post(url, params = {})
|
|
80
|
+
@session.post(url, params)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require_relative 'form'
|
|
2
|
+
|
|
3
|
+
module AutomationObject::Driver::NokogiriAdapter
|
|
4
|
+
#Element class for Nokogiri/XML
|
|
5
|
+
class Element < AutomationObject::Proxies::Proxy
|
|
6
|
+
def initialize(args)
|
|
7
|
+
@driver = args.fetch :driver
|
|
8
|
+
@subject = args.fetch :element
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @return [String] id of element
|
|
12
|
+
def id
|
|
13
|
+
@subject['id']
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @return [String] href of element
|
|
17
|
+
def href
|
|
18
|
+
@subject['href']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @return [String] text of element
|
|
22
|
+
def text
|
|
23
|
+
@subject['content']
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return [String] content of element
|
|
27
|
+
def content
|
|
28
|
+
@subject['content']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def attribute(key, value = nil)
|
|
32
|
+
@subject[key] = value if value
|
|
33
|
+
return @subject[key]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def click
|
|
37
|
+
url = self.href
|
|
38
|
+
if self.attribute('target') == '_blank'
|
|
39
|
+
@driver.new_window
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
@driver.get(url)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def send_keys(text)
|
|
46
|
+
@subject['value'] = text
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def submit
|
|
50
|
+
form = find_form(@subject)
|
|
51
|
+
raise 'Unable to find form' unless form_element
|
|
52
|
+
|
|
53
|
+
@driver.send(form.request_method, form.params)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# @return [AutomationObject::Driver:NokogiriAdapter::Form]
|
|
59
|
+
def find_form(element)
|
|
60
|
+
return nil unless element
|
|
61
|
+
|
|
62
|
+
return AutomationObject::Driver::NokogiriAdapter::Form.new(element) if element.name == 'form'
|
|
63
|
+
return find_form(element.parent)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module AutomationObject
|
|
2
|
+
module Driver
|
|
3
|
+
module NokogiriAdapter
|
|
4
|
+
class Form
|
|
5
|
+
# @param node [Nokogiri::XML::Node]
|
|
6
|
+
def initialize(node)
|
|
7
|
+
@node = node
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# @return [Hash]
|
|
11
|
+
def params
|
|
12
|
+
params = {}
|
|
13
|
+
|
|
14
|
+
@node.traverse { |node|
|
|
15
|
+
next unless node.name == 'input'
|
|
16
|
+
params[node['name']] = node['value']
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return params
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @return [Symbol]
|
|
23
|
+
def request_method
|
|
24
|
+
(@node['method'].upcase == 'GET') ? :get : :post
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require_relative '../error'
|
|
2
|
+
|
|
3
|
+
module AutomationObject
|
|
4
|
+
module Driver
|
|
5
|
+
module NokogiriAdapter
|
|
6
|
+
module DriverElementHelper
|
|
7
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
|
8
|
+
# @param selector_path [String] path to element
|
|
9
|
+
# @return [Element] element
|
|
10
|
+
def find_element(selector_type, selector_path)
|
|
11
|
+
elements = self.get_elements(selector_type, selector_path)
|
|
12
|
+
raise NoSuchElementError if elements.length == 0
|
|
13
|
+
|
|
14
|
+
return AutomationObject::Driver::NokogiriAdapter::Element.new(driver: self, element: elements.first)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
|
18
|
+
# @param selector_path [String] path to element
|
|
19
|
+
# @return [Array<Element>] elements
|
|
20
|
+
def find_elements(selector_type, selector_path)
|
|
21
|
+
elements = self.get_elements(selector_type, selector_path)
|
|
22
|
+
return elements.map { |element|
|
|
23
|
+
AutomationObject::Driver::NokogiriAdapter::Element.new(driver: self, element: element)
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
|
28
|
+
# @param selector_path [String] path to element
|
|
29
|
+
# @return [Boolean] element exists?
|
|
30
|
+
def exists?(selector_type, selector_path)
|
|
31
|
+
elements = self.get_elements(selector_type, selector_path)
|
|
32
|
+
return (elements.length > 0) ? true : false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
protected
|
|
36
|
+
|
|
37
|
+
def get_elements(selector_type, selector_path)
|
|
38
|
+
case selector_type
|
|
39
|
+
when :xpath
|
|
40
|
+
elements = self.xml.xpath(selector_path)
|
|
41
|
+
when :css
|
|
42
|
+
elements = self.xml.css(selector_path)
|
|
43
|
+
else
|
|
44
|
+
raise ArgumentError, "#{selector_type} selector type not implemented. Only :css, :xpath"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
return elements
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require 'securerandom'
|
|
2
|
+
require_relative 'error'
|
|
3
|
+
|
|
4
|
+
module AutomationObject::Driver::NokogiriAdapter
|
|
5
|
+
#Class for creating/maintaining XML session
|
|
6
|
+
#Trying to replicate some functionality of Selenium like multiple windows, etc...
|
|
7
|
+
class Session
|
|
8
|
+
attr_accessor :window_handles, :window_handle, :current_url, :url_history
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
self.create_session
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create_session
|
|
15
|
+
self.current_url = nil
|
|
16
|
+
self.url_history = {self.window_handle => Array.new}
|
|
17
|
+
self.window_handles = [self.window_handle]
|
|
18
|
+
|
|
19
|
+
@windows_xml = Hash.new
|
|
20
|
+
|
|
21
|
+
return nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def new_window
|
|
25
|
+
self.window_handles.push(SecureRandom.hex(16))
|
|
26
|
+
self.url_history[self.window_handles.last] = Array.new
|
|
27
|
+
self.window_handle = self.window_handles.last
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @return [String] current window handle
|
|
31
|
+
def window_handle
|
|
32
|
+
@window_handle ||= SecureRandom.hex(16)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
#Switch window handles
|
|
36
|
+
# @param handle_value [String] handle value of window to switch to
|
|
37
|
+
def window_handle=(handle_value)
|
|
38
|
+
unless self.window_handles.include?(handle_value)
|
|
39
|
+
raise NoSuchWindowError
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#Array returns nil if length is 0, so no need for if
|
|
43
|
+
self.current_url = self.url_history[handle_value].last
|
|
44
|
+
|
|
45
|
+
@window_handle = handle_value
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def xml(xml = nil)
|
|
49
|
+
@windows_xml[self.window_handle] = xml if xml
|
|
50
|
+
|
|
51
|
+
unless @windows_xml[self.window_handle]
|
|
52
|
+
raise NoSuchDocumentError
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
return @windows_xml[self.window_handle]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Get url, will set xml to current window handle
|
|
59
|
+
# @param url [String] url to get xml for
|
|
60
|
+
# @return [Object] nokogiri object
|
|
61
|
+
def get(url, params = {})
|
|
62
|
+
request(:get, url, params)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Post url, will set xml to current window handle
|
|
66
|
+
# @param url [String] url to get xml for
|
|
67
|
+
# @return [Object] nokogiri object
|
|
68
|
+
def post(url, params = {})
|
|
69
|
+
request(:post, url, params)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Request url, will set xml to current window handle
|
|
73
|
+
# @param url [String] url to get xml for
|
|
74
|
+
# @return [Object] nokogiri object
|
|
75
|
+
def request(type, url, params)
|
|
76
|
+
if url.valid_url? == false and self.current_url == nil
|
|
77
|
+
raise ArgumentError, "Expecting get argument url to be a valid_url?, got #{url}"
|
|
78
|
+
elsif url.valid_url? == false and self.current_url
|
|
79
|
+
url = self.current_url.join_url(url)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
client_resource = RestClient::Resource.new(url, :ssl_version => 'SSLv23_client')
|
|
83
|
+
response = client_resource.send(type)
|
|
84
|
+
|
|
85
|
+
self.current_url = url
|
|
86
|
+
self.url_history[self.window_handle].push(url)
|
|
87
|
+
self.xml(Nokogiri::HTML.parse(response))
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def back
|
|
91
|
+
current_url_index = self.url_history[self.window_handle].index(self.current_url)
|
|
92
|
+
return if current_url_index == 0
|
|
93
|
+
|
|
94
|
+
self.url_history[self.window_handle].delete_at(current_url_index)
|
|
95
|
+
url = self.url_history[self.window_handle].delete_at(current_url_index - 1) #get will insert url anyways
|
|
96
|
+
|
|
97
|
+
self.get(url)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def close
|
|
101
|
+
#Just reset everything if only one "window" is open
|
|
102
|
+
return self.create_session if self.window_handles.length == 1
|
|
103
|
+
|
|
104
|
+
@windows_xml.delete(self.window_handle)
|
|
105
|
+
self.url_history.delete(self.window_handle)
|
|
106
|
+
self.window_handles.delete(self.window_handle)
|
|
107
|
+
self.window_handle = self.window_handles.first
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
#Just reset the session
|
|
111
|
+
def quit
|
|
112
|
+
self.create_session
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require_relative '../element'
|
|
2
|
+
require_relative 'element'
|
|
3
|
+
|
|
4
|
+
module AutomationObject
|
|
5
|
+
module Driver
|
|
6
|
+
module NokogiriAdapter
|
|
7
|
+
#Driver for Nokogiri
|
|
8
|
+
#Conforms to interface and provides Selenium type functionality for XML only functionality
|
|
9
|
+
class Driver
|
|
10
|
+
# Navigates current window to a given url
|
|
11
|
+
# @param url [String] navigate to the following url
|
|
12
|
+
# @return [void]
|
|
13
|
+
def get(url)
|
|
14
|
+
self.adapter.get(url)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Set timeout wait
|
|
18
|
+
# @param timeout [Integer] the timeout in seconds
|
|
19
|
+
# @return [void]
|
|
20
|
+
def set_wait(timeout = nil)
|
|
21
|
+
self.adapter.set_wait(timeout)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @param selector_type [Symbol] selector type (:css, :xpath, etc...)
|
|
25
|
+
# @param selector_path [String] path to element
|
|
26
|
+
# @return [Boolean] exists or not
|
|
27
|
+
def exists?(selector_type, selector_path)
|
|
28
|
+
self.adapter.exists?(selector_type, selector_path)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
|
32
|
+
# @param selector_path [String] path to element
|
|
33
|
+
# @return [AutomationObject::Driver::Element] element
|
|
34
|
+
def find_element(selector_type, selector_path)
|
|
35
|
+
self.adapter.find_element(selector_type, selector_path)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @param selector_type [Symbol] selector type, :css, :xpath, etc...
|
|
39
|
+
# @param selector_path [String] path to element
|
|
40
|
+
# @return [Array<AutomationObject::Driver::Element>] elements
|
|
41
|
+
def find_elements(selector_type, selector_path)
|
|
42
|
+
self.adapter.find_elements(selector_type, selector_path)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#Accept prompt either in browser or mobile
|
|
46
|
+
def accept_prompt
|
|
47
|
+
self.adapter.accept_prompt
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#Dismiss the prompt
|
|
51
|
+
def dismiss_prompt
|
|
52
|
+
self.adapter.dismiss_prompt
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Check if browser, more useful for Appium but can be generic here
|
|
56
|
+
# @return [Boolean] whether or not browser is being used
|
|
57
|
+
def is_browser?
|
|
58
|
+
self.adapter.is_browser?
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#Window Handles
|
|
62
|
+
# @return [Array<String>] array of window handle ids
|
|
63
|
+
def window_handles
|
|
64
|
+
self.adapter.window_handles
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#Current window handle
|
|
68
|
+
# @return [String] handle id
|
|
69
|
+
def window_handle
|
|
70
|
+
self.adapter.window_handle
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#Set current window handle to, will switch windows
|
|
74
|
+
# @param handle_value [String] window handle value
|
|
75
|
+
def window_handle=(handle_value)
|
|
76
|
+
self.adapter.window_handle(handle_value)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Run script in browser to check if document in JS is complete
|
|
80
|
+
# @return [Boolean] document is complete
|
|
81
|
+
def document_complete?
|
|
82
|
+
self.adapter.document_complete?
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Wait till the document is complete
|
|
86
|
+
# @return [void]
|
|
87
|
+
def document_complete_wait
|
|
88
|
+
self.adapter.document_complete_wait
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# @param script [String] JS to run
|
|
92
|
+
# @return [Object, nil]
|
|
93
|
+
def execute_script(script)
|
|
94
|
+
self.adapter.execute_script(script)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Destroy the driver
|
|
98
|
+
def quit
|
|
99
|
+
self.adapter.quit
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|