robotest 1.0.2
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 +7 -0
- data/CONTRIBUTING.md +93 -0
- data/Full_Suite/Gemfile +16 -0
- data/Full_Suite/README.md +12 -0
- data/Full_Suite/Rakefile +9 -0
- data/Full_Suite/conf/account_credentials.yml +2 -0
- data/Full_Suite/libraries/constants.rb +25 -0
- data/Full_Suite/libraries/dsl.rb +52 -0
- data/Full_Suite/locators/testpage.rb +27 -0
- data/Full_Suite/pages/testpage.rb +31 -0
- data/Full_Suite/rake-jobs/rake_jobs.rb +9 -0
- data/Full_Suite/rspec_parallel +6 -0
- data/Full_Suite/spec/spec_helper.rb +84 -0
- data/Full_Suite/spec/test_spec.rb +130 -0
- data/Full_Suite/spec/test_spec_copy.rb +131 -0
- data/Full_Suite/spec/test_spec_copy_2.rb +131 -0
- data/Full_Suite/spec/test_spec_copy_3.rb +131 -0
- data/Full_Suite/test-data/attachments/attachment_test.yml +0 -0
- data/Full_Suite/test-data/credentials/test_credentials.conf +2 -0
- data/Full_Suite/yaml/test.yml +38 -0
- data/Full_Suite/yaml/test_parallel.yml +45 -0
- data/LICENSE +674 -0
- data/README.md +207 -0
- data/Rakefile +1 -0
- data/bin/robotest +5 -0
- data/lib/robotest.rb +258 -0
- data/lib/robotest/RoboTest.png +0 -0
- data/lib/robotest/driver.rb +355 -0
- data/lib/robotest/dsl.rb +69 -0
- data/lib/robotest/locator.rb +204 -0
- data/lib/robotest/multilocator.rb +82 -0
- data/lib/robotest/version.rb +3 -0
- data/lib/robotest/wait.rb +75 -0
- data/lib/tasks/robotest.rake +6 -0
- data/robotest.gemspec +62 -0
- metadata +281 -0
Binary file
|
@@ -0,0 +1,355 @@
|
|
1
|
+
module RoboTest
|
2
|
+
|
3
|
+
class Driver
|
4
|
+
attr_accessor :driver
|
5
|
+
$focus_driver = nil
|
6
|
+
@driver = nil
|
7
|
+
@main_window = nil
|
8
|
+
@click_exception_count = nil
|
9
|
+
@@drivers = []
|
10
|
+
@@drivers_with_names = {}
|
11
|
+
|
12
|
+
def initialize(driver_name = "Driver", browser = $conf['browser'], opts = {})
|
13
|
+
begin
|
14
|
+
start(driver_name,browser, opts)
|
15
|
+
puts "#{driver_name} is initialized"
|
16
|
+
rescue Exception => e
|
17
|
+
puts "#{driver_name} is failed to initialize \nRetrying to initialize #{driver_name}"
|
18
|
+
start(driver_name,browser, opts)
|
19
|
+
puts "#{driver_name} is initialized after an exception"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
##############################
|
24
|
+
# Custom methods of robotest #
|
25
|
+
##############################
|
26
|
+
|
27
|
+
def start(driver_name, browser, opts = {})
|
28
|
+
dimensions = $conf['dimensions']
|
29
|
+
|
30
|
+
if (!dimensions['horizontal'] or !dimensions['vertical'])
|
31
|
+
dimensions = {'horizontal' => 1366, 'vertical' => 768}
|
32
|
+
end
|
33
|
+
|
34
|
+
if (!$conf['implicit_wait'])
|
35
|
+
puts "Specify implicit_wait for your project in the .yml files"
|
36
|
+
$conf['implicit_wait'] = 20
|
37
|
+
end
|
38
|
+
|
39
|
+
prefs = {}
|
40
|
+
if opts.empty?
|
41
|
+
switches = $conf['switches']
|
42
|
+
prefs = $conf['prefs'] if $conf.key?('prefs')
|
43
|
+
elsif opts.key?(:switches)
|
44
|
+
switches = opts[:switches]
|
45
|
+
elsif opts.key?(:prefs)
|
46
|
+
prefs = opts[:prefs]
|
47
|
+
end
|
48
|
+
|
49
|
+
case browser
|
50
|
+
|
51
|
+
when 'firefox', 'ff'
|
52
|
+
options = Selenium::WebDriver::Firefox::Options.new
|
53
|
+
switches.map { |k| options.add_argument(k) }
|
54
|
+
if prefs['profile']
|
55
|
+
if prefs['profile']['name']
|
56
|
+
profile = Selenium::WebDriver::Firefox::Profile.from_name(prefs['profile']['name'])
|
57
|
+
options.profile = profile
|
58
|
+
end
|
59
|
+
end
|
60
|
+
if prefs['download']
|
61
|
+
options.add_preference("browser.download.folderList", 2)
|
62
|
+
options.add_preference("browser.download.dir", "#{Pathname.pwd}/#{prefs['download']['default_directory']}")
|
63
|
+
options.add_preference("browser.download.manager.alertOnEXEOpen", false)
|
64
|
+
options.add_preference("browser.helperApps.neverAsk.saveToDisk" , "application/msword,application/csv,text/csv,image/png ,image/jpeg, application/pdf, text/html,text/plain,application/octet-stream")
|
65
|
+
end
|
66
|
+
caps = Selenium::WebDriver::Remote::Capabilities.firefox(
|
67
|
+
'marionette' => true,
|
68
|
+
'moz:useNonSpecCompliantPointerOrigin' => false,
|
69
|
+
'moz:webdriverClick' => false
|
70
|
+
)
|
71
|
+
@driver = Selenium::WebDriver.for :firefox, :desired_capabilities => caps, options: options
|
72
|
+
|
73
|
+
when 'ie', 'internet_explorer'
|
74
|
+
caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer('ie.ensureCleanSession' => true, 'ie.browserCommandLineSwitches' => 'private')
|
75
|
+
@driver = Selenium::WebDriver.for(:internet_explorer, :desired_capabilities => caps)
|
76
|
+
|
77
|
+
when 'edge'
|
78
|
+
@driver = Selenium::WebDriver.for :edge
|
79
|
+
|
80
|
+
when 'chrome'
|
81
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
82
|
+
# options.add_preference(:download, prefs["download"]) if prefs["download"]
|
83
|
+
if prefs
|
84
|
+
prefs.each do |key, value|
|
85
|
+
options.add_preference(key, value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
if opts.key?(:extension)
|
90
|
+
options.add_extension(opts[:extension])
|
91
|
+
end
|
92
|
+
switches.map { |k| options.add_argument(k) }
|
93
|
+
@driver = Selenium::WebDriver.for(:chrome, options: options)
|
94
|
+
if prefs["download"]
|
95
|
+
enable_chrome_headless_downloads("#{Pathname.pwd}/#{prefs["download"]["default_directory"]}")
|
96
|
+
else
|
97
|
+
enable_chrome_headless_downloads(Pathname.pwd)
|
98
|
+
puts "WARNING: Download path is set to the current root folder if it is not specified in the config file.\nExample: "
|
99
|
+
puts "prefs:
|
100
|
+
download:
|
101
|
+
default_directory: downloads/"
|
102
|
+
end
|
103
|
+
|
104
|
+
when 'safari'
|
105
|
+
@driver = Selenium::WebDriver.for(:safari, opts)
|
106
|
+
|
107
|
+
else
|
108
|
+
raise ArgumentError, "Specify a proper browser while initiating a driver \n \n#{browser.inspect}"
|
109
|
+
end
|
110
|
+
|
111
|
+
target_size = Selenium::WebDriver::Dimension.new(dimensions["horizontal"], dimensions["vertical"])
|
112
|
+
@driver.manage.window.size = target_size
|
113
|
+
@click_exception_count=0
|
114
|
+
@@drivers.push(self)
|
115
|
+
@@drivers_with_names[self] = "#{driver_name}"
|
116
|
+
$focus_driver = self
|
117
|
+
puts "#{driver_name} - #{self}"
|
118
|
+
return self
|
119
|
+
end
|
120
|
+
|
121
|
+
def enable_chrome_headless_downloads(directory)
|
122
|
+
bridge = @driver.send(:bridge)
|
123
|
+
path = '/session/:session_id/chromium/send_command'
|
124
|
+
path[':session_id'] = bridge.session_id
|
125
|
+
bridge.http.call(:post, path, {
|
126
|
+
"cmd" => "Page.setDownloadBehavior",
|
127
|
+
"params" => {
|
128
|
+
"behavior" => "allow",
|
129
|
+
"downloadPath" => directory,
|
130
|
+
}
|
131
|
+
})
|
132
|
+
end
|
133
|
+
|
134
|
+
def get(url)
|
135
|
+
$focus_driver = self
|
136
|
+
@driver.get(url)
|
137
|
+
puts "#{$focus_driver} loaded with - #{url}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def refresh
|
141
|
+
$focus_driver = self
|
142
|
+
navigate.refresh
|
143
|
+
puts "#{$focus_driver} is refreshed"
|
144
|
+
end
|
145
|
+
|
146
|
+
def find_element(locator)
|
147
|
+
$focus_driver = self
|
148
|
+
RoboTest::Wait.wait_for_element(locator)
|
149
|
+
return @driver.find_element(locator.how,locator.what)
|
150
|
+
end
|
151
|
+
|
152
|
+
def find_elements(locator)
|
153
|
+
$focus_driver = self
|
154
|
+
return @driver.find_elements(locator.how,locator.what)
|
155
|
+
end
|
156
|
+
|
157
|
+
def mouse_over(locator,index=1)
|
158
|
+
$focus_driver = self
|
159
|
+
element=find_elements(locator)[index-1]
|
160
|
+
@driver.action.move_to(element).perform
|
161
|
+
puts "mouse over for the element - #{locator.how} => #{locator.what} is done"
|
162
|
+
end
|
163
|
+
|
164
|
+
def mouse
|
165
|
+
$focus_driver = self
|
166
|
+
return @driver.mouse
|
167
|
+
end
|
168
|
+
|
169
|
+
def action
|
170
|
+
$focus_driver = self
|
171
|
+
return @driver.action
|
172
|
+
end
|
173
|
+
|
174
|
+
def move_and_click(locator)
|
175
|
+
$focus_driver = self
|
176
|
+
ele=find_element(locator)
|
177
|
+
@driver.action.move_to(ele).click.perform
|
178
|
+
puts "Mouse over the locator and then click for - #{locator.how} => #{locator.what} is done"
|
179
|
+
end
|
180
|
+
|
181
|
+
def browser
|
182
|
+
$focus_driver = self
|
183
|
+
@driver.browser
|
184
|
+
end
|
185
|
+
|
186
|
+
def capabilities
|
187
|
+
$focus_driver = self
|
188
|
+
@driver.capabilities
|
189
|
+
end
|
190
|
+
|
191
|
+
def current_url
|
192
|
+
$focus_driver = self
|
193
|
+
@driver.current_url
|
194
|
+
end
|
195
|
+
|
196
|
+
def execute_async_script(script, *args)
|
197
|
+
$focus_driver = self
|
198
|
+
@driver.execute_async_script(script, *args)
|
199
|
+
end
|
200
|
+
|
201
|
+
def execute_script(script)
|
202
|
+
$focus_driver = self
|
203
|
+
@driver.execute_script(script)
|
204
|
+
end
|
205
|
+
|
206
|
+
def inspect
|
207
|
+
$focus_driver = self
|
208
|
+
@driver.inspect
|
209
|
+
end
|
210
|
+
|
211
|
+
def manage
|
212
|
+
$focus_driver = self
|
213
|
+
@driver.manage
|
214
|
+
end
|
215
|
+
|
216
|
+
def navigate
|
217
|
+
$focus_driver = self
|
218
|
+
@driver.navigate
|
219
|
+
end
|
220
|
+
|
221
|
+
def page_source
|
222
|
+
$focus_driver = self
|
223
|
+
@driver.page_source
|
224
|
+
end
|
225
|
+
|
226
|
+
def body_text
|
227
|
+
$focus_driver = self
|
228
|
+
@driver.find_element(:css, 'body').text
|
229
|
+
end
|
230
|
+
|
231
|
+
def save_screenshot(file_name = nil)
|
232
|
+
$focus_driver = self
|
233
|
+
file_name = "#{Pathname.pwd}/#{$conf['screenshot_location']}/#{Time.new.strftime("%Y-%m-%d-%H-%M-%S-%L-%N")}.png" if file_name.nil?
|
234
|
+
puts "#{$focus_driver}'s Screenshot saved in this path => #{file_name}"
|
235
|
+
@driver.save_screenshot(file_name)
|
236
|
+
end
|
237
|
+
|
238
|
+
def switch_to_frame(locator)
|
239
|
+
$focus_driver = self
|
240
|
+
@main_window=@driver.window_handle
|
241
|
+
@driver.switch_to.frame(find_element(locator))
|
242
|
+
puts "Switched to iframe - #{locator.how} => #{locator.what} on #{$focus_driver}"
|
243
|
+
return @main_window
|
244
|
+
end
|
245
|
+
|
246
|
+
def switch_to_window(locator=nil)
|
247
|
+
$focus_driver = self
|
248
|
+
@main_window=@driver.window_handle
|
249
|
+
locator.click if locator != nil
|
250
|
+
windows=@driver.window_handles
|
251
|
+
new_window=nil;
|
252
|
+
windows.length.times do |i|
|
253
|
+
if windows[i] != @main_window
|
254
|
+
new_window=windows[i]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
@driver.switch_to.window(new_window)
|
258
|
+
puts "Switched to new window on #{$focus_driver}"
|
259
|
+
return @main_window
|
260
|
+
end
|
261
|
+
|
262
|
+
def scroll_to_locator(locator)
|
263
|
+
$focus_driver = self
|
264
|
+
element = find_element(locator)
|
265
|
+
@driver.execute_script("arguments[0].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'nearest'});",element)
|
266
|
+
puts "Scroll to this locator - #{locator.how} => #{locator.what} on #{$focus_driver}"
|
267
|
+
sleep 1
|
268
|
+
end
|
269
|
+
|
270
|
+
def revert_to(window=nil)
|
271
|
+
$focus_driver = self
|
272
|
+
if window != nil
|
273
|
+
@driver.switch_to.window(window)
|
274
|
+
puts "Switched back to another window - #{window} in #{$focus_driver}"
|
275
|
+
else
|
276
|
+
@driver.switch_to.window(@main_window)
|
277
|
+
puts "Switched back to main window in #{focus_driver}"
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
def close
|
282
|
+
$focus_driver = self
|
283
|
+
@driver.close
|
284
|
+
puts "Closed the browser - #{$focus_driver}"
|
285
|
+
end
|
286
|
+
|
287
|
+
def quit
|
288
|
+
@driver.quit
|
289
|
+
@@drivers.delete(self)
|
290
|
+
$focus_driver = @@drivers[0]
|
291
|
+
puts "Quit the browser - #{$focus_driver}"
|
292
|
+
end
|
293
|
+
|
294
|
+
def quit_all
|
295
|
+
@@drivers.each do |driver|
|
296
|
+
driver.quit if driver != self
|
297
|
+
end
|
298
|
+
self.quit
|
299
|
+
puts "deleted all the browsers"
|
300
|
+
end
|
301
|
+
|
302
|
+
def self.quit_all_drivers
|
303
|
+
@@drivers.each do |driver|
|
304
|
+
driver.quit if driver != self
|
305
|
+
end
|
306
|
+
puts "deleted all the browsers"
|
307
|
+
end
|
308
|
+
|
309
|
+
def self.get_all_drivers
|
310
|
+
return @@drivers_with_names
|
311
|
+
end
|
312
|
+
|
313
|
+
def alert(ok_cancel)
|
314
|
+
sleep 2
|
315
|
+
alert = @driver.switch_to.alert
|
316
|
+
alertMsg=alert.text
|
317
|
+
if ok_cancel
|
318
|
+
alert.accept
|
319
|
+
puts "The alert was accepted in #{$focus_driver} with alert message #{alertMsg}"
|
320
|
+
else
|
321
|
+
alert.dismiss
|
322
|
+
puts "The alert was dismissed in #{$focus_driver} with alert message #{alertMsg}"
|
323
|
+
end
|
324
|
+
return alertMsg
|
325
|
+
end
|
326
|
+
|
327
|
+
def is_alert_present?
|
328
|
+
begin
|
329
|
+
alert = @driver.switch_to.alert
|
330
|
+
alertMsg=alert.text
|
331
|
+
return true
|
332
|
+
rescue Exception => e
|
333
|
+
return false
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def self.switch_to(driver)
|
338
|
+
$focus_driver = driver
|
339
|
+
end
|
340
|
+
|
341
|
+
def drag_and_drop(source_locator, target_locator)
|
342
|
+
source = find_element(source_locator)
|
343
|
+
target = find_element(target_locator)
|
344
|
+
@driver.action.click_and_hold(source).perform
|
345
|
+
@driver.action.move_to(target).release.perform
|
346
|
+
sleep 3
|
347
|
+
puts "In driver #{$focus_driver} - #{source_locator.how} => source_locator.what locator was dragged and moved to this locator #{target_locator.how} => #{target_locator.what}"
|
348
|
+
end
|
349
|
+
|
350
|
+
def on
|
351
|
+
$focus_driver = self
|
352
|
+
yield
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
data/lib/robotest/dsl.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module AllureRSpec
|
2
|
+
module DSL
|
3
|
+
module Example
|
4
|
+
|
5
|
+
@@step_count = 0
|
6
|
+
@@current_example_location = nil
|
7
|
+
|
8
|
+
def step(step, *tags, &block)
|
9
|
+
__increment_step_count
|
10
|
+
metadata[:step_group] ||= {}
|
11
|
+
tags = tags[0].nil? ? {} : tags[0]
|
12
|
+
metadata[:step_group][@@step_count] = tags
|
13
|
+
metadata[:step_name] = step
|
14
|
+
|
15
|
+
suite = __description(metadata[:example_group])
|
16
|
+
test = __description(metadata)
|
17
|
+
begin
|
18
|
+
AllureRubyAdaptorApi::Builder.start_step(suite, test, step)
|
19
|
+
__with_step step, &block
|
20
|
+
__set_step_status('passed')
|
21
|
+
AllureRubyAdaptorApi::Builder.stop_step(suite, test, step)
|
22
|
+
rescue Exception => e
|
23
|
+
__set_step_status('failed')
|
24
|
+
AllureRubyAdaptorApi::Builder.stop_step(suite, test, step, :failed)
|
25
|
+
raise e
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def cstep(step, *tags, &block) # to run even after failure
|
30
|
+
__increment_step_count
|
31
|
+
metadata[:step_group] ||= {}
|
32
|
+
tags = tags[0].nil? ? {} : tags[0]
|
33
|
+
metadata[:step_group][@@step_count] = tags
|
34
|
+
metadata[:step_name] = step
|
35
|
+
|
36
|
+
suite = __description(metadata[:example_group])
|
37
|
+
test = __description(metadata)
|
38
|
+
begin
|
39
|
+
AllureRubyAdaptorApi::Builder.start_step(suite, test, step)
|
40
|
+
__with_step step, &block
|
41
|
+
__set_step_status('passed')
|
42
|
+
AllureRubyAdaptorApi::Builder.stop_step(suite, test, step)
|
43
|
+
rescue Exception => e
|
44
|
+
__set_step_status('failed')
|
45
|
+
AllureRubyAdaptorApi::Builder.stop_step(suite, test, step, :failed)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def __increment_step_count
|
52
|
+
if @@current_example_location != metadata[:location]
|
53
|
+
__reset_step_count
|
54
|
+
@@current_example_location = metadata[:location]
|
55
|
+
else
|
56
|
+
@@step_count += 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def __reset_step_count
|
61
|
+
@@step_count = 0
|
62
|
+
end
|
63
|
+
|
64
|
+
def __set_step_status(status)
|
65
|
+
metadata[:step_group][@@step_count][:status] = status
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
module RoboTest
|
2
|
+
class Locator
|
3
|
+
|
4
|
+
attr_accessor :how
|
5
|
+
attr_accessor :what
|
6
|
+
attr_accessor :options
|
7
|
+
|
8
|
+
def initialize(
|
9
|
+
how,
|
10
|
+
what,
|
11
|
+
options = {
|
12
|
+
"hidden" => false,
|
13
|
+
"ajax_load" => false
|
14
|
+
}
|
15
|
+
)
|
16
|
+
@how = how
|
17
|
+
@what = what
|
18
|
+
@options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def options(driver = $focus_driver)
|
22
|
+
@options
|
23
|
+
end
|
24
|
+
|
25
|
+
##################################################
|
26
|
+
# Methods inherited and overriden from Selenium #
|
27
|
+
##################################################
|
28
|
+
|
29
|
+
def click(driver = $focus_driver)
|
30
|
+
begin
|
31
|
+
driver.find_element(self).click
|
32
|
+
puts "Clicked - #{self.how} => #{self.what}"
|
33
|
+
rescue Exception => e
|
34
|
+
if(e.message.include?("is not clickable at point") || e.message.include?("element not visible") || e.message.include?("stale element reference"))
|
35
|
+
sleep 3
|
36
|
+
locator = Locator.new(@how,@what,@options)
|
37
|
+
locator.click
|
38
|
+
else
|
39
|
+
puts "Not clicked at - #{self.how} => #{self.what}"
|
40
|
+
puts e.message
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def text(driver = $focus_driver)
|
46
|
+
return driver.find_element(self).text
|
47
|
+
end
|
48
|
+
|
49
|
+
def texts(driver = $focus_driver)
|
50
|
+
elements_text = []
|
51
|
+
driver.find_elements(self).each do |element|
|
52
|
+
elements_text.push(element.text)
|
53
|
+
end
|
54
|
+
return elements_text
|
55
|
+
end
|
56
|
+
|
57
|
+
def attribute(name, driver = $focus_driver)
|
58
|
+
driver.find_element(self).attribute(name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def css_value(prop, driver = $focus_driver)
|
62
|
+
driver.find_element(self).css_value(prop)
|
63
|
+
end
|
64
|
+
|
65
|
+
def displayed?(driver = $focus_driver)
|
66
|
+
driver.find_element(self).displayed?
|
67
|
+
end
|
68
|
+
|
69
|
+
def enabled?(driver = $focus_driver)
|
70
|
+
driver.find_element(self).enabled?
|
71
|
+
end
|
72
|
+
|
73
|
+
def is_enabled_with_wait?(timeout=$conf["implicit_wait"], driver = $focus_driver)
|
74
|
+
index=0
|
75
|
+
while driver.find_element(self).enabled? == false
|
76
|
+
sleep 1
|
77
|
+
break if index == timeout
|
78
|
+
index+=1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def hash(driver = $focus_driver)
|
83
|
+
driver.find_element(self).hash
|
84
|
+
end
|
85
|
+
|
86
|
+
def location(driver = $focus_driver)
|
87
|
+
driver.find_element(self).location
|
88
|
+
end
|
89
|
+
|
90
|
+
def location_once_scrolled_into_view(driver = $focus_driver)
|
91
|
+
driver.find_element(self).location_once_scrolled_into_view
|
92
|
+
end
|
93
|
+
|
94
|
+
def property(driver = $focus_driver)
|
95
|
+
driver.find_element(self).property
|
96
|
+
end
|
97
|
+
|
98
|
+
def selected?(driver = $focus_driver)
|
99
|
+
driver.find_element(self).selected?
|
100
|
+
end
|
101
|
+
|
102
|
+
def size(driver = $focus_driver)
|
103
|
+
driver.find_element(self).size
|
104
|
+
end
|
105
|
+
|
106
|
+
def style(prop, driver = $focus_driver)
|
107
|
+
driver.find_element(self).style(prop)
|
108
|
+
end
|
109
|
+
|
110
|
+
def submit(driver = $focus_driver)
|
111
|
+
driver.find_element(self).submit
|
112
|
+
end
|
113
|
+
|
114
|
+
def tag_name(driver = $focus_driver)
|
115
|
+
driver.find_element(self).tag_name
|
116
|
+
end
|
117
|
+
|
118
|
+
def is_present?(driver=$focus_driver)
|
119
|
+
driver.driver.manage.timeouts.implicit_wait = 0
|
120
|
+
begin
|
121
|
+
return driver.driver.find_element(self.how,self.what).displayed?
|
122
|
+
rescue Exception => e
|
123
|
+
driver.driver.manage.timeouts.implicit_wait = $conf["implicit_wait"]
|
124
|
+
return false
|
125
|
+
ensure
|
126
|
+
driver.driver.manage.timeouts.implicit_wait = $conf["implicit_wait"]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def is_present_with_wait?(timeout=$conf["implicit_wait"],driver=$focus_driver)
|
131
|
+
Wait.wait_for_element(self,timeout,driver)
|
132
|
+
is_present?(driver)
|
133
|
+
end
|
134
|
+
|
135
|
+
def is_not_present_with_wait?(timeout=$conf["implicit_wait"],driver=$focus_driver)
|
136
|
+
Wait.wait_for_element_hide(self,timeout,driver)
|
137
|
+
return !is_present?(driver)
|
138
|
+
end
|
139
|
+
|
140
|
+
def click_if_present(driver = $focus_driver)
|
141
|
+
click(driver) if is_present?(driver)
|
142
|
+
end
|
143
|
+
|
144
|
+
def click_if_present_with_wait(timeout = $conf["implicit_wait"], driver = $focus_driver)
|
145
|
+
click(driver) if is_present_with_wait?(timeout, driver)
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_s
|
149
|
+
return "How ===> #{@how}\nWhat ===> #{@what}\nOptions ===> #{@options}"
|
150
|
+
end
|
151
|
+
|
152
|
+
def mouse_over(index = 1, driver = $focus_driver)
|
153
|
+
element = driver.find_elements(self)[index-1]
|
154
|
+
driver.action.move_to(element).perform
|
155
|
+
end
|
156
|
+
|
157
|
+
def move_and_click(driver = $focus_driver)
|
158
|
+
element = driver.find_element(self)
|
159
|
+
driver.action.move_to(element).click.perform
|
160
|
+
end
|
161
|
+
|
162
|
+
def get_element(driver = $focus_driver)
|
163
|
+
driver.find_element(self)
|
164
|
+
end
|
165
|
+
|
166
|
+
################################
|
167
|
+
# Check box methods
|
168
|
+
################################
|
169
|
+
|
170
|
+
def is_checked?(driver = $focus_driver)
|
171
|
+
self.attribute("checked") == "true"
|
172
|
+
end
|
173
|
+
|
174
|
+
def check(driver = $focus_driver)
|
175
|
+
self.click unless self.is_checked?
|
176
|
+
end
|
177
|
+
|
178
|
+
def uncheck(driver = $focus_driver)
|
179
|
+
self.click if self.is_checked?
|
180
|
+
end
|
181
|
+
|
182
|
+
##############################
|
183
|
+
# Text box methods
|
184
|
+
##############################
|
185
|
+
|
186
|
+
def clear(driver = $focus_driver)
|
187
|
+
driver.find_element(self).clear
|
188
|
+
end
|
189
|
+
|
190
|
+
def send_keys(*args)
|
191
|
+
$focus_driver.find_element(self).send_keys(*args)
|
192
|
+
end
|
193
|
+
|
194
|
+
def clear_and_send_keys(*args)
|
195
|
+
clear($focus_driver)
|
196
|
+
send_keys(*args)
|
197
|
+
end
|
198
|
+
|
199
|
+
def get_value(driver = $focus_driver)
|
200
|
+
driver.find_element(self).attribute("value")
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
end
|