Module: Capybara::Rc::Actions
Overview
Contributes Selenium-RC action methods to the adapter.
Expects a ‘session` accessor to be provided where it is mixed in.
Instance Method Summary
collapse
Methods included from Extensions
#capybara_find_by_locator, #capybara_has_locator?, #capybara_has_no_locator?
#parse_selenium_rc_locator, #parse_selenium_rc_select_option_locator, #parse_selenium_rc_string_pattern, #parse_selenium_rc_window_locator
Instance Method Details
#attach_file(locator, file_name) ⇒ Object
84
85
86
87
|
# File 'lib/capybara/rc/actions.rb', line 84
def attach_file(locator, file_name)
capybara_element = capybara_find_by_locator(locator)
session.attach_file(capybara_element[:id] || capybara_element[:name], file_name)
end
|
#check(locator) ⇒ Object
30
31
32
|
# File 'lib/capybara/rc/actions.rb', line 30
def check(locator)
capybara_find_by_locator(locator).set(true)
end
|
#click(locator) ⇒ Object
26
27
28
|
# File 'lib/capybara/rc/actions.rb', line 26
def click(locator)
capybara_find_by_locator(locator).click
end
|
#drag_and_drop(draggable_locator, move_by) ⇒ Object
77
78
79
80
81
82
|
# File 'lib/capybara/rc/actions.rb', line 77
def drag_and_drop(draggable_locator, move_by)
draggable = capybara_find_by_locator(draggable_locator).native
delta_x, delta_y = move_by.split(",").map { |int| Kernel.Integer(int) }
session.driver.browser.action.drag_and_drop_by(draggable, delta_x, delta_y).perform
end
|
#drag_and_drop_to_object(draggable_locator, target_locator) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/capybara/rc/actions.rb', line 70
def drag_and_drop_to_object(draggable_locator, target_locator)
draggable = capybara_find_by_locator(draggable_locator)
target = capybara_find_by_locator(target_locator)
draggable.drag_to(target)
end
|
#get_eval(js) ⇒ Object
18
19
20
|
# File 'lib/capybara/rc/actions.rb', line 18
def get_eval(js)
session.execute_script(js)
end
|
#go_back ⇒ Object
89
90
91
|
# File 'lib/capybara/rc/actions.rb', line 89
def go_back
session.execute_script("window.history.back()")
end
|
#mouse_over(locator) ⇒ Object
97
98
99
100
|
# File 'lib/capybara/rc/actions.rb', line 97
def mouse_over(locator)
element = capybara_find_by_locator(locator)
element.hover
end
|
#open(url) ⇒ Object
14
15
16
|
# File 'lib/capybara/rc/actions.rb', line 14
def open(url)
session.visit(url)
end
|
#refresh ⇒ Object
93
94
95
|
# File 'lib/capybara/rc/actions.rb', line 93
def refresh
session.execute_script("window.location.reload()")
end
|
#run_script(js) ⇒ Object
22
23
24
|
# File 'lib/capybara/rc/actions.rb', line 22
def run_script(js)
session.execute_script(js); nil
end
|
#select(select_locator, option_locator) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/capybara/rc/actions.rb', line 38
def select(select_locator, option_locator)
select_element = capybara_find_by_locator(select_locator)
parsed = parse_selenium_rc_select_option_locator(option_locator)
if parsed[:type] == :text
select_element.select(parsed[:string])
return
end
options = select_element.all('option')
option_to_select = nil
case parsed[:type]
when :value
option_to_select = options.detect { |o| o['value'] == parsed[:string] }
else
fail "Don't know how to find a #{parsed[:type].inspect} Selenium option locator with Capybara"
end
if option_to_select
option_to_select.select_option
else
fail Capybara::ElementNotFound, "No option matching #{option_locator.inspect} for select element #{select_locator}"
end
end
|
#type(locator, value) ⇒ Object
60
61
62
63
|
# File 'lib/capybara/rc/actions.rb', line 60
def type(locator, value)
element = capybara_find_by_locator(locator)
element.set(value)
end
|
#type_keys(locator, value) ⇒ Object
65
66
67
68
|
# File 'lib/capybara/rc/actions.rb', line 65
def type_keys(locator, value)
element = capybara_find_by_locator(locator)
element.send_keys(value)
end
|
#uncheck(locator) ⇒ Object
34
35
36
|
# File 'lib/capybara/rc/actions.rb', line 34
def uncheck(locator)
capybara_find_by_locator(locator).set(false)
end
|