Class: Capybara::Session
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#attach_file(locator, path) ⇒ Object
-
#body ⇒ Object
-
#check(locator) ⇒ Object
-
#choose(locator) ⇒ Object
-
#click(locator) ⇒ Object
-
#click_button(locator) ⇒ Object
-
#click_link(locator) ⇒ Object
-
#current_url ⇒ Object
-
#drag(source_locator, target_locator) ⇒ Object
-
#driver ⇒ Object
-
#evaluate_script(script) ⇒ Object
-
#fill_in(locator, options = {}) ⇒ Object
-
#has_content?(content) ⇒ Boolean
-
#has_css?(path, options = {}) ⇒ Boolean
-
#has_no_content?(content) ⇒ Boolean
-
#has_no_css?(path, options = {}) ⇒ Boolean
-
#has_no_xpath?(path, options = {}) ⇒ Boolean
-
#has_xpath?(path, options = {}) ⇒ Boolean
-
#initialize(mode, app) ⇒ Session
constructor
A new instance of Session.
-
#locate(locator, fail_msg = nil) ⇒ Object
return node identified by locator or raise ElementNotFound(using desc).
-
#response_headers ⇒ Object
-
#save_and_open_page ⇒ Object
-
#select(value, options = {}) ⇒ Object
-
#source ⇒ Object
-
#uncheck(locator) ⇒ Object
-
#visit(path) ⇒ Object
-
#wait_until(timeout = Capybara.default_wait_time) ⇒ Object
-
#within(kind, scope = nil) ⇒ Object
-
#within_fieldset(locator) ⇒ Object
-
#within_table(locator) ⇒ Object
Methods included from Searchable
#all, #find, #find_button, #find_by_id, #find_field, #find_link
Constructor Details
#initialize(mode, app) ⇒ Session
Returns a new instance of Session.
9
10
11
12
|
# File 'lib/capybara/session.rb', line 9
def initialize(mode, app)
@mode = mode
@app = app
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
7
8
9
|
# File 'lib/capybara/session.rb', line 7
def app
@app
end
|
#mode ⇒ Object
Returns the value of attribute mode.
7
8
9
|
# File 'lib/capybara/session.rb', line 7
def mode
@mode
end
|
Instance Method Details
#attach_file(locator, path) ⇒ Object
87
88
89
90
|
# File 'lib/capybara/session.rb', line 87
def attach_file(locator, path)
msg = "cannot attach file, no file field with id, name, or label '#{locator}' found"
locate(XPath.file_field(locator), msg).set(path)
end
|
#body ⇒ Object
92
93
94
|
# File 'lib/capybara/session.rb', line 92
def body
driver.body
end
|
#check(locator) ⇒ Object
72
73
74
75
|
# File 'lib/capybara/session.rb', line 72
def check(locator)
msg = "cannot check field, no checkbox with id, name, or label '#{locator}' found"
locate(XPath.checkbox(locator), msg).set(true)
end
|
#choose(locator) ⇒ Object
67
68
69
70
|
# File 'lib/capybara/session.rb', line 67
def choose(locator)
msg = "cannot choose field, no radio button with id, name, or label '#{locator}' found"
locate(XPath.radio_button(locator), msg).set(true)
end
|
#click(locator) ⇒ Object
41
42
43
44
|
# File 'lib/capybara/session.rb', line 41
def click(locator)
msg = "no link or button '#{locator}' found"
locate(XPath.link(locator).button(locator), msg).click
end
|
51
52
53
54
|
# File 'lib/capybara/session.rb', line 51
def click_button(locator)
msg = "no button with value or id or text '#{locator}' found"
locate(XPath.button(locator)).click
end
|
#click_link(locator) ⇒ Object
46
47
48
49
|
# File 'lib/capybara/session.rb', line 46
def click_link(locator)
msg = "no link with title, id or text '#{locator}' found"
locate(XPath.link(locator), msg).click
end
|
#current_url ⇒ Object
29
30
31
|
# File 'lib/capybara/session.rb', line 29
def current_url
driver.current_url
end
|
#drag(source_locator, target_locator) ⇒ Object
56
57
58
59
60
|
# File 'lib/capybara/session.rb', line 56
def drag(source_locator, target_locator)
source = locate(source_locator, "drag source '#{source_locator}' not found on page")
target = locate(target_locator, "drag target '#{target_locator}' not found on page")
source.drag_to(target)
end
|
#evaluate_script(script) ⇒ Object
182
183
184
|
# File 'lib/capybara/session.rb', line 182
def evaluate_script(script)
driver.evaluate_script(script)
end
|
#fill_in(locator, options = {}) ⇒ Object
62
63
64
65
|
# File 'lib/capybara/session.rb', line 62
def fill_in(locator, options={})
msg = "cannot fill in, no text field, text area or password field with id, name, or label '#{locator}' found"
locate(XPath.fillable_field(locator), msg).set(options[:with])
end
|
#has_content?(content) ⇒ Boolean
157
158
159
|
# File 'lib/capybara/session.rb', line 157
def has_content?(content)
has_xpath?(XPath.content(content))
end
|
#has_css?(path, options = {}) ⇒ Boolean
149
150
151
|
# File 'lib/capybara/session.rb', line 149
def has_css?(path, options={})
has_xpath?(XPath.from_css(path), options)
end
|
#has_no_content?(content) ⇒ Boolean
161
162
163
|
# File 'lib/capybara/session.rb', line 161
def has_no_content?(content)
has_no_xpath?(XPath.content(content))
end
|
#has_no_css?(path, options = {}) ⇒ Boolean
153
154
155
|
# File 'lib/capybara/session.rb', line 153
def has_no_css?(path, options={})
has_no_xpath?(XPath.from_css(path), options)
end
|
#has_no_xpath?(path, options = {}) ⇒ Boolean
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/capybara/session.rb', line 135
def has_no_xpath?(path, options={})
wait_conditionally_until do
results = all(path, options)
if options[:count]
results.size != options[:count]
else
results.empty?
end
end
rescue Capybara::TimeoutError
return false
end
|
#has_xpath?(path, options = {}) ⇒ Boolean
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/capybara/session.rb', line 121
def has_xpath?(path, options={})
wait_conditionally_until do
results = all(path, options)
if options[:count]
results.size == options[:count]
else
results.size > 0
end
end
rescue Capybara::TimeoutError
return false
end
|
#locate(locator, fail_msg = nil) ⇒ Object
return node identified by locator or raise ElementNotFound(using desc)
171
172
173
174
175
176
|
# File 'lib/capybara/session.rb', line 171
def locate(locator, fail_msg = nil)
node = wait_conditionally_until { find(locator) }
ensure
raise Capybara::ElementNotFound, fail_msg || "Unable to locate '#{locator}'" unless node
return node
end
|
33
34
35
|
# File 'lib/capybara/session.rb', line 33
def
driver.
end
|
#save_and_open_page ⇒ Object
#select(value, options = {}) ⇒ Object
82
83
84
85
|
# File 'lib/capybara/session.rb', line 82
def select(value, options={})
msg = "cannot select option, no select box with id, name, or label '#{options[:from]}' found"
locate(XPath.select(options[:from]), msg).select(value)
end
|
#source ⇒ Object
96
97
98
|
# File 'lib/capybara/session.rb', line 96
def source
driver.source
end
|
#uncheck(locator) ⇒ Object
77
78
79
80
|
# File 'lib/capybara/session.rb', line 77
def uncheck(locator)
msg = "cannot uncheck field, no checkbox with id, name, or label '#{locator}' found"
locate(XPath.checkbox(locator), msg).set(false)
end
|
#visit(path) ⇒ Object
37
38
39
|
# File 'lib/capybara/session.rb', line 37
def visit(path)
driver.visit(path)
end
|
#wait_until(timeout = Capybara.default_wait_time) ⇒ Object
#within(kind, scope = nil) ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/capybara/session.rb', line 100
def within(kind, scope=nil)
kind, scope = Capybara.default_selector, kind unless scope
scope = XPath.from_css(scope) if kind == :css
locate(scope, "scope '#{scope}' not found on page")
scopes.push(scope)
yield
scopes.pop
end
|
#within_fieldset(locator) ⇒ Object
109
110
111
112
113
|
# File 'lib/capybara/session.rb', line 109
def within_fieldset(locator)
within XPath.fieldset(locator) do
yield
end
end
|
#within_table(locator) ⇒ Object
115
116
117
118
119
|
# File 'lib/capybara/session.rb', line 115
def within_table(locator)
within XPath.table(locator) do
yield
end
end
|