capybara 0.3.0 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +4 -0
- data/README.rdoc +45 -5
- data/lib/capybara.rb +11 -4
- data/lib/capybara/driver/base.rb +3 -0
- data/lib/capybara/driver/celerity_driver.rb +44 -9
- data/lib/capybara/driver/rack_test_driver.rb +80 -16
- data/lib/capybara/driver/selenium_driver.rb +41 -9
- data/lib/capybara/dsl.rb +4 -10
- data/lib/capybara/node.rb +8 -0
- data/lib/capybara/rails.rb +8 -2
- data/lib/capybara/save_and_open_page.rb +5 -1
- data/lib/capybara/searchable.rb +17 -9
- data/lib/capybara/server.rb +35 -23
- data/lib/capybara/session.rb +91 -22
- data/lib/capybara/xpath.rb +66 -27
- data/spec/driver/celerity_driver_spec.rb +2 -2
- data/spec/driver/culerity_driver_spec.rb +1 -2
- data/spec/driver/rack_test_driver_spec.rb +0 -1
- data/spec/driver/remote_culerity_driver_spec.rb +9 -5
- data/spec/driver/selenium_driver_spec.rb +0 -1
- data/spec/drivers_spec.rb +24 -32
- data/spec/dsl/all_spec.rb +56 -25
- data/spec/dsl/attach_file_spec.rb +49 -51
- data/spec/dsl/check_spec.rb +12 -1
- data/spec/dsl/choose_spec.rb +19 -21
- data/spec/dsl/click_button_spec.rb +140 -87
- data/spec/dsl/click_link_spec.rb +88 -68
- data/spec/dsl/click_spec.rb +20 -22
- data/spec/dsl/current_url_spec.rb +6 -8
- data/spec/dsl/fill_in_spec.rb +75 -67
- data/spec/dsl/find_button_spec.rb +12 -14
- data/spec/dsl/find_by_id_spec.rb +16 -0
- data/spec/dsl/find_field_spec.rb +17 -19
- data/spec/dsl/find_link_spec.rb +13 -15
- data/spec/dsl/find_spec.rb +44 -23
- data/spec/dsl/has_button_spec.rb +32 -0
- data/spec/dsl/has_content_spec.rb +79 -81
- data/spec/dsl/has_css_spec.rb +81 -83
- data/spec/dsl/has_field_spec.rb +96 -0
- data/spec/dsl/has_link_spec.rb +33 -0
- data/spec/dsl/has_xpath_spec.rb +97 -89
- data/spec/dsl/locate_spec.rb +47 -26
- data/spec/dsl/select_spec.rb +61 -17
- data/spec/dsl/uncheck_spec.rb +17 -25
- data/spec/dsl/within_spec.rb +112 -104
- data/spec/public/test.js +3 -0
- data/spec/searchable_spec.rb +1 -1
- data/spec/server_spec.rb +7 -7
- data/spec/session/celerity_session_spec.rb +2 -2
- data/spec/session/culerity_session_spec.rb +1 -1
- data/spec/session_spec.rb +7 -0
- data/spec/session_with_javascript_support_spec.rb +139 -120
- data/spec/spec_helper.rb +7 -2
- data/spec/test_app.rb +8 -4
- data/spec/views/form.erb +50 -2
- data/spec/views/tables.erb +61 -1
- data/spec/views/with_html.erb +8 -2
- data/spec/views/with_js.erb +4 -0
- data/spec/xpath_spec.rb +17 -0
- metadata +6 -2
data/spec/dsl/click_link_spec.rb
CHANGED
@@ -1,88 +1,108 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
shared_examples_for "click_link" do
|
2
|
+
describe '#click_link' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
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')
|
13
11
|
end
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should prefer exact matches over partial matches" do
|
27
|
-
@session.click_link('A link')
|
28
|
-
@session.body.should include('Bar')
|
29
|
-
end
|
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')
|
30
23
|
end
|
31
24
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@session.body.should include('Bar')
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should accept partial matches" do
|
39
|
-
@session.click_link('some tit')
|
40
|
-
@session.body.should include('Bar')
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should prefer exact matches over partial matches" do
|
44
|
-
@session.click_link('a fine link')
|
45
|
-
@session.body.should include('Bar')
|
46
|
-
end
|
25
|
+
it "should prefer exact matches over partial matches" do
|
26
|
+
@session.click_link('A link')
|
27
|
+
@session.body.should include('Bar')
|
47
28
|
end
|
29
|
+
end
|
48
30
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end.should raise_error(Capybara::ElementNotFound)
|
54
|
-
end
|
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')
|
55
35
|
end
|
56
36
|
|
57
|
-
it "should
|
58
|
-
@session.click_link('
|
59
|
-
@session.body.should include('
|
37
|
+
it "should accept partial matches" do
|
38
|
+
@session.click_link('some tit')
|
39
|
+
@session.body.should include('Bar')
|
60
40
|
end
|
61
41
|
|
62
|
-
it "should
|
63
|
-
@session.
|
64
|
-
@session.
|
65
|
-
@session.find_field("test_field").value.should == 'blah'
|
66
|
-
@session.click_link('Blank Anchor')
|
67
|
-
@session.find_field("test_field").value.should == 'blah'
|
42
|
+
it "should prefer exact matches over partial matches" do
|
43
|
+
@session.click_link('a fine link')
|
44
|
+
@session.body.should include('Bar')
|
68
45
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
@session.
|
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')
|
74
52
|
end
|
75
|
-
|
76
|
-
it "should
|
77
|
-
@session.click_link('
|
53
|
+
|
54
|
+
it "should take user to the linked page" do
|
55
|
+
@session.click_link('some imag')
|
78
56
|
@session.body.should include('Bar')
|
79
57
|
end
|
80
|
-
|
81
|
-
it "
|
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
|
82
67
|
running do
|
83
|
-
@session.click_link('
|
68
|
+
@session.click_link('does not exist')
|
84
69
|
end.should raise_error(Capybara::ElementNotFound)
|
85
70
|
end
|
86
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 "raise an error with links with no href" do
|
103
|
+
running do
|
104
|
+
@session.click_link('No Href')
|
105
|
+
end.should raise_error(Capybara::ElementNotFound)
|
106
|
+
end
|
87
107
|
end
|
88
|
-
end
|
108
|
+
end
|
data/spec/dsl/click_spec.rb
CHANGED
@@ -1,26 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
5
17
|
@session.visit('/with_html')
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
it "should click on a button" do
|
11
|
-
@session.visit('/form')
|
12
|
-
@session.click('awe123')
|
13
|
-
extract_results(@session)['first_name'].should == 'John'
|
14
|
-
end
|
15
|
-
|
16
|
-
context "with a locator that doesn't exist" do
|
17
|
-
it "should raise an error" do
|
18
|
-
@session.visit('/with_html')
|
19
|
-
running do
|
20
|
-
@session.click('does not exist')
|
21
|
-
end.should raise_error(Capybara::ElementNotFound)
|
22
|
-
end
|
18
|
+
running do
|
19
|
+
@session.click('does not exist')
|
20
|
+
end.should raise_error(Capybara::ElementNotFound)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
26
|
-
end
|
24
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@session.current_url.should =~ %r(http://[^/]+/form)
|
7
|
-
end
|
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)
|
8
6
|
end
|
9
7
|
end
|
10
|
-
end
|
8
|
+
end
|
data/spec/dsl/fill_in_spec.rb
CHANGED
@@ -1,83 +1,91 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
shared_examples_for "fill_in" do
|
2
|
+
describe "#fill_in" do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
it "should fill in a password field by label" do
|
56
|
+
@session.fill_in('Password', :with => 'supasikrit')
|
57
|
+
@session.click_button('awesome')
|
58
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
it "should fill in a password field by name" do
|
62
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
63
|
+
@session.click_button('awesome')
|
64
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should prefer exact matches over partial matches" do
|
68
|
+
@session.fill_in('Name', :with => 'Ford Prefect')
|
69
|
+
@session.click_button('awesome')
|
70
|
+
extract_results(@session)['name'].should == 'Ford Prefect'
|
71
|
+
end
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
73
|
+
context "with ignore_hidden_fields" do
|
74
|
+
before { Capybara.ignore_hidden_elements = true }
|
75
|
+
after { Capybara.ignore_hidden_elements = false }
|
76
|
+
it "should not find a hidden field" do
|
77
|
+
running do
|
78
|
+
@session.fill_in('Super Secret', :with => '777')
|
79
|
+
end.should raise_error(Capybara::ElementNotFound)
|
72
80
|
end
|
81
|
+
end
|
73
82
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
83
|
+
context "with a locator that doesn't exist" do
|
84
|
+
it "should raise an error" do
|
85
|
+
running do
|
86
|
+
@session.fill_in('does not exist', :with => 'Blah blah')
|
87
|
+
end.should raise_error(Capybara::ElementNotFound)
|
80
88
|
end
|
81
89
|
end
|
82
90
|
end
|
83
|
-
end
|
91
|
+
end
|
@@ -1,18 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
shared_examples_for "find_button" do
|
2
|
+
describe '#find_button' do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
it "should return nil if the field doesn't exist" do
|
13
|
+
@session.find_button('Does not exist').should be_nil
|
16
14
|
end
|
17
15
|
end
|
18
|
-
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
|