Class: SeleniumDSL::SeleniumWebdriver::Script
- Inherits:
-
Proxy
- Object
- Proxy
- SeleniumDSL::SeleniumWebdriver::Script
show all
- Defined in:
- lib/selenium_dsl/selenium_webdriver/script.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(driver) ⇒ Script
Returns a new instance of Script.
10
11
12
13
14
15
16
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 10
def initialize driver
super driver, [:open, :select, :type]
@driver = driver
@timeout_in_seconds = 60
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class SeleniumDSL::Proxy
Instance Attribute Details
#driver ⇒ Object
Returns the value of attribute driver.
6
7
8
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 6
def driver
@driver
end
|
#timeout_in_seconds ⇒ Object
Returns the value of attribute timeout_in_seconds.
8
9
10
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 8
def timeout_in_seconds
@timeout_in_seconds
end
|
Instance Method Details
#click(type, query) ⇒ Object
52
53
54
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 52
def click type, query
find_element(type, query).click
end
|
#condition(block) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 18
def condition block
lambda do |type, query|
element = find_element(type, query)
block.call(element)
end
end
|
#generic_condition(block) ⇒ Object
26
27
28
29
30
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 26
def generic_condition block
lambda do
block.call()
end
end
|
77
78
79
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 77
def input type, query, value
find_element(type, query).send_keys(value)
end
|
#is_text_present(type, query, value) ⇒ Object
48
49
50
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 48
def is_text_present type, query, value
!!(find_element(type, query).text =~ /#{value}/i)
end
|
#select_box(type, query, value) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 56
def select_box type, query, value
select_box = find_element(type, query)
options = select_box.find_elements(:tag_name => "option")
option = nil
if value.kind_of? ::Fixnum
option = options[value]
else
options.each do |current_option|
if current_option.text == value
option = current_option
break
end
end
end
option.click if option
end
|
#wait_for_condition(*params) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/selenium_dsl/selenium_webdriver/script.rb', line 32
def wait_for_condition(*params)
if params.size == 1
condition = params[0]
wait = ::Selenium::WebDriver::Wait.new(:timeout => @timeout_in_seconds)
wait.until { condition.call() }
elsif params.size == 3
type, query, condition = *params
wait = ::Selenium::WebDriver::Wait.new(:timeout => @timeout_in_seconds)
wait.until { condition.call(type, query) }
end
end
|