capybara 2.0.0.beta2 → 2.0.0.beta4
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 +30 -1
- data/README.md +52 -31
- data/lib/capybara.rb +1 -0
- data/lib/capybara/driver/base.rb +1 -1
- data/lib/capybara/driver/node.rb +1 -0
- data/lib/capybara/dsl.rb +12 -5
- data/lib/capybara/helpers.rb +33 -0
- data/lib/capybara/node/actions.rb +4 -2
- data/lib/capybara/node/base.rb +52 -1
- data/lib/capybara/node/element.rb +0 -12
- data/lib/capybara/node/finders.rb +1 -1
- data/lib/capybara/node/matchers.rb +57 -47
- data/lib/capybara/node/simple.rb +4 -0
- data/lib/capybara/query.rb +11 -11
- data/lib/capybara/rack_test/browser.rb +14 -15
- data/lib/capybara/rack_test/driver.rb +2 -2
- data/lib/capybara/rack_test/node.rb +15 -2
- data/lib/capybara/result.rb +7 -19
- data/lib/capybara/rspec.rb +7 -4
- data/lib/capybara/rspec/features.rb +4 -1
- data/lib/capybara/rspec/matchers.rb +8 -3
- data/lib/capybara/selector.rb +1 -2
- data/lib/capybara/selenium/driver.rb +2 -2
- data/lib/capybara/selenium/node.rb +9 -7
- data/lib/capybara/session.rb +47 -31
- data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
- data/lib/capybara/spec/public/test.js +1 -1
- data/lib/capybara/spec/session/all_spec.rb +60 -62
- data/lib/capybara/spec/session/assert_selector.rb +123 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
- data/lib/capybara/spec/session/body_spec.rb +21 -0
- data/lib/capybara/spec/session/check_spec.rb +67 -50
- data/lib/capybara/spec/session/choose_spec.rb +32 -21
- data/lib/capybara/spec/session/click_button_spec.rb +261 -221
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
- data/lib/capybara/spec/session/click_link_spec.rb +95 -81
- data/lib/capybara/spec/session/current_url_spec.rb +70 -60
- 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 +118 -92
- 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 +96 -91
- data/lib/capybara/spec/session/first_spec.rb +53 -55
- 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 +167 -169
- data/lib/capybara/spec/session/has_link_spec.rb +26 -29
- data/lib/capybara/spec/session/has_select_spec.rb +175 -176
- data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
- data/lib/capybara/spec/session/has_table_spec.rb +22 -26
- data/lib/capybara/spec/session/has_text_spec.rb +159 -132
- 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 +172 -82
- 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 +8 -24
- data/lib/capybara/spec/session/select_spec.rb +100 -89
- data/lib/capybara/spec/session/source_spec.rb +12 -0
- data/lib/capybara/spec/session/text_spec.rb +15 -17
- data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
- data/lib/capybara/spec/session/unselect_spec.rb +57 -52
- data/lib/capybara/spec/session/visit_spec.rb +58 -60
- data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
- data/lib/capybara/spec/session/within_spec.rb +119 -121
- data/lib/capybara/spec/session/within_window_spec.rb +29 -31
- data/lib/capybara/spec/spec_helper.rb +84 -0
- data/lib/capybara/spec/test_app.rb +5 -3
- data/lib/capybara/spec/views/form.erb +1 -0
- data/lib/capybara/spec/views/with_html.erb +6 -1
- data/lib/capybara/spec/views/with_js.erb +1 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +2 -2
- data/spec/capybara_spec.rb +9 -0
- data/spec/dsl_spec.rb +22 -10
- data/spec/rack_test_spec.rb +28 -23
- data/spec/result_spec.rb +51 -0
- data/spec/rspec/features_spec.rb +19 -0
- data/spec/rspec/matchers_spec.rb +6 -0
- data/spec/rspec_spec.rb +1 -1
- data/spec/selenium_spec.rb +11 -25
- data/spec/server_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -46
- metadata +41 -98
- data/lib/capybara/spec/session.rb +0 -183
- data/lib/capybara/spec/session/javascript.rb +0 -290
- data/lib/capybara/util/save_and_open_page.rb +0 -45
- data/spec/save_and_open_page_spec.rb +0 -155
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Capybara::SpecHelper.spec '#find_button' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "should find any button" do
|
|
7
|
+
@session.find_button('med')[:id].should == "mediocre"
|
|
8
|
+
@session.find_button('crap321').value.should == "crappy"
|
|
9
|
+
end
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
+
it "casts to string" do
|
|
12
|
+
@session.find_button(:'med')[:id].should == "mediocre"
|
|
13
|
+
end
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
15
|
+
it "should raise error if the button doesn't exist" do
|
|
16
|
+
expect do
|
|
17
|
+
@session.find_button('Does not exist')
|
|
18
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
17
19
|
end
|
|
18
20
|
end
|
|
@@ -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,121 +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
|
-
|
|
20
|
+
it "should raise an error if there are multiple matches" do
|
|
21
|
+
expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
|
|
22
|
+
end
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
end
|
|
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
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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)
|
|
38
36
|
end
|
|
37
|
+
end
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
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'
|
|
45
43
|
end
|
|
44
|
+
end
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
@session.find(:monkey, 'john').text.should == 'Monkey John'
|
|
53
|
-
@session.find(:monkey, 'paul').text.should == 'Monkey Paul'
|
|
54
|
-
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'
|
|
55
50
|
end
|
|
51
|
+
end
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
match { |value| value.is_a?(Fixnum) }
|
|
62
|
-
end
|
|
63
|
-
@session.find(:monkey, '2').text.should == 'Monkey Paul'
|
|
64
|
-
@session.find(1).text.should == 'Monkey John'
|
|
65
|
-
@session.find(2).text.should == 'Monkey Paul'
|
|
66
|
-
@session.find('//h1').text.should == 'This is a test'
|
|
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']" }
|
|
67
57
|
end
|
|
58
|
+
@session.find(:monkey, 'john').text.should == 'Monkey John'
|
|
59
|
+
@session.find(:monkey, 'paul').text.should == 'Monkey Paul'
|
|
68
60
|
end
|
|
61
|
+
end
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "should find elements that match the filter" do
|
|
79
|
-
@session.find(:monkey, '1', :name => 'Monkey John').text.should == 'Monkey John'
|
|
80
|
-
@session.find(:monkey, '2', :name => '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) }
|
|
81
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
|
+
end
|
|
74
|
+
end
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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 }
|
|
86
81
|
end
|
|
87
82
|
end
|
|
88
83
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
@session.find('h1').text.should == 'This is a test'
|
|
93
|
-
@session.find("input[id='test_field']")[:value].should == 'monkey'
|
|
94
|
-
end
|
|
95
|
-
after { Capybara.default_selector = :xpath }
|
|
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'
|
|
96
87
|
end
|
|
97
88
|
|
|
98
|
-
it "should
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
end.should raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\"")
|
|
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)
|
|
102
92
|
end
|
|
93
|
+
end
|
|
103
94
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
@session.find(
|
|
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'
|
|
108
100
|
end
|
|
101
|
+
after { Capybara.default_selector = :xpath }
|
|
102
|
+
end
|
|
109
103
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
|
109
|
+
|
|
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
|
|
115
|
+
|
|
116
|
+
context "within a scope" do
|
|
117
|
+
before do
|
|
118
|
+
@session.visit('/with_scope')
|
|
119
|
+
end
|
|
114
120
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
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/
|
|
119
124
|
end
|
|
120
125
|
end
|
|
121
126
|
end
|
|
@@ -1,72 +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
|
-
|
|
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
|
|
51
|
+
end
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
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
|
|
59
57
|
end
|
|
58
|
+
end
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
context "within a scope" do
|
|
61
|
+
before do
|
|
62
|
+
@session.visit('/with_scope')
|
|
63
|
+
end
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
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
|
|
70
68
|
end
|
|
71
69
|
end
|
|
72
70
|
end
|