capybara 0.3.0 → 0.3.5
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/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
@@ -2,7 +2,7 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
if RUBY_PLATFORM =~ /java/
|
4
4
|
describe Capybara::Driver::Celerity do
|
5
|
-
before do
|
5
|
+
before(:all) do
|
6
6
|
@driver = Capybara::Driver::Celerity.new(TestApp)
|
7
7
|
end
|
8
8
|
|
@@ -14,4 +14,4 @@ if RUBY_PLATFORM =~ /java/
|
|
14
14
|
end
|
15
15
|
else
|
16
16
|
puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
|
17
|
-
end
|
17
|
+
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe Capybara::Driver::Culerity do
|
4
|
-
before do
|
4
|
+
before(:all) do
|
5
5
|
@driver = Capybara::Driver::Culerity.new(TestApp)
|
6
6
|
end
|
7
7
|
|
8
8
|
it_should_behave_like "driver"
|
9
9
|
it_should_behave_like "driver with javascript support"
|
10
10
|
it_should_behave_like "driver with header support"
|
11
|
-
it_should_behave_like "driver with node path support"
|
12
11
|
|
13
12
|
end
|
@@ -1,19 +1,23 @@
|
|
1
1
|
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe Capybara::Driver::Culerity do
|
4
|
-
before do
|
5
|
-
@driver = Capybara::Driver::Culerity.new(TestApp)
|
6
|
-
end
|
7
|
-
|
8
4
|
before(:all) do
|
9
5
|
Capybara.app_host = "http://capybara-testapp.heroku.com"
|
6
|
+
Capybara.run_server = false
|
7
|
+
@driver = Capybara::Driver::Culerity.new(TestApp)
|
10
8
|
end
|
11
9
|
|
12
10
|
after(:all) do
|
13
11
|
Capybara.app_host = nil
|
12
|
+
Capybara.run_server = true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should navigate to a fully qualified remote page" do
|
16
|
+
@driver.visit('http://elabs.se/contact')
|
17
|
+
@driver.body.should include('Edithouse eLabs AB')
|
14
18
|
end
|
15
19
|
|
16
20
|
it_should_behave_like "driver"
|
17
21
|
it_should_behave_like "driver with javascript support"
|
18
22
|
it_should_behave_like "driver with header support"
|
19
|
-
end
|
23
|
+
end
|
data/spec/drivers_spec.rb
CHANGED
@@ -47,6 +47,10 @@ shared_examples_for 'driver' do
|
|
47
47
|
@driver.find('//a')[1][:rel].should be_nil
|
48
48
|
end
|
49
49
|
|
50
|
+
it "should extract boolean node attributes" do
|
51
|
+
@driver.find('//input[@id="checked_field"]')[0][:checked].should be_true
|
52
|
+
end
|
53
|
+
|
50
54
|
it "should allow assignment of field value" do
|
51
55
|
@driver.find('//input').first.value.should == 'monkey'
|
52
56
|
@driver.find('//input').first.set('gorilla')
|
@@ -68,6 +72,26 @@ shared_examples_for 'driver' do
|
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
75
|
+
describe "node relative searching" do
|
76
|
+
before do
|
77
|
+
@driver.visit('/tables')
|
78
|
+
@node = @driver.find('//body').first
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should be able to navigate/search child node" do
|
82
|
+
@node.all('//table').size.should == 5
|
83
|
+
@node.find('//form').all('.//table').size.should == 1
|
84
|
+
@node.find('//form').find('.//table//caption').text.should == 'Agent'
|
85
|
+
if @driver.class == Capybara::Driver::Selenium
|
86
|
+
pending("Selenium gets this wrong, see http://code.google.com/p/selenium/issues/detail?id=403") do
|
87
|
+
@node.find('//form').all('//table').size.should == 5
|
88
|
+
end
|
89
|
+
else
|
90
|
+
@node.find('//form').all('//table').size.should == 5
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
71
95
|
end
|
72
96
|
|
73
97
|
shared_examples_for "driver with javascript support" do
|
@@ -93,7 +117,6 @@ shared_examples_for "driver with javascript support" do
|
|
93
117
|
@driver.evaluate_script('1+1').should == 2
|
94
118
|
end
|
95
119
|
end
|
96
|
-
|
97
120
|
end
|
98
121
|
|
99
122
|
shared_examples_for "driver with header support" do
|
@@ -102,34 +125,3 @@ shared_examples_for "driver with header support" do
|
|
102
125
|
@driver.response_headers['Content-Type'].should == 'text/html'
|
103
126
|
end
|
104
127
|
end
|
105
|
-
|
106
|
-
shared_examples_for "driver with node path support" do
|
107
|
-
describe "node relative searching" do
|
108
|
-
before do
|
109
|
-
@driver.visit('/tables')
|
110
|
-
@node = @driver.find('//body').first
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should be able to navigate/search child nodes" do
|
114
|
-
@node.all('//table').size.should == 3
|
115
|
-
@node.find('//form').all('//table').size.should == 1
|
116
|
-
@node.find('//form').find('//table//caption').text.should == 'Agent'
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
shared_examples_for "driver without node path support" do
|
122
|
-
describe "node relative searching" do
|
123
|
-
before do
|
124
|
-
@driver.visit('/tables')
|
125
|
-
@node = @driver.find('//body').first
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should get NotSupportedByDriverError" do
|
129
|
-
running do
|
130
|
-
@node.all('//form')
|
131
|
-
end.should raise_error(Capybara::NotSupportedByDriverError)
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
end
|
data/spec/dsl/all_spec.rb
CHANGED
@@ -1,38 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
shared_examples_for "all" do
|
2
|
+
describe '#all' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should find all elements using the given locator" do
|
8
|
+
@session.all('//p').should have(3).elements
|
9
|
+
@session.all('//h1').first.text.should == 'This is a test'
|
10
|
+
@session.all("//input[@id='test_field']").first[:value].should == 'monkey'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return an empty array when nothing was found" do
|
14
|
+
@session.all('//div[@id="nosuchthing"]').should be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should accept an XPath instance" do
|
18
|
+
@session.visit('/form')
|
19
|
+
@xpath = Capybara::XPath.text_field('Name')
|
20
|
+
@result = @session.all(@xpath).map { |r| r.value }
|
21
|
+
@result.should include('Smith', 'John', 'John Smith')
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with css selectors" do
|
25
|
+
it "should find the first element using the given locator" do
|
26
|
+
@session.all(:css, 'h1').first.text.should == 'This is a test'
|
27
|
+
@session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
|
6
28
|
end
|
29
|
+
end
|
7
30
|
|
8
|
-
|
9
|
-
|
10
|
-
@session.all('//h1').first.text.should == 'This is a test'
|
11
|
-
@session.all("//input[@id='test_field']").first[:value].should == 'monkey'
|
31
|
+
context "with xpath selectors" do
|
32
|
+
it "should find the first element using the given locator" do
|
33
|
+
@session.all(:xpath, '//h1').first.text.should == 'This is a test'
|
34
|
+
@session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
|
12
35
|
end
|
36
|
+
end
|
13
37
|
|
14
|
-
|
15
|
-
|
38
|
+
context "with css as default selector" do
|
39
|
+
before { Capybara.default_selector = :css }
|
40
|
+
it "should find the first element using the given locator" do
|
41
|
+
@session.all('h1').first.text.should == 'This is a test'
|
42
|
+
@session.all("input[id='test_field']").first[:value].should == 'monkey'
|
16
43
|
end
|
44
|
+
after { Capybara.default_selector = :xpath }
|
45
|
+
end
|
17
46
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@
|
22
|
-
@
|
47
|
+
context "with visible filter" do
|
48
|
+
after { Capybara.ignore_hidden_elements = false }
|
49
|
+
it "should only find visible nodes" do
|
50
|
+
@session.all("//a[@title='awesome title']").should have(2).elements
|
51
|
+
@session.all("//a[@title='awesome title']", :visible => true).should have(1).elements
|
52
|
+
Capybara.ignore_hidden_elements = true
|
53
|
+
@session.all("//a[@title='awesome title']").should have(1).elements
|
23
54
|
end
|
55
|
+
end
|
24
56
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
57
|
+
context "within a scope" do
|
58
|
+
before do
|
59
|
+
@session.visit('/with_scope')
|
60
|
+
end
|
29
61
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
62
|
+
it "should find any element using the given locator" do
|
63
|
+
@session.within(:xpath, "//div[@id='for_bar']") do
|
64
|
+
@session.all('//li').should have(2).elements
|
34
65
|
end
|
35
66
|
end
|
36
67
|
end
|
37
68
|
end
|
38
|
-
end
|
69
|
+
end
|
@@ -1,66 +1,64 @@
|
|
1
|
-
|
2
|
-
shared_examples_for "attach_file" do
|
1
|
+
shared_examples_for "attach_file" do
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe "#attach_file" do
|
4
|
+
before do
|
5
|
+
@session.visit('/form')
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
context "with normal form" do
|
9
|
+
it "should set a file path by id" do
|
10
|
+
@session.attach_file "form_image", __FILE__
|
11
|
+
@session.click_button('awesome')
|
12
|
+
extract_results(@session)['image'].should == File.basename(__FILE__)
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
15
|
+
it "should set a file path by label" do
|
16
|
+
@session.attach_file "Image", __FILE__
|
17
|
+
@session.click_button('awesome')
|
18
|
+
extract_results(@session)['image'].should == File.basename(__FILE__)
|
21
19
|
end
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
context "with multipart form" do
|
23
|
+
before do
|
24
|
+
@test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
|
25
|
+
@test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
it "should set a file path by id" do
|
29
|
+
@session.attach_file "form_document", @test_file_path
|
30
|
+
@session.click_button('Upload')
|
31
|
+
@session.body.should include(File.read(@test_file_path))
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
it "should set a file path by label" do
|
35
|
+
@session.attach_file "Document", @test_file_path
|
36
|
+
@session.click_button('Upload')
|
37
|
+
@session.body.should include(File.read(@test_file_path))
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
it "should not break if no file is submitted" do
|
41
|
+
@session.click_button('Upload')
|
42
|
+
@session.body.should include('No file uploaded')
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
it "should send content type text/plain when uploading a text file" do
|
46
|
+
@session.attach_file "Document", @test_file_path
|
47
|
+
@session.click_button 'Upload'
|
48
|
+
@session.body.should include('text/plain')
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
51
|
+
it "should send content type image/jpeg when uploading an image" do
|
52
|
+
@session.attach_file "Document", @test_jpg_file_path
|
53
|
+
@session.click_button 'Upload'
|
54
|
+
@session.body.should include('image/jpeg')
|
57
55
|
end
|
56
|
+
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
58
|
+
context "with a locator that doesn't exist" do
|
59
|
+
it "should raise an error" do
|
60
|
+
running { @session.attach_file('does not exist', 'foo.txt') }.should raise_error(Capybara::ElementNotFound)
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|
66
|
-
end
|
64
|
+
end
|
data/spec/dsl/check_spec.rb
CHANGED
@@ -5,6 +5,17 @@ module CheckSpec
|
|
5
5
|
before do
|
6
6
|
@session.visit('/form')
|
7
7
|
end
|
8
|
+
|
9
|
+
describe "'checked' attribute" do
|
10
|
+
it "should be true if checked" do
|
11
|
+
@session.check("Terms of Use")
|
12
|
+
@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be false if unchecked" do
|
16
|
+
@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
|
17
|
+
end
|
18
|
+
end
|
8
19
|
|
9
20
|
it "should check a checkbox by id" do
|
10
21
|
@session.check("form_pets_cat")
|
@@ -25,4 +36,4 @@ module CheckSpec
|
|
25
36
|
end
|
26
37
|
end
|
27
38
|
end
|
28
|
-
end
|
39
|
+
end
|
data/spec/dsl/choose_spec.rb
CHANGED
@@ -1,28 +1,26 @@
|
|
1
|
-
|
2
|
-
shared_examples_for "choose" do
|
1
|
+
shared_examples_for "choose" do
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe "#choose" do
|
4
|
+
before do
|
5
|
+
@session.visit('/form')
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
it "should choose a radio button by id" do
|
9
|
+
@session.choose("gender_male")
|
10
|
+
@session.click_button('awesome')
|
11
|
+
extract_results(@session)['gender'].should == 'male'
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
it "should choose a radio button by label" do
|
15
|
+
@session.choose("Both")
|
16
|
+
@session.click_button('awesome')
|
17
|
+
extract_results(@session)['gender'].should == 'both'
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
20
|
+
context "with a locator that doesn't exist" do
|
21
|
+
it "should raise an error" do
|
22
|
+
running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
28
|
-
end
|
26
|
+
end
|
@@ -1,19 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
shared_examples_for "click_button" do
|
2
|
+
describe '#click_button' do
|
3
|
+
before do
|
4
|
+
@session.visit('/form')
|
5
|
+
end
|
6
|
+
|
7
|
+
context "with multiple values with the same name" do
|
8
|
+
it "should use the latest given value" do
|
9
|
+
@session.check('Terms of Use')
|
10
|
+
@session.click_button('awesome')
|
11
|
+
extract_results(@session)['terms_of_use'].should == '1'
|
6
12
|
end
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@session.click_button('
|
12
|
-
extract_results(@session)
|
15
|
+
context "with value given on a submit button" do
|
16
|
+
context "on a form with HTML5 fields" do
|
17
|
+
before do
|
18
|
+
@session.click_button('html5_submit')
|
19
|
+
@results = extract_results(@session)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should serialise and submit search fields" do
|
23
|
+
@results['html5_search'].should == 'what are you looking for'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should serialise and submit email fields" do
|
27
|
+
@results['html5_email'].should == 'person@email.com'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should serialise and submit url fields" do
|
31
|
+
@results['html5_url'].should == 'http://www.example.com'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should serialise and submit tel fields" do
|
35
|
+
@results['html5_tel'].should == '911'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should serialise and submit color fields" do
|
39
|
+
@results['html5_color'].should == '#FFF'
|
13
40
|
end
|
14
41
|
end
|
15
42
|
|
16
|
-
context "
|
43
|
+
context "on an HTML4 form" do
|
17
44
|
before do
|
18
45
|
@session.click_button('awesome')
|
19
46
|
@results = extract_results(@session)
|
@@ -73,85 +100,72 @@ module ClickButtonSpec
|
|
73
100
|
@results['tendency'].should be_nil
|
74
101
|
end
|
75
102
|
end
|
103
|
+
end
|
76
104
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should work with partial matches" do
|
84
|
-
@session.click_button('Go')
|
85
|
-
@session.body.should include('You landed')
|
86
|
-
end
|
105
|
+
context "with id given on a submit button" do
|
106
|
+
it "should submit the associated form" do
|
107
|
+
@session.click_button('awe123')
|
108
|
+
extract_results(@session)['first_name'].should == 'John'
|
87
109
|
end
|
88
110
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
111
|
+
it "should work with partial matches" do
|
112
|
+
@session.click_button('Go')
|
113
|
+
@session.body.should include('You landed')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "with alt given on an image button" do
|
118
|
+
it "should submit the associated form" do
|
119
|
+
@session.click_button('oh hai thar')
|
120
|
+
extract_results(@session)['first_name'].should == 'John'
|
99
121
|
end
|
100
122
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
extract_results(@session)['first_name'].should == 'John'
|
105
|
-
end
|
123
|
+
it "should work with partial matches" do
|
124
|
+
@session.click_button('hai')
|
125
|
+
extract_results(@session)['first_name'].should == 'John'
|
106
126
|
end
|
127
|
+
end
|
107
128
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
129
|
+
context "with value given on an image button" do
|
130
|
+
it "should submit the associated form" do
|
131
|
+
@session.click_button('okay')
|
132
|
+
extract_results(@session)['first_name'].should == 'John'
|
133
|
+
end
|
113
134
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
135
|
+
it "should work with partial matches" do
|
136
|
+
@session.click_button('kay')
|
137
|
+
extract_results(@session)['first_name'].should == 'John'
|
138
|
+
end
|
139
|
+
end
|
118
140
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
141
|
+
context "with id given on an image button" do
|
142
|
+
it "should submit the associated form" do
|
143
|
+
@session.click_button('okay556')
|
144
|
+
extract_results(@session)['first_name'].should == 'John'
|
123
145
|
end
|
146
|
+
end
|
124
147
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
148
|
+
context "with text given on a button defined by <button> tag" do
|
149
|
+
it "should submit the associated form" do
|
150
|
+
@session.click_button('Click me')
|
151
|
+
extract_results(@session)['first_name'].should == 'John'
|
130
152
|
end
|
131
153
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
154
|
+
it "should work with partial matches" do
|
155
|
+
@session.click_button('Click')
|
156
|
+
extract_results(@session)['first_name'].should == 'John'
|
157
|
+
end
|
137
158
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should prefer exact matches over partial matches" do
|
144
|
-
@session.click_button('Just a button')
|
145
|
-
extract_results(@session)['button'].should == 'Just a button'
|
146
|
-
end
|
159
|
+
it "should prefer exact matches over partial matches" do
|
160
|
+
@session.click_button('Just an input')
|
161
|
+
extract_results(@session)['button'].should == 'button_second'
|
147
162
|
end
|
163
|
+
end
|
148
164
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end.should raise_error(Capybara::ElementNotFound)
|
154
|
-
end
|
165
|
+
context "with id given on a button defined by <button> tag" do
|
166
|
+
it "should submit the associated form" do
|
167
|
+
@session.click_button('click_me_123')
|
168
|
+
extract_results(@session)['first_name'].should == 'John'
|
155
169
|
end
|
156
170
|
|
157
171
|
it "should serialize and send GET forms" do
|
@@ -161,23 +175,62 @@ module ClickButtonSpec
|
|
161
175
|
@results['middle_name'].should == 'Darren'
|
162
176
|
@results['foo'].should be_nil
|
163
177
|
end
|
178
|
+
end
|
164
179
|
|
165
|
-
|
166
|
-
|
167
|
-
@session.
|
180
|
+
context "with value given on a button defined by <button> tag" do
|
181
|
+
it "should submit the associated form" do
|
182
|
+
@session.click_button('click_me')
|
183
|
+
extract_results(@session)['first_name'].should == 'John'
|
168
184
|
end
|
169
|
-
|
170
|
-
it "should
|
171
|
-
@session.
|
172
|
-
@session.
|
173
|
-
|
185
|
+
|
186
|
+
it "should work with partial matches" do
|
187
|
+
@session.click_button('ck_me')
|
188
|
+
extract_results(@session)['first_name'].should == 'John'
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should prefer exact matches over partial matches" do
|
192
|
+
@session.click_button('Just a button')
|
193
|
+
extract_results(@session)['button'].should == 'Just a button'
|
174
194
|
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
195
|
+
end
|
196
|
+
|
197
|
+
context "with a locator that doesn't exist" do
|
198
|
+
it "should raise an error" do
|
199
|
+
running do
|
200
|
+
@session.click_button('does not exist')
|
201
|
+
end.should raise_error(Capybara::ElementNotFound)
|
180
202
|
end
|
181
203
|
end
|
204
|
+
|
205
|
+
it "should serialize and send valueless buttons that were clicked" do
|
206
|
+
@session.click_button('No Value!')
|
207
|
+
@results = extract_results(@session)
|
208
|
+
@results['no_value'].should_not be_nil
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should serialize and send GET forms" do
|
212
|
+
@session.visit('/form')
|
213
|
+
@session.click_button('med')
|
214
|
+
@results = extract_results(@session)
|
215
|
+
@results['middle_name'].should == 'Darren'
|
216
|
+
@results['foo'].should be_nil
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should follow redirects" do
|
220
|
+
@session.click_button('Go FAR')
|
221
|
+
@session.body.should include('You landed')
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should post pack to the same URL when no action given" do
|
225
|
+
@session.visit('/postback')
|
226
|
+
@session.click_button('With no action')
|
227
|
+
@session.body.should include('Postback')
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should post pack to the same URL when blank action given" do
|
231
|
+
@session.visit('/postback')
|
232
|
+
@session.click_button('With blank action')
|
233
|
+
@session.body.should include('Postback')
|
234
|
+
end
|
182
235
|
end
|
183
236
|
end
|