david-capybara 0.3.8
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 +87 -0
- data/README.rdoc +389 -0
- data/lib/capybara.rb +52 -0
- data/lib/capybara/cucumber.rb +32 -0
- data/lib/capybara/driver/base.rb +48 -0
- data/lib/capybara/driver/celerity_driver.rb +143 -0
- data/lib/capybara/driver/culerity_driver.rb +25 -0
- data/lib/capybara/driver/rack_test_driver.rb +272 -0
- data/lib/capybara/driver/selenium_driver.rb +156 -0
- data/lib/capybara/dsl.rb +60 -0
- data/lib/capybara/node.rb +60 -0
- data/lib/capybara/rails.rb +17 -0
- data/lib/capybara/save_and_open_page.rb +33 -0
- data/lib/capybara/searchable.rb +54 -0
- data/lib/capybara/server.rb +114 -0
- data/lib/capybara/session.rb +262 -0
- data/lib/capybara/spec/driver.rb +162 -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/canvas.jpg +0 -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 +81 -0
- data/lib/capybara/spec/session/all_spec.rb +69 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +64 -0
- data/lib/capybara/spec/session/check_spec.rb +67 -0
- data/lib/capybara/spec/session/choose_spec.rb +26 -0
- data/lib/capybara/spec/session/click_button_spec.rb +236 -0
- data/lib/capybara/spec/session/click_link_spec.rb +118 -0
- data/lib/capybara/spec/session/click_spec.rb +24 -0
- data/lib/capybara/spec/session/current_url_spec.rb +8 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +108 -0
- data/lib/capybara/spec/session/find_button_spec.rb +16 -0
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -0
- data/lib/capybara/spec/session/find_field_spec.rb +22 -0
- data/lib/capybara/spec/session/find_link_spec.rb +17 -0
- data/lib/capybara/spec/session/find_spec.rb +57 -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 +107 -0
- data/lib/capybara/spec/session/has_field_spec.rb +96 -0
- data/lib/capybara/spec/session/has_link_spec.rb +33 -0
- data/lib/capybara/spec/session/has_select_spec.rb +89 -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 +204 -0
- data/lib/capybara/spec/session/locate_spec.rb +59 -0
- data/lib/capybara/spec/session/select_spec.rb +83 -0
- data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
- data/lib/capybara/spec/session/unselect_spec.rb +54 -0
- data/lib/capybara/spec/session/within_spec.rb +153 -0
- data/lib/capybara/spec/test_app.rb +75 -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 +235 -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/postback.erb +13 -0
- data/lib/capybara/spec/views/tables.erb +122 -0
- data/lib/capybara/spec/views/with_html.erb +46 -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/version.rb +3 -0
- data/lib/capybara/wait_until.rb +28 -0
- data/lib/capybara/xpath.rb +180 -0
- data/spec/capybara_spec.rb +18 -0
- data/spec/driver/celerity_driver_spec.rb +16 -0
- data/spec/driver/culerity_driver_spec.rb +12 -0
- data/spec/driver/rack_test_driver_spec.rb +17 -0
- data/spec/driver/remote_culerity_driver_spec.rb +23 -0
- data/spec/driver/remote_selenium_driver_spec.rb +18 -0
- data/spec/driver/selenium_driver_spec.rb +11 -0
- data/spec/dsl_spec.rb +140 -0
- data/spec/save_and_open_page_spec.rb +43 -0
- data/spec/searchable_spec.rb +66 -0
- data/spec/server_spec.rb +53 -0
- data/spec/session/celerity_session_spec.rb +27 -0
- data/spec/session/culerity_session_spec.rb +25 -0
- data/spec/session/rack_test_session_spec.rb +33 -0
- data/spec/session/selenium_session_spec.rb +25 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/wait_until_spec.rb +28 -0
- data/spec/xpath_spec.rb +180 -0
- metadata +260 -0
|
@@ -0,0 +1,118 @@
|
|
|
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 do nothing on anchor links" do
|
|
84
|
+
@session.fill_in("test_field", :with => 'blah')
|
|
85
|
+
@session.click_link('Anchor')
|
|
86
|
+
@session.find_field("test_field").value.should == 'blah'
|
|
87
|
+
@session.click_link('Blank Anchor')
|
|
88
|
+
@session.find_field("test_field").value.should == 'blah'
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should do nothing on URL+anchor links for the same page" do
|
|
92
|
+
@session.fill_in("test_field", :with => 'blah')
|
|
93
|
+
@session.click_link('Anchor on same page')
|
|
94
|
+
@session.find_field("test_field").value.should == 'blah'
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should follow link on URL+anchor links for a different page" do
|
|
98
|
+
@session.click_link('Anchor on different page')
|
|
99
|
+
@session.body.should include('Bar')
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "should follow an image map link with alt attribute" do
|
|
103
|
+
@session.click_link('Image Map')
|
|
104
|
+
@session.body.should include('Bar')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should follow an image map link using the coordinates" do
|
|
108
|
+
@session.click_link('109,240,129,259')
|
|
109
|
+
@session.body.should include('Bar')
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "raise an error with links with no href" do
|
|
113
|
+
running do
|
|
114
|
+
@session.click_link('No Href')
|
|
115
|
+
end.should raise_error(Capybara::ElementNotFound)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
|
@@ -0,0 +1,108 @@
|
|
|
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 favour exact label matches over partial matches" do
|
|
26
|
+
@session.fill_in('Name', :with => 'Harry Jones')
|
|
27
|
+
@session.click_button('awesome')
|
|
28
|
+
extract_results(@session)['name'].should == 'Harry Jones'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should fill in a textarea by id" do
|
|
32
|
+
@session.fill_in('form_description', :with => 'Texty text')
|
|
33
|
+
@session.click_button('awesome')
|
|
34
|
+
extract_results(@session)['description'].should == 'Texty text'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should fill in a textarea by label" do
|
|
38
|
+
@session.fill_in('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 name" do
|
|
44
|
+
@session.fill_in('form[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 password field by id" do
|
|
50
|
+
@session.fill_in('form_password', :with => 'supasikrit')
|
|
51
|
+
@session.click_button('awesome')
|
|
52
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should fill in a field with a custom type" do
|
|
56
|
+
pending "selenium doesn't seem to find custom fields" if @session.mode == :selenium
|
|
57
|
+
@session.fill_in('Schmooo', :with => 'Schmooo is the game')
|
|
58
|
+
@session.click_button('awesome')
|
|
59
|
+
extract_results(@session)['schmooo'].should == 'Schmooo is the game'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should fill in a password field by name" do
|
|
63
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
|
64
|
+
@session.click_button('awesome')
|
|
65
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should fill in a password field by label" do
|
|
69
|
+
@session.fill_in('Password', :with => 'supasikrit')
|
|
70
|
+
@session.click_button('awesome')
|
|
71
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should fill in a password field by name" do
|
|
75
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
|
76
|
+
@session.click_button('awesome')
|
|
77
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should prefer exact matches over partial matches" do
|
|
81
|
+
@session.fill_in('Name', :with => 'Ford Prefect')
|
|
82
|
+
@session.click_button('awesome')
|
|
83
|
+
extract_results(@session)['name'].should == 'Ford Prefect'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should throw an exception if a hash containing 'with' is not provided" do
|
|
87
|
+
lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context "with ignore_hidden_fields" do
|
|
91
|
+
before { Capybara.ignore_hidden_elements = true }
|
|
92
|
+
after { Capybara.ignore_hidden_elements = false }
|
|
93
|
+
it "should not find a hidden field" do
|
|
94
|
+
running do
|
|
95
|
+
@session.fill_in('Super Secret', :with => '777')
|
|
96
|
+
end.should raise_error(Capybara::ElementNotFound)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "with a locator that doesn't exist" do
|
|
101
|
+
it "should raise an error" do
|
|
102
|
+
running do
|
|
103
|
+
@session.fill_in('does not exist', :with => 'Blah blah')
|
|
104
|
+
end.should raise_error(Capybara::ElementNotFound)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
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 return nil if the field doesn't exist" do
|
|
13
|
+
@session.find_button('Does not exist').should be_nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
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 return nil if no element with id is found" do
|
|
13
|
+
@session.find_by_id('nothing_with_this_id').should be_nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
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 be nil if the field doesn't exist" do
|
|
14
|
+
@session.find_field('Does not exist').should be_nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should be aliased as 'field_labeled' for webrat compatibility" do
|
|
18
|
+
@session.field_labeled('Dog').value.should == 'dog'
|
|
19
|
+
@session.field_labeled('Does not exist').should be_nil
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
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 == "/with_simple_html"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should return nil if the field doesn't exist" do
|
|
14
|
+
@session.find_link('Does not exist').should be_nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
shared_examples_for "find" do
|
|
2
|
+
describe '#find' 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.find('//h1').text.should == 'This is a test'
|
|
9
|
+
@session.find("//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.find(:css, 'h1').text.should == 'This is a test'
|
|
15
|
+
@session.find(: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.find(:xpath, '//h1').text.should == 'This is a test'
|
|
22
|
+
@session.find(: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.find('h1').text.should == 'This is a test'
|
|
30
|
+
@session.find("input[id='test_field']")[:value].should == 'monkey'
|
|
31
|
+
end
|
|
32
|
+
after { Capybara.default_selector = :xpath }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should return nil when nothing was found" do
|
|
36
|
+
@session.find('//div[@id="nosuchthing"]').should be_nil
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should accept an XPath instance and respect the order of paths" do
|
|
40
|
+
@session.visit('/form')
|
|
41
|
+
@xpath = Capybara::XPath.text_field('Name')
|
|
42
|
+
@session.find(@xpath).value.should == 'John Smith'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "within a scope" do
|
|
46
|
+
before do
|
|
47
|
+
@session.visit('/with_scope')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should find the first element using the given locator" do
|
|
51
|
+
@session.within(:xpath, "//div[@id='for_bar']") do
|
|
52
|
+
@session.find('//li').text.should =~ /With Simple HTML/
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
shared_examples_for "has_button" do
|
|
2
|
+
describe '#has_button?' do
|
|
3
|
+
before do
|
|
4
|
+
@session.visit('/form')
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
it "should be true if the given button is on the page" do
|
|
8
|
+
@session.should have_button('med')
|
|
9
|
+
@session.should have_button('crap321')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should be false if the given button is not on the page" do
|
|
13
|
+
@session.should_not have_button('monkey')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#has_no_button?' do
|
|
18
|
+
before do
|
|
19
|
+
@session.visit('/form')
|
|
20
|
+
end
|
|
21
|
+
|
|
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
|
+
|
|
27
|
+
it "should be false if the given button is not on the page" do
|
|
28
|
+
@session.should have_no_button('monkey')
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
shared_examples_for "has_content" do
|
|
2
|
+
describe '#has_content?' do
|
|
3
|
+
it "should be true if the given content is on the page at least once" do
|
|
4
|
+
@session.visit('/with_html')
|
|
5
|
+
@session.should have_content('est')
|
|
6
|
+
@session.should have_content('Lorem')
|
|
7
|
+
@session.should have_content('Redirect')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should be true if scoped to an element which has the content" do
|
|
11
|
+
@session.visit('/with_html')
|
|
12
|
+
@session.within("//a[@title='awesome title']") do
|
|
13
|
+
@session.should have_content('labore')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should be false if scoped to an element which does not have the content" do
|
|
18
|
+
@session.visit('/with_html')
|
|
19
|
+
@session.within("//a[@title='awesome title']") do
|
|
20
|
+
@session.should_not have_content('monkey')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should ignore tags" do
|
|
25
|
+
@session.visit('/with_html')
|
|
26
|
+
@session.should_not have_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
|
|
27
|
+
@session.should have_content('exercitation ullamco laboris')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should ignore extra whitespace and newlines" do
|
|
31
|
+
@session.visit('/with_html')
|
|
32
|
+
@session.should have_content('text with whitespace')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should be false if the given content is not on the page" do
|
|
36
|
+
@session.visit('/with_html')
|
|
37
|
+
@session.should_not have_content('xxxxyzzz')
|
|
38
|
+
@session.should_not have_content('monkey')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'should handle single quotes in the content' do
|
|
42
|
+
@session.visit('/with-quotes')
|
|
43
|
+
@session.should have_content("can't")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'should handle double quotes in the content' do
|
|
47
|
+
@session.visit('/with-quotes')
|
|
48
|
+
@session.should have_content(%q{"No," he said})
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'should handle mixed single and double quotes in the content' do
|
|
52
|
+
@session.visit('/with-quotes')
|
|
53
|
+
@session.should have_content(%q{"you can't do that."})
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#has_no_content?' do
|
|
58
|
+
it "should be false if the given content is on the page at least once" do
|
|
59
|
+
@session.visit('/with_html')
|
|
60
|
+
@session.should_not have_no_content('est')
|
|
61
|
+
@session.should_not have_no_content('Lorem')
|
|
62
|
+
@session.should_not have_no_content('Redirect')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should be false if scoped to an element which has the content" do
|
|
66
|
+
@session.visit('/with_html')
|
|
67
|
+
@session.within("//a[@title='awesome title']") do
|
|
68
|
+
@session.should_not have_no_content('labore')
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should be true if scoped to an element which does not have the content" do
|
|
73
|
+
@session.visit('/with_html')
|
|
74
|
+
@session.within("//a[@title='awesome title']") do
|
|
75
|
+
@session.should have_no_content('monkey')
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should ignore tags" do
|
|
80
|
+
@session.visit('/with_html')
|
|
81
|
+
@session.should have_no_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
|
|
82
|
+
@session.should_not have_no_content('exercitation ullamco laboris')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should be true if the given content is not on the page" do
|
|
86
|
+
@session.visit('/with_html')
|
|
87
|
+
@session.should have_no_content('xxxxyzzz')
|
|
88
|
+
@session.should have_no_content('monkey')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'should handle single quotes in the content' do
|
|
92
|
+
@session.visit('/with-quotes')
|
|
93
|
+
@session.should_not have_no_content("can't")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'should handle double quotes in the content' do
|
|
97
|
+
@session.visit('/with-quotes')
|
|
98
|
+
@session.should_not have_no_content(%q{"No," he said})
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should handle mixed single and double quotes in the content' do
|
|
102
|
+
@session.visit('/with-quotes')
|
|
103
|
+
@session.should_not have_no_content(%q{"you can't do that."})
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|