capybara-rails-2-2 0.4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +202 -0
- data/README.rdoc +540 -0
- data/lib/capybara.rb +231 -0
- data/lib/capybara/cucumber.rb +32 -0
- data/lib/capybara/driver/base.rb +60 -0
- data/lib/capybara/driver/celerity_driver.rb +164 -0
- data/lib/capybara/driver/culerity_driver.rb +26 -0
- data/lib/capybara/driver/node.rb +74 -0
- data/lib/capybara/driver/rack_test_driver.rb +303 -0
- data/lib/capybara/driver/selenium_driver.rb +161 -0
- data/lib/capybara/dsl.rb +109 -0
- data/lib/capybara/node/actions.rb +160 -0
- data/lib/capybara/node/base.rb +47 -0
- data/lib/capybara/node/document.rb +17 -0
- data/lib/capybara/node/element.rb +178 -0
- data/lib/capybara/node/finders.rb +201 -0
- data/lib/capybara/node/matchers.rb +391 -0
- data/lib/capybara/node/simple.rb +116 -0
- data/lib/capybara/rails.rb +16 -0
- data/lib/capybara/rspec.rb +18 -0
- data/lib/capybara/selector.rb +70 -0
- data/lib/capybara/server.rb +90 -0
- data/lib/capybara/session.rb +281 -0
- data/lib/capybara/spec/driver.rb +243 -0
- data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
- data/lib/capybara/spec/fixtures/test_file.txt +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +35 -0
- data/lib/capybara/spec/public/jquery.js +19 -0
- data/lib/capybara/spec/public/test.js +33 -0
- data/lib/capybara/spec/session.rb +110 -0
- data/lib/capybara/spec/session/all_spec.rb +78 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +70 -0
- data/lib/capybara/spec/session/check_spec.rb +65 -0
- data/lib/capybara/spec/session/choose_spec.rb +26 -0
- data/lib/capybara/spec/session/click_button_spec.rb +252 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +36 -0
- data/lib/capybara/spec/session/click_link_spec.rb +113 -0
- data/lib/capybara/spec/session/current_url_spec.rb +15 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +119 -0
- data/lib/capybara/spec/session/find_button_spec.rb +18 -0
- data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
- data/lib/capybara/spec/session/find_field_spec.rb +26 -0
- data/lib/capybara/spec/session/find_link_spec.rb +19 -0
- data/lib/capybara/spec/session/find_spec.rb +121 -0
- data/lib/capybara/spec/session/first_spec.rb +72 -0
- data/lib/capybara/spec/session/has_button_spec.rb +32 -0
- data/lib/capybara/spec/session/has_content_spec.rb +106 -0
- data/lib/capybara/spec/session/has_css_spec.rb +213 -0
- data/lib/capybara/spec/session/has_field_spec.rb +156 -0
- data/lib/capybara/spec/session/has_link_spec.rb +37 -0
- data/lib/capybara/spec/session/has_select_spec.rb +129 -0
- data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
- data/lib/capybara/spec/session/has_table_spec.rb +96 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
- data/lib/capybara/spec/session/headers.rb +19 -0
- data/lib/capybara/spec/session/javascript.rb +223 -0
- data/lib/capybara/spec/session/response_code.rb +19 -0
- data/lib/capybara/spec/session/select_spec.rb +105 -0
- data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
- data/lib/capybara/spec/session/unselect_spec.rb +61 -0
- data/lib/capybara/spec/session/within_spec.rb +160 -0
- data/lib/capybara/spec/test_app.rb +117 -0
- data/lib/capybara/spec/views/buttons.erb +4 -0
- data/lib/capybara/spec/views/fieldsets.erb +29 -0
- data/lib/capybara/spec/views/form.erb +348 -0
- data/lib/capybara/spec/views/frame_one.erb +8 -0
- data/lib/capybara/spec/views/frame_two.erb +8 -0
- 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/postback.erb +13 -0
- data/lib/capybara/spec/views/tables.erb +122 -0
- data/lib/capybara/spec/views/with_html.erb +69 -0
- data/lib/capybara/spec/views/with_js.erb +39 -0
- data/lib/capybara/spec/views/with_scope.erb +36 -0
- data/lib/capybara/spec/views/with_simple_html.erb +1 -0
- data/lib/capybara/spec/views/within_frames.erb +10 -0
- data/lib/capybara/spec/views/within_popups.erb +25 -0
- data/lib/capybara/util/save_and_open_page.rb +40 -0
- data/lib/capybara/util/timeout.rb +27 -0
- data/lib/capybara/version.rb +3 -0
- data/spec/basic_node_spec.rb +77 -0
- data/spec/capybara_spec.rb +46 -0
- data/spec/driver/celerity_driver_spec.rb +13 -0
- data/spec/driver/culerity_driver_spec.rb +14 -0
- data/spec/driver/rack_test_driver_spec.rb +84 -0
- data/spec/driver/remote_culerity_driver_spec.rb +22 -0
- data/spec/driver/remote_selenium_driver_spec.rb +16 -0
- data/spec/driver/selenium_driver_spec.rb +14 -0
- data/spec/dsl_spec.rb +157 -0
- data/spec/rspec_spec.rb +47 -0
- data/spec/save_and_open_page_spec.rb +159 -0
- data/spec/server_spec.rb +85 -0
- data/spec/session/celerity_session_spec.rb +24 -0
- data/spec/session/culerity_session_spec.rb +26 -0
- data/spec/session/rack_test_session_spec.rb +44 -0
- data/spec/session/selenium_session_spec.rb +26 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/string_spec.rb +77 -0
- data/spec/timeout_spec.rb +28 -0
- metadata +360 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_examples_for "click_link_or_button" do
|
2
|
+
describe '#click' do
|
3
|
+
it "should click on a link" do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
@session.click_link_or_button('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_link_or_button('awe123')
|
12
|
+
extract_results(@session)['first_name'].should == 'John'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should click on a button with no type attribute" do
|
16
|
+
@session.visit('/form')
|
17
|
+
@session.click_link_or_button('no_type')
|
18
|
+
extract_results(@session)['first_name'].should == 'John'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be aliased as click_on" do
|
22
|
+
@session.visit('/form')
|
23
|
+
@session.click_on('awe123')
|
24
|
+
extract_results(@session)['first_name'].should == 'John'
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with a locator that doesn't exist" do
|
28
|
+
it "should raise an error" do
|
29
|
+
@session.visit('/with_html')
|
30
|
+
running do
|
31
|
+
@session.click_link_or_button('does not exist')
|
32
|
+
end.should raise_error(Capybara::ElementNotFound)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
shared_examples_for "click_link" do
|
2
|
+
describe '#click_link' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
6
|
+
|
7
|
+
context "with id given" do
|
8
|
+
it "should take user to the linked page" do
|
9
|
+
@session.click_link('foo')
|
10
|
+
@session.body.should include('Another World')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "with text given" do
|
15
|
+
it "should take user to the linked page" do
|
16
|
+
@session.click_link('labore')
|
17
|
+
@session.body.should include('Bar')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should accept partial matches" do
|
21
|
+
@session.click_link('abo')
|
22
|
+
@session.body.should include('Bar')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should prefer exact matches over partial matches" do
|
26
|
+
@session.click_link('A link')
|
27
|
+
@session.body.should include('Bar')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with title given" do
|
32
|
+
it "should take user to the linked page" do
|
33
|
+
@session.click_link('awesome title')
|
34
|
+
@session.body.should include('Bar')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should accept partial matches" do
|
38
|
+
@session.click_link('some tit')
|
39
|
+
@session.body.should include('Bar')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should prefer exact matches over partial matches" do
|
43
|
+
@session.click_link('a fine link')
|
44
|
+
@session.body.should include('Bar')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with alternative text given to a contained image" do
|
49
|
+
it "should take user to the linked page" do
|
50
|
+
@session.click_link('awesome image')
|
51
|
+
@session.body.should include('Bar')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should take user to the linked page" do
|
55
|
+
@session.click_link('some imag')
|
56
|
+
@session.body.should include('Bar')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should prefer exact matches over partial matches" do
|
60
|
+
@session.click_link('fine image')
|
61
|
+
@session.body.should include('Bar')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "with a locator that doesn't exist" do
|
66
|
+
it "should raise an error" do
|
67
|
+
running do
|
68
|
+
@session.click_link('does not exist')
|
69
|
+
end.should raise_error(Capybara::ElementNotFound)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should follow redirects" do
|
74
|
+
@session.click_link('Redirect')
|
75
|
+
@session.body.should include('You landed')
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should follow redirects" do
|
79
|
+
@session.click_link('BackToMyself')
|
80
|
+
@session.body.should include('This is a test')
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should add query string to current URL with naked query string" do
|
84
|
+
@session.click_link('Naked Query String')
|
85
|
+
@session.body.should include('Query String sent')
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should do nothing on anchor links" do
|
89
|
+
@session.fill_in("test_field", :with => 'blah')
|
90
|
+
@session.click_link('Anchor')
|
91
|
+
@session.find_field("test_field").value.should == 'blah'
|
92
|
+
@session.click_link('Blank Anchor')
|
93
|
+
@session.find_field("test_field").value.should == 'blah'
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should do nothing on URL+anchor links for the same page" do
|
97
|
+
@session.fill_in("test_field", :with => 'blah')
|
98
|
+
@session.click_link('Anchor on same page')
|
99
|
+
@session.find_field("test_field").value.should == 'blah'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should follow link on URL+anchor links for a different page" do
|
103
|
+
@session.click_link('Anchor on different page')
|
104
|
+
@session.body.should include('Bar')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "raise an error with links with no href" do
|
108
|
+
running do
|
109
|
+
@session.click_link('No Href')
|
110
|
+
end.should raise_error(Capybara::ElementNotFound)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
shared_examples_for "current_url" do
|
2
|
+
describe '#current_url' do
|
3
|
+
it "should return the current url" do
|
4
|
+
@session.visit('/form')
|
5
|
+
@session.current_url.should =~ %r(http://[^/]+/form)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#current_path' do
|
10
|
+
it 'should show the correct location' do
|
11
|
+
@session.visit('/foo')
|
12
|
+
@session.current_path.should == '/foo'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
shared_examples_for "fill_in" do
|
2
|
+
describe "#fill_in" do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should fill in a text field by id" do
|
8
|
+
@session.fill_in('form_first_name', :with => 'Harry')
|
9
|
+
@session.click_button('awesome')
|
10
|
+
extract_results(@session)['first_name'].should == 'Harry'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should fill in a text field by name" do
|
14
|
+
@session.fill_in('form[last_name]', :with => 'Green')
|
15
|
+
@session.click_button('awesome')
|
16
|
+
extract_results(@session)['last_name'].should == 'Green'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should fill in a text field by label without for" do
|
20
|
+
@session.fill_in('Street', :with => 'Avenue Q')
|
21
|
+
@session.click_button('awesome')
|
22
|
+
extract_results(@session)['street'].should == 'Avenue Q'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should fill in a url field by label without for" do
|
26
|
+
@session.fill_in('Html5 Url', :with => 'http://www.avenueq.com')
|
27
|
+
@session.click_button('html5_submit')
|
28
|
+
extract_results(@session)['html5_url'].should == 'http://www.avenueq.com'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should favour exact label matches over partial matches" do
|
32
|
+
@session.fill_in('Name', :with => 'Harry Jones')
|
33
|
+
@session.click_button('awesome')
|
34
|
+
extract_results(@session)['name'].should == 'Harry Jones'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should fill in a textarea by id" do
|
38
|
+
@session.fill_in('form_description', :with => 'Texty text')
|
39
|
+
@session.click_button('awesome')
|
40
|
+
extract_results(@session)['description'].should == 'Texty text'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should fill in a textarea by label" do
|
44
|
+
@session.fill_in('Description', :with => 'Texty text')
|
45
|
+
@session.click_button('awesome')
|
46
|
+
extract_results(@session)['description'].should == 'Texty text'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should fill in a textarea by name" do
|
50
|
+
@session.fill_in('form[description]', :with => 'Texty text')
|
51
|
+
@session.click_button('awesome')
|
52
|
+
extract_results(@session)['description'].should == 'Texty text'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should fill in a password field by id" do
|
56
|
+
@session.fill_in('form_password', :with => 'supasikrit')
|
57
|
+
@session.click_button('awesome')
|
58
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should fill in a field with a custom type" do
|
62
|
+
@session.fill_in('Schmooo', :with => 'Schmooo is the game')
|
63
|
+
@session.click_button('awesome')
|
64
|
+
extract_results(@session)['schmooo'].should == 'Schmooo is the game'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should fill in a field without a type" do
|
68
|
+
@session.fill_in('Phone', :with => '+1 555 7022')
|
69
|
+
@session.click_button('awesome')
|
70
|
+
extract_results(@session)['phone'].should == '+1 555 7022'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should fill in a password field by name" do
|
74
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
75
|
+
@session.click_button('awesome')
|
76
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should fill in a password field by label" do
|
80
|
+
@session.fill_in('Password', :with => 'supasikrit')
|
81
|
+
@session.click_button('awesome')
|
82
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should fill in a password field by name" do
|
86
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
87
|
+
@session.click_button('awesome')
|
88
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should prefer exact matches over partial matches" do
|
92
|
+
@session.fill_in('Name', :with => 'Ford Prefect')
|
93
|
+
@session.click_button('awesome')
|
94
|
+
extract_results(@session)['name'].should == 'Ford Prefect'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should throw an exception if a hash containing 'with' is not provided" do
|
98
|
+
lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
|
99
|
+
end
|
100
|
+
|
101
|
+
context "with ignore_hidden_fields" do
|
102
|
+
before { Capybara.ignore_hidden_elements = true }
|
103
|
+
after { Capybara.ignore_hidden_elements = false }
|
104
|
+
it "should not find a hidden field" do
|
105
|
+
running do
|
106
|
+
@session.fill_in('Super Secret', :with => '777')
|
107
|
+
end.should raise_error(Capybara::ElementNotFound)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "with a locator that doesn't exist" do
|
112
|
+
it "should raise an error" do
|
113
|
+
running do
|
114
|
+
@session.fill_in('does not exist', :with => 'Blah blah')
|
115
|
+
end.should raise_error(Capybara::ElementNotFound)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
shared_examples_for "find_button" do
|
2
|
+
describe '#find_button' do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should find any field" do
|
8
|
+
@session.find_button('med')[:id].should == "mediocre"
|
9
|
+
@session.find_button('crap321').value.should == "crappy"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise error if the field doesn't exist" do
|
13
|
+
running do
|
14
|
+
@session.find_button('Does not exist')
|
15
|
+
end.should raise_error(Capybara::ElementNotFound)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
shared_examples_for "find_by_id" do
|
2
|
+
describe '#find_by_id' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should find any element by id" do
|
8
|
+
@session.find_by_id('red').tag_name.should == 'a'
|
9
|
+
@session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise error if no element with id is found" do
|
13
|
+
running do
|
14
|
+
@session.find_by_id('nothing_with_this_id')
|
15
|
+
end.should raise_error(Capybara::ElementNotFound)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
shared_examples_for "find_field" do
|
2
|
+
describe '#find_field' do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should find any field" do
|
8
|
+
@session.find_field('Dog').value.should == 'dog'
|
9
|
+
@session.find_field('form_description').text.should == 'Descriptive text goes here'
|
10
|
+
@session.find_field('Region')[:name].should == 'form[region]'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise error if the field doesn't exist" do
|
14
|
+
running do
|
15
|
+
@session.find_field('Does not exist')
|
16
|
+
end.should raise_error(Capybara::ElementNotFound)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be aliased as 'field_labeled' for webrat compatibility" do
|
20
|
+
@session.field_labeled('Dog').value.should == 'dog'
|
21
|
+
running do
|
22
|
+
@session.field_labeled('Does not exist')
|
23
|
+
end.should raise_error(Capybara::ElementNotFound)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
shared_examples_for "find_link" do
|
2
|
+
|
3
|
+
describe '#find_link' do
|
4
|
+
before do
|
5
|
+
@session.visit('/with_html')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should find any field" do
|
9
|
+
@session.find_link('foo').text.should == "ullamco"
|
10
|
+
@session.find_link('labore')[:href].should =~ %r(/with_simple_html$)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise error if the field doesn't exist" do
|
14
|
+
running do
|
15
|
+
@session.find_link('Does not exist')
|
16
|
+
end.should raise_error(Capybara::ElementNotFound)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
shared_examples_for "find" do
|
2
|
+
describe '#find' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
6
|
+
|
7
|
+
after do
|
8
|
+
Capybara::Selector.remove(:monkey)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should find the first element using the given locator" do
|
12
|
+
@session.find('//h1').text.should == 'This is a test'
|
13
|
+
@session.find("//input[@id='test_field']")[:value].should == 'monkey'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should find the first element using the given locator and options" do
|
17
|
+
@session.find('//a', :text => 'Redirect')[:id].should == 'red'
|
18
|
+
@session.find(:css, 'a', :text => 'A link')[:title].should == 'twas a fine link'
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'the returned node' do
|
22
|
+
it "should act like a session object" do
|
23
|
+
@session.visit('/form')
|
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
|
31
|
+
|
32
|
+
it "should scope CSS selectors" do
|
33
|
+
@session.find(:css, '#second').should have_no_css('h1')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with css selectors" do
|
38
|
+
it "should find the first element using the given locator" do
|
39
|
+
@session.find(:css, 'h1').text.should == 'This is a test'
|
40
|
+
@session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with id selectors" do
|
45
|
+
it "should find the first element using the given locator" do
|
46
|
+
@session.find(:id, 'john_monkey').text.should == 'Monkey John'
|
47
|
+
@session.find(:id, 'red').text.should == 'Redirect'
|
48
|
+
@session.find(:red).text.should == 'Redirect'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with xpath selectors" do
|
53
|
+
it "should find the first element using the given locator" do
|
54
|
+
@session.find(:xpath, '//h1').text.should == 'This is a test'
|
55
|
+
@session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with custom selector" do
|
60
|
+
it "should use the custom selector" do
|
61
|
+
Capybara.add_selector(:monkey) do
|
62
|
+
xpath { |name| ".//*[@id='#{name}_monkey']" }
|
63
|
+
end
|
64
|
+
@session.find(:monkey, 'john').text.should == 'Monkey John'
|
65
|
+
@session.find(:monkey, 'paul').text.should == 'Monkey Paul'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with custom selector with :for option" do
|
70
|
+
it "should use the selector when it matches the :for option" do
|
71
|
+
Capybara.add_selector(:monkey) do
|
72
|
+
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
73
|
+
match { |value| value.is_a?(Fixnum) }
|
74
|
+
end
|
75
|
+
@session.find(:monkey, '2').text.should == 'Monkey Paul'
|
76
|
+
@session.find(1).text.should == 'Monkey John'
|
77
|
+
@session.find(2).text.should == 'Monkey Paul'
|
78
|
+
@session.find('//h1').text.should == 'This is a test'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with css as default selector" do
|
83
|
+
before { Capybara.default_selector = :css }
|
84
|
+
it "should find the first element using the given locator" do
|
85
|
+
@session.find('h1').text.should == 'This is a test'
|
86
|
+
@session.find("input[id='test_field']")[:value].should == 'monkey'
|
87
|
+
end
|
88
|
+
after { Capybara.default_selector = :xpath }
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should raise ElementNotFound with specified fail message if nothing was found" do
|
92
|
+
running do
|
93
|
+
@session.find(:xpath, '//div[@id="nosuchthing"]', :message => 'arghh').should be_nil
|
94
|
+
end.should raise_error(Capybara::ElementNotFound, "arghh")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should raise ElementNotFound with a useful default message if nothing was found" do
|
98
|
+
running do
|
99
|
+
@session.find(:xpath, '//div[@id="nosuchthing"]').should be_nil
|
100
|
+
end.should raise_error(Capybara::ElementNotFound, "Unable to find '//div[@id=\"nosuchthing\"]'")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should accept an XPath instance and respect the order of paths" do
|
104
|
+
@session.visit('/form')
|
105
|
+
@xpath = XPath::HTML.fillable_field('Name')
|
106
|
+
@session.find(@xpath).value.should == 'John Smith'
|
107
|
+
end
|
108
|
+
|
109
|
+
context "within a scope" do
|
110
|
+
before do
|
111
|
+
@session.visit('/with_scope')
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should find the first element using the given locator" do
|
115
|
+
@session.within(:xpath, "//div[@id='for_bar']") do
|
116
|
+
@session.find('.//li').text.should =~ /With Simple HTML/
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|