nimboids-capybara 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +289 -0
- data/README.rdoc +722 -0
- data/lib/capybara.rb +252 -0
- data/lib/capybara/cucumber.rb +28 -0
- data/lib/capybara/driver/base.rb +64 -0
- data/lib/capybara/driver/node.rb +74 -0
- data/lib/capybara/dsl.rb +168 -0
- data/lib/capybara/node/actions.rb +162 -0
- data/lib/capybara/node/base.rb +63 -0
- data/lib/capybara/node/document.rb +25 -0
- data/lib/capybara/node/element.rb +201 -0
- data/lib/capybara/node/finders.rb +197 -0
- data/lib/capybara/node/matchers.rb +417 -0
- data/lib/capybara/node/simple.rb +132 -0
- data/lib/capybara/rack_test/browser.rb +121 -0
- data/lib/capybara/rack_test/driver.rb +80 -0
- data/lib/capybara/rack_test/form.rb +80 -0
- data/lib/capybara/rack_test/node.rb +105 -0
- data/lib/capybara/rails.rb +17 -0
- data/lib/capybara/rspec.rb +26 -0
- data/lib/capybara/rspec/features.rb +22 -0
- data/lib/capybara/rspec/matchers.rb +154 -0
- data/lib/capybara/selector.rb +89 -0
- data/lib/capybara/selenium/driver.rb +163 -0
- data/lib/capybara/selenium/node.rb +91 -0
- data/lib/capybara/server.rb +90 -0
- data/lib/capybara/session.rb +321 -0
- data/lib/capybara/spec/driver.rb +301 -0
- data/lib/capybara/spec/fixtures/capybara.jpg +3 -0
- data/lib/capybara/spec/fixtures/test_file.txt +1 -0
- data/lib/capybara/spec/public/test.js +43 -0
- data/lib/capybara/spec/session.rb +154 -0
- data/lib/capybara/spec/session/all_spec.rb +78 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +73 -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 +304 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +36 -0
- data/lib/capybara/spec/session/click_link_spec.rb +119 -0
- data/lib/capybara/spec/session/current_host_spec.rb +68 -0
- data/lib/capybara/spec/session/current_url_spec.rb +15 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +125 -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 +149 -0
- data/lib/capybara/spec/session/first_spec.rb +105 -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 +243 -0
- data/lib/capybara/spec/session/has_field_spec.rb +192 -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 +289 -0
- data/lib/capybara/spec/session/response_code.rb +19 -0
- data/lib/capybara/spec/session/select_spec.rb +113 -0
- data/lib/capybara/spec/session/text_spec.rb +19 -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 +178 -0
- data/lib/capybara/spec/test_app.rb +142 -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 +365 -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/header_links.erb +7 -0
- data/lib/capybara/spec/views/host_links.erb +12 -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 +78 -0
- data/lib/capybara/spec/views/with_html_entities.erb +1 -0
- data/lib/capybara/spec/views/with_js.erb +48 -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 +44 -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/rack_test_driver_spec.rb +89 -0
- data/spec/driver/selenium_driver_spec.rb +50 -0
- data/spec/dsl_spec.rb +253 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +8 -0
- data/spec/fixtures/selenium_driver_rspec_success.rb +8 -0
- data/spec/rspec/features_spec.rb +45 -0
- data/spec/rspec/matchers_spec.rb +495 -0
- data/spec/rspec_spec.rb +53 -0
- data/spec/save_and_open_page_spec.rb +155 -0
- data/spec/server_spec.rb +89 -0
- data/spec/session/rack_test_session_spec.rb +55 -0
- data/spec/session/selenium_session_spec.rb +26 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/string_spec.rb +77 -0
- data/spec/timeout_spec.rb +28 -0
- metadata +346 -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,119 @@
|
|
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 relative links" do
|
74
|
+
@session.visit('/')
|
75
|
+
@session.click_link('Relative')
|
76
|
+
@session.body.should include('This is a test')
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should follow redirects" do
|
80
|
+
@session.click_link('Redirect')
|
81
|
+
@session.body.should include('You landed')
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should follow redirects" do
|
85
|
+
@session.click_link('BackToMyself')
|
86
|
+
@session.body.should include('This is a test')
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should add query string to current URL with naked query string" do
|
90
|
+
@session.click_link('Naked Query String')
|
91
|
+
@session.body.should include('Query String sent')
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should do nothing on anchor links" do
|
95
|
+
@session.fill_in("test_field", :with => 'blah')
|
96
|
+
@session.click_link('Anchor')
|
97
|
+
@session.find_field("test_field").value.should == 'blah'
|
98
|
+
@session.click_link('Blank Anchor')
|
99
|
+
@session.find_field("test_field").value.should == 'blah'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should do nothing on URL+anchor links for the same page" do
|
103
|
+
@session.fill_in("test_field", :with => 'blah')
|
104
|
+
@session.click_link('Anchor on same page')
|
105
|
+
@session.find_field("test_field").value.should == 'blah'
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should follow link on URL+anchor links for a different page" do
|
109
|
+
@session.click_link('Anchor on different page')
|
110
|
+
@session.body.should include('Bar')
|
111
|
+
end
|
112
|
+
|
113
|
+
it "raise an error with links with no href" do
|
114
|
+
running do
|
115
|
+
@session.click_link('No Href')
|
116
|
+
end.should raise_error(Capybara::ElementNotFound)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
shared_examples_for "current_host" do
|
2
|
+
after do
|
3
|
+
Capybara.app_host = nil
|
4
|
+
end
|
5
|
+
|
6
|
+
describe '#current_host' do
|
7
|
+
it "is affected by visiting a page directly" do
|
8
|
+
@session.visit('http://capybara-testapp.heroku.com/host')
|
9
|
+
@session.body.should include('Current host is http://capybara-testapp.heroku.com')
|
10
|
+
@session.current_host.should == 'http://capybara-testapp.heroku.com'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns to the app host when visiting a relative url" do
|
14
|
+
Capybara.app_host = "http://capybara1.elabs.se"
|
15
|
+
@session.visit('http://capybara-testapp.heroku.com/host')
|
16
|
+
@session.body.should include('Current host is http://capybara-testapp.heroku.com')
|
17
|
+
@session.current_host.should == 'http://capybara-testapp.heroku.com'
|
18
|
+
@session.visit('/host')
|
19
|
+
@session.body.should include('Current host is http://capybara1.elabs.se')
|
20
|
+
@session.current_host.should == 'http://capybara1.elabs.se'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is affected by setting Capybara.app_host" do
|
24
|
+
Capybara.app_host = "http://capybara-testapp.heroku.com"
|
25
|
+
@session.visit('/host')
|
26
|
+
@session.body.should include('Current host is http://capybara-testapp.heroku.com')
|
27
|
+
@session.current_host.should == 'http://capybara-testapp.heroku.com'
|
28
|
+
Capybara.app_host = "http://capybara1.elabs.se"
|
29
|
+
@session.visit('/host')
|
30
|
+
@session.body.should include('Current host is http://capybara1.elabs.se')
|
31
|
+
@session.current_host.should == 'http://capybara1.elabs.se'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is unaffected by following a relative link" do
|
35
|
+
@session.visit('http://capybara-testapp.heroku.com/host_links')
|
36
|
+
@session.click_link('Relative Host')
|
37
|
+
@session.body.should include('Current host is http://capybara-testapp.heroku.com')
|
38
|
+
@session.current_host.should == 'http://capybara-testapp.heroku.com'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "is affected by following an absolute link" do
|
42
|
+
@session.visit('http://capybara-testapp.heroku.com/host_links')
|
43
|
+
@session.click_link('Absolute Host')
|
44
|
+
@session.body.should include('Current host is http://capybara2.elabs.se')
|
45
|
+
@session.current_host.should == 'http://capybara2.elabs.se'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "is unaffected by posting through a relative form" do
|
49
|
+
@session.visit('http://capybara-testapp.heroku.com/host_links')
|
50
|
+
@session.click_button('Relative Host')
|
51
|
+
@session.body.should include('Current host is http://capybara-testapp.heroku.com')
|
52
|
+
@session.current_host.should == 'http://capybara-testapp.heroku.com'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "is affected by posting through an absolute form" do
|
56
|
+
@session.visit('http://capybara-testapp.heroku.com/host_links')
|
57
|
+
@session.click_button('Absolute Host')
|
58
|
+
@session.body.should include('Current host is http://capybara2.elabs.se')
|
59
|
+
@session.current_host.should == 'http://capybara2.elabs.se'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "is affected by following a redirect" do
|
63
|
+
@session.visit('http://capybara-testapp.heroku.com/redirect_secure')
|
64
|
+
@session.body.should include('Current host is https://capybara-testapp.heroku.com')
|
65
|
+
@session.current_host.should == 'https://capybara-testapp.heroku.com'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
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,125 @@
|
|
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 text field respecting its maxlength attribute" do
|
74
|
+
@session.fill_in('Zipcode', :with => '52071350')
|
75
|
+
@session.click_button('awesome')
|
76
|
+
extract_results(@session)['zipcode'].should == '52071'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should fill in a password field by name" do
|
80
|
+
@session.fill_in('form[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 label" do
|
86
|
+
@session.fill_in('Password', :with => 'supasikrit')
|
87
|
+
@session.click_button('awesome')
|
88
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should fill in a password field by name" do
|
92
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
93
|
+
@session.click_button('awesome')
|
94
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should prefer exact matches over partial matches" do
|
98
|
+
@session.fill_in('Name', :with => 'Ford Prefect')
|
99
|
+
@session.click_button('awesome')
|
100
|
+
extract_results(@session)['name'].should == 'Ford Prefect'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should throw an exception if a hash containing 'with' is not provided" do
|
104
|
+
lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
context "with ignore_hidden_fields" do
|
108
|
+
before { Capybara.ignore_hidden_elements = true }
|
109
|
+
after { Capybara.ignore_hidden_elements = false }
|
110
|
+
it "should not find a hidden field" do
|
111
|
+
running do
|
112
|
+
@session.fill_in('Super Secret', :with => '777')
|
113
|
+
end.should raise_error(Capybara::ElementNotFound)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "with a locator that doesn't exist" do
|
118
|
+
it "should raise an error" do
|
119
|
+
running do
|
120
|
+
@session.fill_in('does not exist', :with => 'Blah blah')
|
121
|
+
end.should raise_error(Capybara::ElementNotFound)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
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
|