capybara 0.3.9 → 0.4.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +43 -1
- data/README.rdoc +168 -98
- data/lib/capybara.rb +77 -15
- data/lib/capybara/driver/base.rb +21 -16
- data/lib/capybara/driver/celerity_driver.rb +39 -41
- data/lib/capybara/driver/culerity_driver.rb +2 -1
- data/lib/capybara/driver/node.rb +66 -0
- data/lib/capybara/driver/rack_test_driver.rb +66 -67
- data/lib/capybara/driver/selenium_driver.rb +43 -47
- data/lib/capybara/dsl.rb +44 -6
- data/lib/capybara/node.rb +185 -24
- data/lib/capybara/node/actions.rb +170 -0
- data/lib/capybara/node/finders.rb +150 -0
- data/lib/capybara/node/matchers.rb +360 -0
- data/lib/capybara/rails.rb +1 -0
- data/lib/capybara/selector.rb +52 -0
- data/lib/capybara/server.rb +68 -87
- data/lib/capybara/session.rb +221 -207
- data/lib/capybara/spec/driver.rb +45 -35
- data/lib/capybara/spec/public/test.js +1 -1
- data/lib/capybara/spec/session.rb +28 -53
- data/lib/capybara/spec/session/all_spec.rb +7 -3
- data/lib/capybara/spec/session/check_spec.rb +50 -52
- data/lib/capybara/spec/session/click_button_spec.rb +9 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +37 -0
- data/lib/capybara/spec/session/current_url_spec.rb +7 -0
- data/lib/capybara/spec/session/find_button_spec.rb +4 -2
- data/lib/capybara/spec/session/find_by_id_spec.rb +4 -2
- data/lib/capybara/spec/session/find_field_spec.rb +7 -3
- data/lib/capybara/spec/session/find_link_spec.rb +5 -3
- data/lib/capybara/spec/session/find_spec.rb +71 -6
- data/lib/capybara/spec/session/has_field_spec.rb +1 -1
- data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +4 -4
- data/lib/capybara/spec/session/javascript.rb +25 -5
- data/lib/capybara/spec/session/select_spec.rb +16 -2
- data/lib/capybara/spec/session/unselect_spec.rb +8 -1
- data/lib/capybara/spec/session/within_spec.rb +5 -5
- data/lib/capybara/spec/views/form.erb +65 -1
- data/lib/capybara/spec/views/popup_one.erb +8 -0
- data/lib/capybara/spec/views/popup_two.erb +8 -0
- data/lib/capybara/spec/views/with_html.erb +5 -0
- data/lib/capybara/spec/views/within_popups.erb +25 -0
- data/lib/capybara/{save_and_open_page.rb → util/save_and_open_page.rb} +3 -3
- data/lib/capybara/util/timeout.rb +27 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/capybara_spec.rb +18 -8
- data/spec/driver/celerity_driver_spec.rb +10 -14
- data/spec/driver/culerity_driver_spec.rb +4 -3
- data/spec/driver/rack_test_driver_spec.rb +39 -2
- data/spec/driver/remote_culerity_driver_spec.rb +5 -7
- data/spec/driver/remote_selenium_driver_spec.rb +7 -10
- data/spec/driver/selenium_driver_spec.rb +3 -2
- data/spec/dsl_spec.rb +5 -14
- data/spec/save_and_open_page_spec.rb +19 -19
- data/spec/server_spec.rb +22 -10
- data/spec/session/celerity_session_spec.rb +17 -21
- data/spec/session/culerity_session_spec.rb +3 -3
- data/spec/session/rack_test_session_spec.rb +2 -2
- data/spec/session/selenium_session_spec.rb +2 -2
- data/spec/spec_helper.rb +27 -6
- data/spec/{wait_until_spec.rb → timeout_spec.rb} +14 -14
- metadata +88 -46
- data/lib/capybara/searchable.rb +0 -54
- data/lib/capybara/spec/session/click_spec.rb +0 -24
- data/lib/capybara/spec/session/locate_spec.rb +0 -65
- data/lib/capybara/wait_until.rb +0 -28
- data/lib/capybara/xpath.rb +0 -179
- data/spec/searchable_spec.rb +0 -66
- data/spec/xpath_spec.rb +0 -180
data/lib/capybara/searchable.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module Capybara
|
2
|
-
module Searchable
|
3
|
-
def find(*args)
|
4
|
-
all(*args).first
|
5
|
-
end
|
6
|
-
|
7
|
-
def find_field(locator)
|
8
|
-
find(:xpath, XPath.field(locator))
|
9
|
-
end
|
10
|
-
alias_method :field_labeled, :find_field
|
11
|
-
|
12
|
-
def find_link(locator)
|
13
|
-
find(:xpath, XPath.link(locator))
|
14
|
-
end
|
15
|
-
|
16
|
-
def find_button(locator)
|
17
|
-
find(:xpath, XPath.button(locator))
|
18
|
-
end
|
19
|
-
|
20
|
-
def find_by_id(id)
|
21
|
-
find(:css, "##{id}")
|
22
|
-
end
|
23
|
-
|
24
|
-
def all(*args)
|
25
|
-
options = if args.last.is_a?(Hash) then args.pop else {} end
|
26
|
-
if args[1].nil?
|
27
|
-
kind, locator = Capybara.default_selector, args.first
|
28
|
-
else
|
29
|
-
kind, locator = args
|
30
|
-
end
|
31
|
-
locator = XPath.from_css(locator) if kind == :css
|
32
|
-
|
33
|
-
results = all_unfiltered(locator)
|
34
|
-
|
35
|
-
if options[:text]
|
36
|
-
options[:text] = Regexp.escape(options[:text]) unless options[:text].kind_of?(Regexp)
|
37
|
-
results = results.select { |n| n.text.match(options[:text]) }
|
38
|
-
end
|
39
|
-
|
40
|
-
if options[:visible] or Capybara.ignore_hidden_elements
|
41
|
-
results = results.select { |n| n.visible? }
|
42
|
-
end
|
43
|
-
|
44
|
-
results
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def all_unfiltered(locator)
|
50
|
-
raise "Must be overridden"
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
shared_examples_for "click" do
|
2
|
-
describe '#click' do
|
3
|
-
it "should click on a link" do
|
4
|
-
@session.visit('/with_html')
|
5
|
-
@session.click('labore')
|
6
|
-
@session.body.should include('Bar')
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should click on a button" do
|
10
|
-
@session.visit('/form')
|
11
|
-
@session.click('awe123')
|
12
|
-
extract_results(@session)['first_name'].should == 'John'
|
13
|
-
end
|
14
|
-
|
15
|
-
context "with a locator that doesn't exist" do
|
16
|
-
it "should raise an error" do
|
17
|
-
@session.visit('/with_html')
|
18
|
-
running do
|
19
|
-
@session.click('does not exist')
|
20
|
-
end.should raise_error(Capybara::ElementNotFound)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
shared_examples_for "locate" do
|
2
|
-
describe '#locate' do
|
3
|
-
before do
|
4
|
-
@session.visit('/with_html')
|
5
|
-
end
|
6
|
-
|
7
|
-
it "should find the first element using the given locator" do
|
8
|
-
@session.locate('//h1').text.should == 'This is a test'
|
9
|
-
@session.locate("//input[@id='test_field']")[:value].should == 'monkey'
|
10
|
-
end
|
11
|
-
|
12
|
-
context "with css selectors" do
|
13
|
-
it "should find the first element using the given locator" do
|
14
|
-
@session.locate(:css, 'h1').text.should == 'This is a test'
|
15
|
-
@session.locate(:css, "input[id='test_field']")[:value].should == 'monkey'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "with xpath selectors" do
|
20
|
-
it "should find the first element using the given locator" do
|
21
|
-
@session.locate(:xpath, '//h1').text.should == 'This is a test'
|
22
|
-
@session.locate(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "with css as default selector" do
|
27
|
-
before { Capybara.default_selector = :css }
|
28
|
-
it "should find the first element using the given locator" do
|
29
|
-
@session.locate('h1').text.should == 'This is a test'
|
30
|
-
@session.locate("input[id='test_field']")[:value].should == 'monkey'
|
31
|
-
end
|
32
|
-
after { Capybara.default_selector = :xpath }
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should raise ElementNotFound with specified fail message if nothing was found" do
|
36
|
-
running do
|
37
|
-
@session.locate(:xpath, '//div[@id="nosuchthing"]', 'arghh').should be_nil
|
38
|
-
end.should raise_error(Capybara::ElementNotFound, "arghh")
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should raise ElementNotFound with a useful default message if nothing was found" do
|
42
|
-
running do
|
43
|
-
@session.locate(:xpath, '//div[@id="nosuchthing"]').should be_nil
|
44
|
-
end.should raise_error(Capybara::ElementNotFound, "Unable to locate '//div[@id=\"nosuchthing\"]'")
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should accept an XPath instance and respect the order of paths" do
|
48
|
-
@session.visit('/form')
|
49
|
-
@xpath = Capybara::XPath.text_field('Name')
|
50
|
-
@session.locate(@xpath).value.should == 'John Smith'
|
51
|
-
end
|
52
|
-
|
53
|
-
context "within a scope" do
|
54
|
-
before do
|
55
|
-
@session.visit('/with_scope')
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should find the first element using the given locator" do
|
59
|
-
@session.within(:xpath, "//div[@id='for_bar']") do
|
60
|
-
@session.locate('//li').text.should =~ /With Simple HTML/
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/lib/capybara/wait_until.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Capybara
|
2
|
-
#Provides timeout similar to standard library Timeout, but avoids threads
|
3
|
-
class WaitUntil
|
4
|
-
|
5
|
-
class << self
|
6
|
-
|
7
|
-
def timeout(seconds = 1, driver = nil, &block)
|
8
|
-
start_time = Time.now
|
9
|
-
|
10
|
-
result = nil
|
11
|
-
|
12
|
-
until result
|
13
|
-
return result if result = yield
|
14
|
-
|
15
|
-
delay = seconds - (Time.now - start_time)
|
16
|
-
if delay <= 0
|
17
|
-
raise TimeoutError
|
18
|
-
end
|
19
|
-
|
20
|
-
driver && driver.wait_until(delay)
|
21
|
-
|
22
|
-
sleep(0.05)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/capybara/xpath.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
module Capybara
|
2
|
-
# this is a class for generating XPath queries, use it like this:
|
3
|
-
# Xpath.text_field('foo').link('blah').to_s
|
4
|
-
# this will generate an XPath that matches either a text field or a link
|
5
|
-
class XPath
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def escape(string)
|
9
|
-
if string.include?("'")
|
10
|
-
string = string.split("'", -1).map do |substr|
|
11
|
-
"'#{substr}'"
|
12
|
-
end.join(%q{,"'",})
|
13
|
-
"concat(#{string})"
|
14
|
-
else
|
15
|
-
"'#{string}'"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def wrap(path)
|
20
|
-
if path.is_a?(self)
|
21
|
-
path
|
22
|
-
else
|
23
|
-
new(path.to_s)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def respond_to?(method)
|
28
|
-
new.respond_to?(method)
|
29
|
-
end
|
30
|
-
|
31
|
-
def method_missing(*args)
|
32
|
-
new.send(*args)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
attr_reader :paths
|
37
|
-
|
38
|
-
def initialize(*paths)
|
39
|
-
@paths = paths
|
40
|
-
end
|
41
|
-
|
42
|
-
def scope(scope)
|
43
|
-
XPath.new(*paths.map { |p| scope + p })
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_s
|
47
|
-
@paths.join(' | ')
|
48
|
-
end
|
49
|
-
|
50
|
-
def append(path)
|
51
|
-
XPath.new(*[@paths, XPath.wrap(path).paths].flatten)
|
52
|
-
end
|
53
|
-
|
54
|
-
def prepend(path)
|
55
|
-
XPath.new(*[XPath.wrap(path).paths, @paths].flatten)
|
56
|
-
end
|
57
|
-
|
58
|
-
def from_css(css)
|
59
|
-
append(Nokogiri::CSS.xpath_for(css).first)
|
60
|
-
end
|
61
|
-
alias_method :for_css, :from_css
|
62
|
-
|
63
|
-
def field(locator, options={})
|
64
|
-
if options[:with]
|
65
|
-
fillable_field(locator, options)
|
66
|
-
else
|
67
|
-
xpath = fillable_field(locator)
|
68
|
-
xpath = xpath.input_field(:file, locator, options)
|
69
|
-
xpath = xpath.checkbox(locator, options)
|
70
|
-
xpath = xpath.radio_button(locator, options)
|
71
|
-
xpath.select(locator, options)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def fillable_field(locator, options={})
|
76
|
-
text_area(locator, options).text_field(locator, options)
|
77
|
-
end
|
78
|
-
|
79
|
-
def content(locator)
|
80
|
-
append("/descendant-or-self::*[contains(normalize-space(.),#{s(locator)})]")
|
81
|
-
end
|
82
|
-
|
83
|
-
def table(locator, options={})
|
84
|
-
conditions = ""
|
85
|
-
if options[:rows]
|
86
|
-
row_conditions = options[:rows].map do |row|
|
87
|
-
row = row.map { |column| "*[self::td or self::th][text()=#{s(column)}]" }.join(sibling)
|
88
|
-
"tr[./#{row}]"
|
89
|
-
end.join(sibling)
|
90
|
-
conditions << "[.//#{row_conditions}]"
|
91
|
-
end
|
92
|
-
append("//table[@id=#{s(locator)} or contains(caption,#{s(locator)})]#{conditions}")
|
93
|
-
end
|
94
|
-
|
95
|
-
def fieldset(locator)
|
96
|
-
append("//fieldset[@id=#{s(locator)} or contains(legend,#{s(locator)})]")
|
97
|
-
end
|
98
|
-
|
99
|
-
def link(locator)
|
100
|
-
xpath = append("//a[@href][@id=#{s(locator)} or contains(.,#{s(locator)}) or contains(@title,#{s(locator)}) or img[contains(@alt,#{s(locator)})]]")
|
101
|
-
xpath.prepend("//a[@href][text()=#{s(locator)} or @title=#{s(locator)} or img[@alt=#{s(locator)}]]")
|
102
|
-
end
|
103
|
-
|
104
|
-
def button(locator)
|
105
|
-
xpath = append("//input[@type='submit' or @type='image' or @type='button'][@id=#{s(locator)} or contains(@value,#{s(locator)})]")
|
106
|
-
xpath = xpath.append("//button[@id=#{s(locator)} or contains(@value,#{s(locator)}) or contains(.,#{s(locator)})]")
|
107
|
-
xpath = xpath.prepend("//input[@type='submit' or @type='image' or @type='button'][@value=#{s(locator)}]")
|
108
|
-
xpath = xpath.prepend("//input[@type='image'][@alt=#{s(locator)} or contains(@alt,#{s(locator)})]")
|
109
|
-
xpath = xpath.prepend("//button[@value=#{s(locator)} or text()=#{s(locator)}]")
|
110
|
-
end
|
111
|
-
|
112
|
-
def text_field(locator, options={})
|
113
|
-
options = options.merge(:value => options[:with]) if options.has_key?(:with)
|
114
|
-
add_field(locator, "//input[not(@type) or (@type!='radio' and @type!='checkbox' and @type!='hidden')]", options)
|
115
|
-
end
|
116
|
-
|
117
|
-
def text_area(locator, options={})
|
118
|
-
options = options.merge(:text => options[:with]) if options.has_key?(:with)
|
119
|
-
add_field(locator, "//textarea", options)
|
120
|
-
end
|
121
|
-
|
122
|
-
def select(locator, options={})
|
123
|
-
add_field(locator, "//select", options)
|
124
|
-
end
|
125
|
-
|
126
|
-
def checkbox(locator, options={})
|
127
|
-
input_field(:checkbox, locator, options)
|
128
|
-
end
|
129
|
-
|
130
|
-
def radio_button(locator, options={})
|
131
|
-
input_field(:radio, locator, options)
|
132
|
-
end
|
133
|
-
|
134
|
-
def file_field(locator, options={})
|
135
|
-
input_field(:file, locator, options)
|
136
|
-
end
|
137
|
-
|
138
|
-
protected
|
139
|
-
|
140
|
-
def input_field(type, locator, options={})
|
141
|
-
options = options.merge(:value => options[:with]) if options.has_key?(:with)
|
142
|
-
add_field(locator, "//input[@type='#{type}']", options)
|
143
|
-
end
|
144
|
-
|
145
|
-
# place this between to nodes to indicate that they should be siblings
|
146
|
-
def sibling
|
147
|
-
'/following-sibling::*[1]/self::'
|
148
|
-
end
|
149
|
-
|
150
|
-
def add_field(locator, field, options={})
|
151
|
-
postfix = extract_postfix(options)
|
152
|
-
xpath = append("#{field}[@id=#{s(locator)}]#{postfix}")
|
153
|
-
xpath = xpath.append("#{field}[@name=#{s(locator)}]#{postfix}")
|
154
|
-
xpath = xpath.append("#{field}[@id=//label[contains(.,#{s(locator)})]/@for]#{postfix}")
|
155
|
-
xpath = xpath.append("//label[contains(.,#{s(locator)})]#{field}#{postfix}")
|
156
|
-
xpath.prepend("#{field}[@id=//label[text()=#{s(locator)}]/@for]#{postfix}")
|
157
|
-
end
|
158
|
-
|
159
|
-
def extract_postfix(options)
|
160
|
-
options.inject("") do |postfix, (key, value)|
|
161
|
-
case key
|
162
|
-
when :value then postfix += "[@value=#{s(value)}]"
|
163
|
-
when :text then postfix += "[text()=#{s(value)}]"
|
164
|
-
when :checked then postfix += "[@checked]"
|
165
|
-
when :unchecked then postfix += "[not(@checked)]"
|
166
|
-
when :options then postfix += value.map { |o| "[.//option/text()=#{s(o)}]" }.join
|
167
|
-
when :selected then postfix += [value].flatten.map { |o| "[.//option[@selected]/text()=#{s(o)}]" }.join
|
168
|
-
end
|
169
|
-
postfix
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# Sanitize a String for putting it into an xpath query
|
174
|
-
def s(string)
|
175
|
-
XPath.escape(string)
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
end
|
data/spec/searchable_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
module Capybara
|
4
|
-
|
5
|
-
describe Searchable do
|
6
|
-
class Klass
|
7
|
-
include Searchable
|
8
|
-
|
9
|
-
def all_unfiltered(locator, options = {})
|
10
|
-
[]
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#all" do
|
16
|
-
before do
|
17
|
-
@searchable = Klass.new
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return unfiltered list without options" do
|
21
|
-
node1 = stub(Node)
|
22
|
-
node2 = stub(Node)
|
23
|
-
@searchable.should_receive(:all_unfiltered).with('//x').and_return([node1, node2])
|
24
|
-
@searchable.all('//x').should == [node1, node2]
|
25
|
-
end
|
26
|
-
|
27
|
-
context "with :text filter" do
|
28
|
-
before do
|
29
|
-
@node1 = stub(Node, :text => 'node one text (with parens)')
|
30
|
-
@node2 = stub(Node, :text => 'node two text [-]')
|
31
|
-
@searchable.stub(:all_unfiltered).and_return([@node1, @node2])
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should accept regular expression" do
|
35
|
-
@searchable.all('//x', :text => /node one/).should == [@node1]
|
36
|
-
@searchable.all('//x', :text => /node two/).should == [@node2]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should accept text" do
|
40
|
-
@searchable.all('//x', :text => "node one").should == [@node1]
|
41
|
-
@searchable.all('//x', :text => "node two").should == [@node2]
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should allow Regexp reserved words in text" do
|
45
|
-
@searchable.all('//x', :text => "node one text (with parens)").should == [@node1]
|
46
|
-
@searchable.all('//x', :text => "node two text [-]").should == [@node2]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "with :visible filter" do
|
51
|
-
before do
|
52
|
-
@visible_node = stub(Node, :visible? => true)
|
53
|
-
@hidden_node = stub(Node, :visible? => false)
|
54
|
-
@searchable.stub(:all_unfiltered).and_return([@visible_node, @hidden_node])
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should filter out hidden nodes" do
|
58
|
-
@searchable.all('//x', :visible => true).should == [@visible_node]
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end #all
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
data/spec/xpath_spec.rb
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
describe Capybara::XPath do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@driver = Capybara::Driver::RackTest.new(TestApp)
|
7
|
-
@driver.visit('/form')
|
8
|
-
@xpath = Capybara::XPath.new
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should proxy any class method calls to a new instance" do
|
12
|
-
@query = Capybara::XPath.fillable_field('First Name').to_s
|
13
|
-
@driver.find(@query).first.value.should == 'John'
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should respond to instance methods at the class level" do
|
17
|
-
Capybara::XPath.should respond_to(:fillable_field)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '.wrap' do
|
21
|
-
it "should return an XPath unmodified" do
|
22
|
-
Capybara::XPath.wrap(@xpath).should == @xpath
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should wrap a string in an xpath object" do
|
26
|
-
@xpath = Capybara::XPath.wrap('//foo/bar')
|
27
|
-
@xpath.should be_an_instance_of(Capybara::XPath)
|
28
|
-
@xpath.paths.should == ['//foo/bar']
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#append' do
|
33
|
-
it "should append an XPath's paths" do
|
34
|
-
@xpath = Capybara::XPath.wrap('//test')
|
35
|
-
@xpath = @xpath.append(Capybara::XPath.wrap('//foo/bar'))
|
36
|
-
@xpath.paths.should == ['//test', '//foo/bar']
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should append an String as a new path" do
|
40
|
-
@xpath = Capybara::XPath.wrap('//test')
|
41
|
-
@xpath = @xpath.append('//foo/bar')
|
42
|
-
@xpath.paths.should == ['//test', '//foo/bar']
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#prepend' do
|
47
|
-
it "should prepend an XPath's paths" do
|
48
|
-
@xpath = Capybara::XPath.wrap('//test')
|
49
|
-
@xpath = @xpath.prepend(Capybara::XPath.wrap('//foo/bar'))
|
50
|
-
@xpath.paths.should == ['//foo/bar', '//test']
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should prepend an String as a new path" do
|
54
|
-
@xpath = Capybara::XPath.wrap('//test')
|
55
|
-
@xpath = @xpath.prepend('//foo/bar')
|
56
|
-
@xpath.paths.should == ['//foo/bar', '//test']
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#scope' do
|
61
|
-
it "should prepend the given scope to all paths" do
|
62
|
-
@xpath = Capybara::XPath.new('//foo/bar', '//test[@blah=foo]').scope('//quox')
|
63
|
-
@xpath.paths.should include('//quox//foo/bar', '//quox//test[@blah=foo]')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#field' do
|
68
|
-
it "should find any field by id or label" do
|
69
|
-
@query = @xpath.field('First Name').to_s
|
70
|
-
@driver.find(@query).first.value.should == 'John'
|
71
|
-
@query = @xpath.field('Password').to_s
|
72
|
-
@driver.find(@query).first.value.should == 'seeekrit'
|
73
|
-
@query = @xpath.field('Description').to_s
|
74
|
-
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
75
|
-
@query = @xpath.field('Document').to_s
|
76
|
-
@driver.find(@query).first[:name].should == 'form[document]'
|
77
|
-
@query = @xpath.field('Cat').to_s
|
78
|
-
@driver.find(@query).first.value.should == 'cat'
|
79
|
-
@query = @xpath.field('Male').to_s
|
80
|
-
@driver.find(@query).first.value.should == 'male'
|
81
|
-
@query = @xpath.field('Region').to_s
|
82
|
-
@driver.find(@query).first[:name].should == 'form[region]'
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should be chainable" do
|
86
|
-
@query = @xpath.field('First Name').button('Click me!').to_s
|
87
|
-
@driver.find(@query).first.value.should == 'John'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#fillable_field' do
|
92
|
-
it "should find a text field, password field, or text area by id or label" do
|
93
|
-
@query = @xpath.fillable_field('First Name').to_s
|
94
|
-
@driver.find(@query).first.value.should == 'John'
|
95
|
-
@query = @xpath.fillable_field('Password').to_s
|
96
|
-
@driver.find(@query).first.value.should == 'seeekrit'
|
97
|
-
@query = @xpath.fillable_field('Description').to_s
|
98
|
-
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should be chainable" do
|
102
|
-
@query = @xpath.fillable_field('First Name').button('Click me!').to_s
|
103
|
-
@driver.find(@query).first.value.should == 'John'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe '#text_area' do
|
108
|
-
it "should find a text area by id or label" do
|
109
|
-
@query = @xpath.text_area('form_description').to_s
|
110
|
-
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
111
|
-
@query = @xpath.text_area('Description').to_s
|
112
|
-
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should be chainable" do
|
116
|
-
@query = @xpath.text_area('Description').button('Click me!').to_s
|
117
|
-
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe '#button' do
|
122
|
-
it "should find a button by id or content" do
|
123
|
-
@query = @xpath.button('awe123').to_s
|
124
|
-
@driver.find(@query).first.value.should == 'awesome'
|
125
|
-
@query = @xpath.button('okay556').to_s
|
126
|
-
@driver.find(@query).first.value.should == 'okay'
|
127
|
-
@query = @xpath.button('click_me_123').to_s
|
128
|
-
@driver.find(@query).first.value.should == 'click_me'
|
129
|
-
@query = @xpath.button('Click me!').to_s
|
130
|
-
@driver.find(@query).first.value.should == 'click_me'
|
131
|
-
@query = @xpath.button('fresh_btn').to_s
|
132
|
-
@driver.find(@query).first.value.should == 'i am fresh'
|
133
|
-
@query = @xpath.button('i am fresh').to_s
|
134
|
-
@driver.find(@query).first[:name].should == 'form[fresh]'
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe '#radio_button' do
|
139
|
-
it "should find a radio button by id or label" do
|
140
|
-
@query = @xpath.radio_button('Male').to_s
|
141
|
-
@driver.find(@query).first.value.should == 'male'
|
142
|
-
@query = @xpath.radio_button('gender_male').to_s
|
143
|
-
@driver.find(@query).first.value.should == 'male'
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should be chainable" do
|
147
|
-
@query = @xpath.radio_button('Male').button('Click me!').to_s
|
148
|
-
@driver.find(@query).first.value.should == 'male'
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe '#checkbox' do
|
153
|
-
it "should find a checkbox by id or label" do
|
154
|
-
@query = @xpath.checkbox('Cat').to_s
|
155
|
-
@driver.find(@query).first.value.should == 'cat'
|
156
|
-
@query = @xpath.checkbox('form_pets_cat').to_s
|
157
|
-
@driver.find(@query).first.value.should == 'cat'
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should be chainable" do
|
161
|
-
@query = @xpath.checkbox('Cat').button('Click me!').to_s
|
162
|
-
@driver.find(@query).first.value.should == 'cat'
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe '#select' do
|
167
|
-
it "should find a select by id or label" do
|
168
|
-
@query = @xpath.select('Region').to_s
|
169
|
-
@driver.find(@query).first[:name].should == 'form[region]'
|
170
|
-
@query = @xpath.select('form_region').to_s
|
171
|
-
@driver.find(@query).first[:name].should == 'form[region]'
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should be chainable" do
|
175
|
-
@query = @xpath.select('Region').button('Click me!').to_s
|
176
|
-
@driver.find(@query).first[:name].should == 'form[region]'
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|