-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase_page.rb
More file actions
46 lines (40 loc) · 1.27 KB
/
base_page.rb
File metadata and controls
46 lines (40 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require "selenium-webdriver"
module BasePage
DEFAULT_WAIT_TIME = 10
WEBDRIVER_ERRORS = [
Selenium::WebDriver::Error::TimeOutError,
Selenium::WebDriver::Error::NoSuchElementError
].freeze
def explicitly_wait_for_presence(locator = nil, wait_time = DEFAULT_WAIT_TIME)
puts "Explicitly waiting for element: #{locator}"
begin
wait = Selenium::WebDriver::Wait.new(timeout: wait_time)
wait.until do
@driver.find_element(locator)
end
puts 'Found Element'
return true
rescue *WEBDRIVER_ERRORS => e
puts "Element not found after waiting #{wait_time} seconds"
puts e.message
return false
end
end
def wait_then_click(locator, wait_time = DEFAULT_WAIT_TIME)
is_present = explicitly_wait_for_presence(locator, wait_time)
unless is_present
print 'Element not present after wait'
return false
end
begin
element = @driver.find_element(locator)
element.click
puts "Elememnt Clicked"
return true
rescue *WEBDRIVER_ERRORS => e
puts 'Wait Then Click: Error'
puts e.message
return false
end
end
end