capybara 1.1.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{History.txt → History.md} +138 -0
- data/License.txt +22 -0
- data/README.md +850 -0
- data/lib/capybara/cucumber.rb +2 -5
- data/lib/capybara/driver/base.rb +6 -6
- data/lib/capybara/driver/node.rb +3 -2
- data/lib/capybara/dsl.rb +13 -124
- data/lib/capybara/helpers.rb +33 -0
- data/lib/capybara/node/actions.rb +16 -30
- data/lib/capybara/node/base.rb +56 -13
- data/lib/capybara/node/element.rb +18 -30
- data/lib/capybara/node/finders.rb +28 -90
- data/lib/capybara/node/matchers.rb +121 -73
- data/lib/capybara/node/simple.rb +13 -11
- data/lib/capybara/query.rb +78 -0
- data/lib/capybara/rack_test/browser.rb +27 -39
- data/lib/capybara/rack_test/driver.rb +13 -3
- data/lib/capybara/rack_test/node.rb +31 -2
- data/lib/capybara/result.rb +72 -0
- data/lib/capybara/rspec/features.rb +4 -1
- data/lib/capybara/rspec/matchers.rb +33 -63
- data/lib/capybara/rspec.rb +7 -4
- data/lib/capybara/selector.rb +97 -34
- data/lib/capybara/selenium/driver.rb +15 -62
- data/lib/capybara/selenium/node.rb +14 -21
- data/lib/capybara/server.rb +32 -27
- data/lib/capybara/session.rb +90 -50
- data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +791 -0
- data/lib/capybara/spec/public/jquery.js +9046 -0
- data/lib/capybara/spec/public/test.js +3 -0
- data/lib/capybara/spec/session/all_spec.rb +61 -59
- data/lib/capybara/spec/session/assert_selector.rb +123 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
- data/lib/capybara/spec/session/body_spec.rb +21 -0
- data/lib/capybara/spec/session/check_spec.rb +68 -48
- data/lib/capybara/spec/session/choose_spec.rb +32 -18
- data/lib/capybara/spec/session/click_button_spec.rb +263 -232
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
- data/lib/capybara/spec/session/click_link_spec.rb +96 -96
- data/lib/capybara/spec/session/current_url_spec.rb +88 -10
- data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
- data/lib/capybara/spec/session/find_button_spec.rb +16 -14
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
- data/lib/capybara/spec/session/find_field_spec.rb +23 -21
- data/lib/capybara/spec/session/find_link_spec.rb +15 -14
- data/lib/capybara/spec/session/find_spec.rb +93 -115
- data/lib/capybara/spec/session/first_spec.rb +51 -85
- data/lib/capybara/spec/session/has_button_spec.rb +22 -24
- data/lib/capybara/spec/session/has_css_spec.rb +190 -205
- data/lib/capybara/spec/session/has_field_spec.rb +170 -144
- data/lib/capybara/spec/session/has_link_spec.rb +26 -29
- data/lib/capybara/spec/session/has_select_spec.rb +161 -109
- data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
- data/lib/capybara/spec/session/has_table_spec.rb +22 -88
- data/lib/capybara/spec/session/has_text_spec.rb +195 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
- data/lib/capybara/spec/session/headers.rb +4 -17
- data/lib/capybara/spec/session/html_spec.rb +15 -0
- data/lib/capybara/spec/session/node_spec.rb +205 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
- data/lib/capybara/spec/session/response_code.rb +4 -17
- data/lib/capybara/spec/session/save_page_spec.rb +46 -0
- data/lib/capybara/spec/session/screenshot.rb +13 -0
- data/lib/capybara/spec/session/select_spec.rb +99 -88
- data/lib/capybara/spec/session/source_spec.rb +12 -0
- data/lib/capybara/spec/session/text_spec.rb +15 -12
- data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
- data/lib/capybara/spec/session/unselect_spec.rb +69 -58
- data/lib/capybara/spec/session/visit_spec.rb +74 -0
- data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
- data/lib/capybara/spec/session/within_spec.rb +118 -131
- data/lib/capybara/spec/session/within_window_spec.rb +38 -0
- data/lib/capybara/spec/spec_helper.rb +84 -0
- data/lib/capybara/spec/test_app.rb +32 -6
- data/lib/capybara/spec/views/form.erb +12 -10
- data/lib/capybara/spec/views/host_links.erb +2 -2
- data/lib/capybara/spec/views/tables.erb +6 -66
- data/lib/capybara/spec/views/with_html.erb +9 -4
- data/lib/capybara/spec/views/with_js.erb +11 -7
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +125 -6
- data/spec/basic_node_spec.rb +17 -5
- data/spec/capybara_spec.rb +9 -0
- data/spec/dsl_spec.rb +31 -17
- data/spec/rack_test_spec.rb +157 -0
- data/spec/result_spec.rb +51 -0
- data/spec/rspec/features_spec.rb +19 -2
- data/spec/rspec/matchers_spec.rb +170 -89
- data/spec/rspec_spec.rb +1 -3
- data/spec/selenium_spec.rb +53 -0
- data/spec/server_spec.rb +37 -25
- data/spec/spec_helper.rb +1 -30
- metadata +39 -31
- data/README.rdoc +0 -722
- data/lib/capybara/spec/driver.rb +0 -301
- data/lib/capybara/spec/session/current_host_spec.rb +0 -68
- data/lib/capybara/spec/session/has_content_spec.rb +0 -106
- data/lib/capybara/spec/session/javascript.rb +0 -306
- data/lib/capybara/spec/session.rb +0 -154
- data/lib/capybara/util/save_and_open_page.rb +0 -44
- data/lib/capybara/util/timeout.rb +0 -27
- data/spec/driver/rack_test_driver_spec.rb +0 -89
- data/spec/driver/selenium_driver_spec.rb +0 -37
- data/spec/save_and_open_page_spec.rb +0 -155
- data/spec/session/rack_test_session_spec.rb +0 -55
- data/spec/session/selenium_session_spec.rb +0 -26
- data/spec/string_spec.rb +0 -77
- data/spec/timeout_spec.rb +0 -28
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Capybara::SpecHelper.spec '#find_by_id' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "should find any element by id" do
|
|
7
|
+
@session.find_by_id('red').tag_name.should == 'a'
|
|
8
|
+
@session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
|
|
9
|
+
end
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
+
it "casts to string" do
|
|
12
|
+
@session.find_by_id(:'red').tag_name.should == 'a'
|
|
13
|
+
end
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
15
|
+
it "should raise error if no element with id is found" do
|
|
16
|
+
expect do
|
|
17
|
+
@session.find_by_id('nothing_with_this_id')
|
|
18
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
17
19
|
end
|
|
18
20
|
end
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#find_field' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
it "should find any field" do
|
|
7
|
+
@session.find_field('Dog').value.should == 'dog'
|
|
8
|
+
@session.find_field('form_description').text.should == 'Descriptive text goes here'
|
|
9
|
+
@session.find_field('Region')[:name].should == 'form[region]'
|
|
10
|
+
end
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
it "casts to string" do
|
|
13
|
+
@session.find_field(:'Dog').value.should == 'dog'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should raise error if the field doesn't exist" do
|
|
17
|
+
expect do
|
|
18
|
+
@session.find_field('Does not exist')
|
|
19
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
20
|
+
end
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
22
|
+
it "should be aliased as 'field_labeled' for webrat compatibility" do
|
|
23
|
+
@session.field_labeled('Dog').value.should == 'dog'
|
|
24
|
+
expect do
|
|
25
|
+
@session.field_labeled('Does not exist')
|
|
26
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
25
27
|
end
|
|
26
28
|
end
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
Capybara::SpecHelper.spec '#find_link' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
end
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
it "should find any field" do
|
|
7
|
+
@session.find_link('foo').text.should == "ullamco"
|
|
8
|
+
@session.find_link('labore')[:href].should =~ %r(/with_simple_html$)
|
|
9
|
+
end
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
end
|
|
11
|
+
it "casts to string" do
|
|
12
|
+
@session.find_link(:'foo').text.should == "ullamco"
|
|
13
|
+
end
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
15
|
+
it "should raise error if the field doesn't exist" do
|
|
16
|
+
expect do
|
|
17
|
+
@session.find_link('Does not exist')
|
|
18
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
18
19
|
end
|
|
19
20
|
end
|
|
@@ -1,148 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#find' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
after do
|
|
7
|
+
Capybara::Selector.remove(:monkey)
|
|
8
|
+
end
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
it "should find the first element using the given locator" do
|
|
11
|
+
@session.find('//h1').text.should == 'This is a test'
|
|
12
|
+
@session.find("//input[@id='test_field']")[:value].should == 'monkey'
|
|
13
|
+
end
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
it "should find the first element using the given locator and options" do
|
|
16
|
+
@session.find('//a', :text => 'Redirect')[:id].should == 'red'
|
|
17
|
+
@session.find(:css, 'a', :text => 'A link came first')[:title].should == 'twas a fine link'
|
|
18
|
+
end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@form = @session.find(:css, '#get-form')
|
|
25
|
-
@form.should have_field('Middle Name')
|
|
26
|
-
@form.should have_no_field('Languages')
|
|
27
|
-
@form.fill_in('Middle Name', :with => 'Monkey')
|
|
28
|
-
@form.click_button('med')
|
|
29
|
-
extract_results(@session)['middle_name'].should == 'Monkey'
|
|
30
|
-
end
|
|
20
|
+
it "should raise an error if there are multiple matches" do
|
|
21
|
+
expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
|
|
22
|
+
end
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
it "should wait for asynchronous load", :requires => [:js] do
|
|
25
|
+
@session.visit('/with_js')
|
|
26
|
+
@session.click_link('Click me')
|
|
27
|
+
@session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
|
|
28
|
+
end
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
context "with frozen time", :requires => [:js] do
|
|
31
|
+
it "raises an error suggesting that Capybara is stuck in time" do
|
|
32
|
+
@session.visit('/with_js')
|
|
33
|
+
now = Time.now
|
|
34
|
+
Time.stub(:now).and_return(now)
|
|
35
|
+
expect { @session.find('//isnotthere') }.to raise_error(Capybara::FrozenInTime)
|
|
41
36
|
end
|
|
37
|
+
end
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end
|
|
39
|
+
context "with css selectors" do
|
|
40
|
+
it "should find the first element using the given locator" do
|
|
41
|
+
@session.find(:css, 'h1').text.should == 'This is a test'
|
|
42
|
+
@session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
|
|
48
43
|
end
|
|
44
|
+
end
|
|
49
45
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@session.find(:red).text.should == 'Redirect'
|
|
55
|
-
end
|
|
46
|
+
context "with xpath selectors" do
|
|
47
|
+
it "should find the first element using the given locator" do
|
|
48
|
+
@session.find(:xpath, '//h1').text.should == 'This is a test'
|
|
49
|
+
@session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
|
|
56
50
|
end
|
|
51
|
+
end
|
|
57
52
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
context "with custom selector" do
|
|
54
|
+
it "should use the custom selector" do
|
|
55
|
+
Capybara.add_selector(:monkey) do
|
|
56
|
+
xpath { |name| ".//*[@id='#{name}_monkey']" }
|
|
62
57
|
end
|
|
58
|
+
@session.find(:monkey, 'john').text.should == 'Monkey John'
|
|
59
|
+
@session.find(:monkey, 'paul').text.should == 'Monkey Paul'
|
|
63
60
|
end
|
|
61
|
+
end
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
@session.find(:monkey, 'john').text.should == 'Monkey John'
|
|
71
|
-
@session.find(:monkey, 'paul').text.should == 'Monkey Paul'
|
|
63
|
+
context "with custom selector with :for option" do
|
|
64
|
+
it "should use the selector when it matches the :for option" do
|
|
65
|
+
Capybara.add_selector(:monkey) do
|
|
66
|
+
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
|
67
|
+
match { |value| value.is_a?(Fixnum) }
|
|
72
68
|
end
|
|
69
|
+
@session.find(:monkey, '2').text.should == 'Monkey Paul'
|
|
70
|
+
@session.find(1).text.should == 'Monkey John'
|
|
71
|
+
@session.find(2).text.should == 'Monkey Paul'
|
|
72
|
+
@session.find('//h1').text.should == 'This is a test'
|
|
73
73
|
end
|
|
74
|
+
end
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
@session.find(:monkey, '2').text.should == 'Monkey Paul'
|
|
82
|
-
@session.find(1).text.should == 'Monkey John'
|
|
83
|
-
@session.find(2).text.should == 'Monkey Paul'
|
|
84
|
-
@session.find('//h1').text.should == 'This is a test'
|
|
76
|
+
context "with custom selector with custom filter" do
|
|
77
|
+
before do
|
|
78
|
+
Capybara.add_selector(:monkey) do
|
|
79
|
+
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
|
80
|
+
filter(:name) { |node, name| node.text == name }
|
|
85
81
|
end
|
|
86
82
|
end
|
|
87
83
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
|
92
|
-
failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
|
|
93
|
-
end
|
|
94
|
-
running do
|
|
95
|
-
@session.find(:monkey, '14').text.should == 'Monkey Paul'
|
|
96
|
-
end.should raise_error(Capybara::ElementNotFound, "Monkey John, Monkey Paul")
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should pass the selector as the second argument" do
|
|
100
|
-
Capybara.add_selector(:monkey) do
|
|
101
|
-
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
|
102
|
-
failure_message { |node, selector| selector.name.to_s + ': ' + selector.locator + ' - ' + node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
|
|
103
|
-
end
|
|
104
|
-
running do
|
|
105
|
-
@session.find(:monkey, '14').text.should == 'Monkey Paul'
|
|
106
|
-
end.should raise_error(Capybara::ElementNotFound, "monkey: 14 - Monkey John, Monkey Paul")
|
|
107
|
-
end
|
|
84
|
+
it "should find elements that match the filter" do
|
|
85
|
+
@session.find(:monkey, '1', :name => 'Monkey John').text.should == 'Monkey John'
|
|
86
|
+
@session.find(:monkey, '2', :name => 'Monkey Paul').text.should == 'Monkey Paul'
|
|
108
87
|
end
|
|
109
88
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
@session.find('h1').text.should == 'This is a test'
|
|
114
|
-
@session.find("input[id='test_field']")[:value].should == 'monkey'
|
|
115
|
-
end
|
|
116
|
-
after { Capybara.default_selector = :xpath }
|
|
89
|
+
it "should not find elements that don't match the filter" do
|
|
90
|
+
expect { @session.find(:monkey, '2', :name => 'Monkey John') }.to raise_error(Capybara::ElementNotFound)
|
|
91
|
+
expect { @session.find(:monkey, '1', :name => 'Monkey Paul') }.to raise_error(Capybara::ElementNotFound)
|
|
117
92
|
end
|
|
93
|
+
end
|
|
118
94
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
95
|
+
context "with css as default selector" do
|
|
96
|
+
before { Capybara.default_selector = :css }
|
|
97
|
+
it "should find the first element using the given locator" do
|
|
98
|
+
@session.find('h1').text.should == 'This is a test'
|
|
99
|
+
@session.find("input[id='test_field']")[:value].should == 'monkey'
|
|
123
100
|
end
|
|
101
|
+
after { Capybara.default_selector = :xpath }
|
|
102
|
+
end
|
|
124
103
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
104
|
+
it "should raise ElementNotFound with a useful default message if nothing was found" do
|
|
105
|
+
expect do
|
|
106
|
+
@session.find(:xpath, '//div[@id="nosuchthing"]').to be_nil
|
|
107
|
+
end.to raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\"")
|
|
108
|
+
end
|
|
130
109
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
110
|
+
it "should accept an XPath instance" do
|
|
111
|
+
@session.visit('/form')
|
|
112
|
+
@xpath = XPath::HTML.fillable_field('First Name')
|
|
113
|
+
@session.find(@xpath).value.should == 'John'
|
|
114
|
+
end
|
|
136
115
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
116
|
+
context "within a scope" do
|
|
117
|
+
before do
|
|
118
|
+
@session.visit('/with_scope')
|
|
119
|
+
end
|
|
141
120
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
end
|
|
121
|
+
it "should find the an element using the given locator" do
|
|
122
|
+
@session.within(:xpath, "//div[@id='for_bar']") do
|
|
123
|
+
@session.find('.//li[1]').text.should =~ /With Simple HTML/
|
|
146
124
|
end
|
|
147
125
|
end
|
|
148
126
|
end
|
|
@@ -1,104 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#first' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
it "should find the first element using the given locator" do
|
|
7
|
+
@session.first('//h1').text.should == 'This is a test'
|
|
8
|
+
@session.first("//input[@id='test_field']")[:value].should == 'monkey'
|
|
9
|
+
end
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
it "should return nil when nothing was found" do
|
|
12
|
+
@session.first('//div[@id="nosuchthing"]').should be_nil
|
|
13
|
+
end
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
it "should accept an XPath instance" do
|
|
16
|
+
@session.visit('/form')
|
|
17
|
+
@xpath = XPath::HTML.fillable_field('First Name')
|
|
18
|
+
@session.first(@xpath).value.should == 'John'
|
|
19
|
+
end
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
21
|
+
context "with css selectors" do
|
|
22
|
+
it "should find the first element using the given selector" do
|
|
23
|
+
@session.first(:css, 'h1').text.should == 'This is a test'
|
|
24
|
+
@session.first(:css, "input[id='test_field']")[:value].should == 'monkey'
|
|
27
25
|
end
|
|
26
|
+
end
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
28
|
+
context "with xpath selectors" do
|
|
29
|
+
it "should find the first element using the given locator" do
|
|
30
|
+
@session.first(:xpath, '//h1').text.should == 'This is a test'
|
|
31
|
+
@session.first(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
|
|
34
32
|
end
|
|
33
|
+
end
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
after { Capybara.default_selector = :xpath }
|
|
35
|
+
context "with css as default selector" do
|
|
36
|
+
before { Capybara.default_selector = :css }
|
|
37
|
+
it "should find the first element using the given locator" do
|
|
38
|
+
@session.first('h1').text.should == 'This is a test'
|
|
39
|
+
@session.first("input[id='test_field']")[:value].should == 'monkey'
|
|
43
40
|
end
|
|
41
|
+
after { Capybara.default_selector = :xpath }
|
|
42
|
+
end
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "should include invisible nodes if false given" do
|
|
55
|
-
Capybara.ignore_hidden_elements = true
|
|
56
|
-
@session.first(:css, "a#invisible", :visible => false).should_not be_nil
|
|
57
|
-
@session.first(:css, "a#invisible").should be_nil
|
|
58
|
-
end
|
|
44
|
+
context "with visible filter" do
|
|
45
|
+
after { Capybara.ignore_hidden_elements = false }
|
|
46
|
+
it "should only find visible nodes if true given" do
|
|
47
|
+
@session.first(:css, "a#invisible").should_not be_nil
|
|
48
|
+
@session.first(:css, "a#invisible", :visible => true).should be_nil
|
|
49
|
+
Capybara.ignore_hidden_elements = true
|
|
50
|
+
@session.first(:css, "a#invisible").should be_nil
|
|
59
51
|
end
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
it "should prefer visible elements over invisible elements" do
|
|
67
|
-
@session.first(:css, 'a.visibility')[:id].should == 'visible'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "should return the first invisible element if no visible elements exist" do
|
|
71
|
-
@session.first(:css, 'a.hidden')[:id].should == 'first_invisble'
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "find visible links normally" do
|
|
75
|
-
@session.first(:css, 'a#visible')[:id].should == 'visible'
|
|
76
|
-
end
|
|
53
|
+
it "should include invisible nodes if false given" do
|
|
54
|
+
Capybara.ignore_hidden_elements = true
|
|
55
|
+
@session.first(:css, "a#invisible", :visible => false).should_not be_nil
|
|
56
|
+
@session.first(:css, "a#invisible").should be_nil
|
|
77
57
|
end
|
|
58
|
+
end
|
|
78
59
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
it "should find invisible elements if no visible element exists" do
|
|
83
|
-
@session.first(:css, 'a#invisible')[:id].should == 'invisible'
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it "should not prefer visible elements over invisible elements" do
|
|
87
|
-
@session.first(:css, 'a.visibility')[:id].should == 'invisible'
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
after { Capybara.prefer_visible_elements = true }
|
|
60
|
+
context "within a scope" do
|
|
61
|
+
before do
|
|
62
|
+
@session.visit('/with_scope')
|
|
91
63
|
end
|
|
92
64
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
@session.
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "should find the first element using the given locator" do
|
|
99
|
-
@session.within(:xpath, "//div[@id='for_bar']") do
|
|
100
|
-
@session.first('.//form').should_not be_nil
|
|
101
|
-
end
|
|
65
|
+
it "should find the first element using the given locator" do
|
|
66
|
+
@session.within(:xpath, "//div[@id='for_bar']") do
|
|
67
|
+
@session.first('.//form').should_not be_nil
|
|
102
68
|
end
|
|
103
69
|
end
|
|
104
70
|
end
|
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#has_button?' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
it "should be true if the given button is on the page" do
|
|
7
|
+
@session.should have_button('med')
|
|
8
|
+
@session.should have_button('crap321')
|
|
9
|
+
@session.should have_button(:'crap321')
|
|
10
|
+
end
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
12
|
+
it "should be false if the given button is not on the page" do
|
|
13
|
+
@session.should_not have_button('monkey')
|
|
15
14
|
end
|
|
15
|
+
end
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
Capybara::SpecHelper.spec '#has_no_button?' do
|
|
18
|
+
before do
|
|
19
|
+
@session.visit('/form')
|
|
20
|
+
end
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
it "should be true if the given button is on the page" do
|
|
23
|
+
@session.should_not have_no_button('med')
|
|
24
|
+
@session.should_not have_no_button('crap321')
|
|
25
|
+
end
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end
|
|
27
|
+
it "should be false if the given button is not on the page" do
|
|
28
|
+
@session.should have_no_button('monkey')
|
|
30
29
|
end
|
|
31
30
|
end
|
|
32
|
-
|