tellurium_driver 1.0.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.
- data/tellurium_driver.rb +254 -0
- metadata +47 -0
data/tellurium_driver.rb
ADDED
@@ -0,0 +1,254 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.require(:default)
|
3
|
+
#Provides added functionality to Selenium WebDriver
|
4
|
+
class TelluriumDriver
|
5
|
+
#takes browser name, browser version, hub ip(optional)
|
6
|
+
def initialize(*args)
|
7
|
+
|
8
|
+
browser, version,hub_ip = args
|
9
|
+
@wait = Selenium::WebDriver::Wait.new(:timeout=>120)
|
10
|
+
binding.pry
|
11
|
+
is_ie = browser.include?("internet") && version
|
12
|
+
is_local_chrome = browser.include?("chrome") && version.include?("local")
|
13
|
+
is_local_firefox = browser.include?("firefox")&& version.include?("local")
|
14
|
+
|
15
|
+
if is_local_chrome
|
16
|
+
@driver = Selenium::WebDriver.for :chrome
|
17
|
+
elsif is_local_firefox
|
18
|
+
@driver = Selenium::WebDriver.for :firefox
|
19
|
+
elsif is_ie
|
20
|
+
caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer
|
21
|
+
caps.version = version
|
22
|
+
@driver = Selenium::WebDriver.for(:remote,:desired_capabilities=>caps,:url=> "http://#{hub_ip}:4444/wd/hub")
|
23
|
+
else
|
24
|
+
@driver = Selenium::WebDriver.for(:remote,:desired_capabilities=>browser,:url=> "http://#{hub_ip}:4444/wd/hub")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def driver
|
30
|
+
@driver
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(sym, *args, &block)
|
34
|
+
@driver.send sym,*args,&block
|
35
|
+
end
|
36
|
+
|
37
|
+
def go_to(url)
|
38
|
+
current_name = driver.title
|
39
|
+
driver.get url
|
40
|
+
|
41
|
+
#wait until the current title changes to see that you're at a new url
|
42
|
+
@wait.until { driver.title != current_name }
|
43
|
+
end
|
44
|
+
#takes a url, the symbol of what you wait to exist and the id/name/xpath, whatever of what you want to wait to exist
|
45
|
+
def load_website_and_wait_for_element(url,arg1,id)
|
46
|
+
current_name = driver.title
|
47
|
+
driver.get url
|
48
|
+
|
49
|
+
@wait.until { driver.title != current_name and driver.find_elements(arg1, id).size > 0 }
|
50
|
+
end
|
51
|
+
|
52
|
+
#takes the id you want to click, the id you want to change, and the value of the id you want
|
53
|
+
# to change. (Example, I click start-application and wait for the next dialogue
|
54
|
+
# box to not be hidden)
|
55
|
+
def click_and_wait_to_change(id_to_click,id_to_change,value)
|
56
|
+
element_to_click = driver.find_element(:id, id_to_click)
|
57
|
+
element_to_change = driver.find_element(:id, id_to_change)
|
58
|
+
current_value = element_to_change.attribute(value.to_sym)
|
59
|
+
|
60
|
+
element_to_click.click
|
61
|
+
@wait.until { element_to_change.attribute(value.to_sym) != current_value }
|
62
|
+
end
|
63
|
+
|
64
|
+
def click_selector(sym,id,selector_value)
|
65
|
+
option = Selenium::WebDriver::Support::Select.new(driver.find_element(sym.to_sym,id))
|
66
|
+
option.select_by(:text, selector_value)
|
67
|
+
end
|
68
|
+
|
69
|
+
def click_selector_and_wait(id_to_click,selector_value,id_to_change,value)
|
70
|
+
element_to_change = driver.find_element(:id => id_to_change)
|
71
|
+
current_value = element_to_change.attribute(value.to_sym)
|
72
|
+
|
73
|
+
option = Selenium::WebDriver::Support::Select.new(driver.find_element(:id => id_to_click))
|
74
|
+
option.select_by(:text, selector_value)
|
75
|
+
|
76
|
+
@wait.until { element_to_change.attribute(value.to_sym) != current_value }
|
77
|
+
end
|
78
|
+
|
79
|
+
def wait_for_element(element)
|
80
|
+
@wait.until {
|
81
|
+
bool = false
|
82
|
+
|
83
|
+
if(element.displayed?)
|
84
|
+
bool = true
|
85
|
+
@element = element
|
86
|
+
break
|
87
|
+
end
|
88
|
+
|
89
|
+
bool == true
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def wait_to_disappear(sym,id)
|
94
|
+
@wait.until {
|
95
|
+
element_arr = driver.find_elements(sym,id)
|
96
|
+
element_arr.size > 0 and !element_arr[0].displayed? #wait until the element both exists and is displayed
|
97
|
+
}
|
98
|
+
|
99
|
+
def wait_for_element_to_dissappear(element)
|
100
|
+
@wait.until {
|
101
|
+
begin
|
102
|
+
!element.displayed?
|
103
|
+
rescue
|
104
|
+
break
|
105
|
+
end
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
def wait_to_appear(sym,id)
|
112
|
+
@wait.until {
|
113
|
+
element_arr = driver.find_elements(sym,id)
|
114
|
+
element_arr.size > 0 and element_arr[0].displayed? #wait until the element both exists and is displayed
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def wait_and_click(sym, id)
|
119
|
+
found_element = false
|
120
|
+
|
121
|
+
#if the specified symbol and id point to multiple elements, we want to find the first visible one
|
122
|
+
#and click that
|
123
|
+
@wait.until do
|
124
|
+
driver.find_elements(sym,id).shuffle.each do |element|
|
125
|
+
if element.displayed? and element.enabled?
|
126
|
+
@element=element
|
127
|
+
found_element = true
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
found_element
|
132
|
+
end
|
133
|
+
|
134
|
+
i = 0
|
135
|
+
|
136
|
+
begin
|
137
|
+
@element.click
|
138
|
+
rescue Exception => ex
|
139
|
+
i+=1
|
140
|
+
sleep(1)
|
141
|
+
retry if i<20
|
142
|
+
raise ex
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
def wait_for_element_and_click(element)
|
148
|
+
wait_for_element(element)
|
149
|
+
|
150
|
+
i = 0
|
151
|
+
begin
|
152
|
+
@element.click
|
153
|
+
rescue Exception => ex
|
154
|
+
i+=1
|
155
|
+
sleep(1)
|
156
|
+
retry if i<20
|
157
|
+
raise ex
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
#hovers where the element is and clicks. Workaround for timeout on click that happened with the new update to the showings app
|
163
|
+
def hover_click(*args)
|
164
|
+
if args.size == 1
|
165
|
+
driver.action.click(element).perform
|
166
|
+
else
|
167
|
+
sym,id = args
|
168
|
+
driver.action.click(driver.find_element(sym.to_sym,id)).perform
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
def send_keys(sym,id,value)
|
174
|
+
#self.wait_and_click(sym, id)
|
175
|
+
#driver.action.send_keys(driver.find_element(sym => id),value).perform
|
176
|
+
element = driver.find_element(sym,id)
|
177
|
+
element.click
|
178
|
+
element.send_keys(value)
|
179
|
+
end
|
180
|
+
|
181
|
+
def send_keys_leasing(sym,id,value)
|
182
|
+
self.wait_to_appear(sym,id)
|
183
|
+
self.driver.find_element(sym,id).send_keys(value)
|
184
|
+
end
|
185
|
+
|
186
|
+
#takes the id you want to click, the id you want to exist.(Example, I click start-application and wait for the next dialogue box to exist
|
187
|
+
def click_and_wait_to_exist(*args)
|
188
|
+
case args.size
|
189
|
+
when 2 #takes just two id's
|
190
|
+
id1,id2 = args
|
191
|
+
element_to_click = driver.find_element(:id => id1)
|
192
|
+
element_to_change = driver.find_element(:id => id2)
|
193
|
+
|
194
|
+
element_to_click.click
|
195
|
+
wait_for_element(element_to_change)
|
196
|
+
|
197
|
+
when 4 #takes sym,sym2,id1,id2
|
198
|
+
sym,sym2,id1,id2 = args
|
199
|
+
element_to_click = driver.find_element(sym => id)
|
200
|
+
element_to_change = driver.find_element(sym2 => id2)
|
201
|
+
|
202
|
+
element_to_click.click
|
203
|
+
wait_for_element(element_to_change)
|
204
|
+
|
205
|
+
else
|
206
|
+
error
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def form_fillout(hash) #takes a hash of ID's with values to fillout
|
211
|
+
hash.each do |id,value|
|
212
|
+
self.wait_to_appear(:id,id)
|
213
|
+
self.send_keys(:id,id,value)
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
def form_fillout_editable(selector,hash)
|
219
|
+
hash.each do |id,value|
|
220
|
+
name = "#{selector}\[#{id}\]"
|
221
|
+
driver.execute_script("$('[data-field=\"#{name}\"]').editable('setValue', '#{value}');")
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def form_fillout_selector(hash)
|
226
|
+
hash.each do |id,value|
|
227
|
+
option = Selenium::WebDriver::Support::Select.new(driver.find_element(:id => id))
|
228
|
+
option.select_by(:text,value)
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
def wait_and_hover_click(sym,id)
|
234
|
+
found = false
|
235
|
+
#wait until an element with sym,id is displayed. When it is, hover click it
|
236
|
+
@wait.until {
|
237
|
+
elements = driver.find_elements(sym, id)
|
238
|
+
elements.each do |element|
|
239
|
+
if element.displayed?
|
240
|
+
found = true
|
241
|
+
@element = element
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
found == true
|
246
|
+
}
|
247
|
+
self.hover_click(@element)
|
248
|
+
end
|
249
|
+
|
250
|
+
def close
|
251
|
+
driver.quit
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tellurium_driver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Noah Prince
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Provides useful extra methods for Selenium WebDriver, especially helpful
|
15
|
+
in javascript webapps
|
16
|
+
email: noahprince8@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- tellurium_driver.rb
|
22
|
+
homepage: http://rubygems.org/gems/tellurium_driver
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.25
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Extends the functionality of Selenium WebDriver
|
47
|
+
test_files: []
|