xpage 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/xpage.rb +172 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 463202270d34ab2fcb557ffdbfd34517b0ec0d78
|
4
|
+
data.tar.gz: 2946031eed481a85d0b7c9590c6b56a4c13dc53c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4155612c78d5d1e7737ea64019ffe63665c7b5282fb314e48babd118e534001b90eca25159cbee2fc77fd31545abe5646bc715f264a32a3d416f3e9a8ec9523a
|
7
|
+
data.tar.gz: 5bacd0fefbc103981df4ebea6576a5a8740942d00257e97d1063e4b3c771d4bb6a422db8ef9622c7326c4ed1efb7a5a6b32067b9a9fabd56689c6665fde57d12
|
data/lib/xpage.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
require_relative 'retryer.rb'
|
2
|
+
|
3
|
+
class Xpage
|
4
|
+
def self.set_driver(driver)
|
5
|
+
@@driver = driver
|
6
|
+
end
|
7
|
+
|
8
|
+
@@wait = Retryer::Wait.new(:timeout => 20, :interval => 1, :verbose => false)
|
9
|
+
@@retryer = Retryer::Retry.new(max_retries: 5, interval: 1, :verbose => true)
|
10
|
+
|
11
|
+
def get_element(xpath)
|
12
|
+
@@retryer.do(description: 'get_element') {
|
13
|
+
begin
|
14
|
+
@@driver.find_element(:xpath, xpath)
|
15
|
+
rescue Selenium::WebDriver::Error::NoSuchElementError
|
16
|
+
nil # element doesn't exist
|
17
|
+
end
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def click_xpath(xpath)
|
22
|
+
wait_for_xpath_to_display xpath
|
23
|
+
|
24
|
+
@@retryer.do(description: 'click_xpath') {
|
25
|
+
element = get_element xpath
|
26
|
+
element.click
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def clear_xpath(xpath)
|
31
|
+
wait_for_xpath_to_display xpath
|
32
|
+
|
33
|
+
@@retryer.do(description: 'clear_xpath') {
|
34
|
+
element = get_element xpath
|
35
|
+
element.clear
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_xpath_text(xpath)
|
40
|
+
wait_for_xpath_to_exist xpath
|
41
|
+
|
42
|
+
@@retryer.do(description: 'get_xpath_text') {
|
43
|
+
element = get_element xpath
|
44
|
+
element.text
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def move_to_xpath(xpath)
|
49
|
+
wait_for_xpath_to_display xpath
|
50
|
+
|
51
|
+
@@retryer.do(description: 'move_to_xpath') {
|
52
|
+
element = get_element xpath
|
53
|
+
@@driver.mouse.move_to element
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def select_xpath(xpath, option)
|
58
|
+
wait_for_xpath_to_display xpath
|
59
|
+
|
60
|
+
@@retryer.do(description: 'select_xpath') {
|
61
|
+
element = get_element xpath
|
62
|
+
Selenium::WebDriver::Support::Select.new(element).select_by(:text, option)
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def send_keys_xpath(xpath, text)
|
67
|
+
wait_for_xpath_to_display xpath
|
68
|
+
|
69
|
+
@@retryer.do(description: 'send_keys_xpath') {
|
70
|
+
element = get_element xpath
|
71
|
+
element.send_keys text
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def send_keys_slowly_xpath(xpath, text, speed=0.8)
|
76
|
+
wait_for_xpath_to_display xpath
|
77
|
+
|
78
|
+
text.each_char { |c|
|
79
|
+
send_keys_xpath(xpath, c)
|
80
|
+
sleep(speed)
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def set_xpath(xpath, text)
|
85
|
+
clear_xpath xpath
|
86
|
+
send_keys_xpath xpath, text
|
87
|
+
end
|
88
|
+
|
89
|
+
def switch_iframe(xpath)
|
90
|
+
wait_for_xpath_to_display xpath
|
91
|
+
|
92
|
+
@@retryer.do(description: 'switch_iframe') {
|
93
|
+
element = get_element xpath
|
94
|
+
@@driver.switch_to.frame(element)
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def switch_to_first_frame
|
99
|
+
@@retryer.do(description: 'switch_to_first_frame') {
|
100
|
+
@@driver.switch_to.window(@@driver.window_handles.first)
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def switch_to_last_frame
|
105
|
+
@@retryer.do(description: 'switch_to_last_frame') {
|
106
|
+
@@driver.switch_to.window(@@driver.window_handles.last)
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
def text_displayed?(text)
|
111
|
+
elements = nil
|
112
|
+
@@retryer.do(description: 'text_displayed?') {
|
113
|
+
elements = @@driver.find_elements(:xpath, "//*[contains(.,'#{text}')]")
|
114
|
+
}
|
115
|
+
|
116
|
+
elements.each do |element|
|
117
|
+
if element.displayed? == true
|
118
|
+
return true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
return false
|
122
|
+
end
|
123
|
+
|
124
|
+
def wait_for_xpath_to_be_enabled(xpath)
|
125
|
+
@@wait.until { xpath_enabled? xpath }
|
126
|
+
end
|
127
|
+
|
128
|
+
def wait_for_xpath_to_display(xpath)
|
129
|
+
@@wait.until { xpath_displayed? xpath }
|
130
|
+
end
|
131
|
+
|
132
|
+
def wait_for_xpath_to_exist(xpath)
|
133
|
+
@@wait.until { xpath_exists? xpath }
|
134
|
+
end
|
135
|
+
|
136
|
+
def xpath_displayed?(xpath)
|
137
|
+
@@retryer.do(description: 'xpath_displayed?') {
|
138
|
+
element = get_element xpath
|
139
|
+
if element.nil?
|
140
|
+
false
|
141
|
+
else
|
142
|
+
element.displayed?
|
143
|
+
end
|
144
|
+
}
|
145
|
+
end
|
146
|
+
|
147
|
+
def xpath_enabled?(xpath)
|
148
|
+
wait_for_xpath_to_exist xpath
|
149
|
+
|
150
|
+
@@retryer.do(description: 'xpath_enabled?') {
|
151
|
+
element = get_element xpath
|
152
|
+
element.enabled?
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
def xpath_exists?(xpath)
|
157
|
+
element = get_element xpath
|
158
|
+
if element.nil?
|
159
|
+
return false
|
160
|
+
end
|
161
|
+
true
|
162
|
+
end
|
163
|
+
|
164
|
+
def xpath_selected?(xpath)
|
165
|
+
wait_for_xpath_to_exist xpath
|
166
|
+
|
167
|
+
@@retryer.do(description: 'xpath_selected?') {
|
168
|
+
element = get_element xpath
|
169
|
+
element.selected?
|
170
|
+
}
|
171
|
+
end
|
172
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xpage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Barker
|
8
|
+
- Adam Arnold
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-11-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: retryer
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.4.2
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.4.2
|
28
|
+
description: Simple xpath page object implementation
|
29
|
+
email: jarbarker@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/xpage.rb
|
35
|
+
homepage: http://github.com/assert200/xpage
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.5.1
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: xpage
|
59
|
+
test_files: []
|