capybara 2.0.0.beta2 → 2.0.0.beta4
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 +30 -1
- data/README.md +52 -31
- data/lib/capybara.rb +1 -0
- data/lib/capybara/driver/base.rb +1 -1
- data/lib/capybara/driver/node.rb +1 -0
- data/lib/capybara/dsl.rb +12 -5
- data/lib/capybara/helpers.rb +33 -0
- data/lib/capybara/node/actions.rb +4 -2
- data/lib/capybara/node/base.rb +52 -1
- data/lib/capybara/node/element.rb +0 -12
- data/lib/capybara/node/finders.rb +1 -1
- data/lib/capybara/node/matchers.rb +57 -47
- data/lib/capybara/node/simple.rb +4 -0
- data/lib/capybara/query.rb +11 -11
- data/lib/capybara/rack_test/browser.rb +14 -15
- data/lib/capybara/rack_test/driver.rb +2 -2
- data/lib/capybara/rack_test/node.rb +15 -2
- data/lib/capybara/result.rb +7 -19
- data/lib/capybara/rspec.rb +7 -4
- data/lib/capybara/rspec/features.rb +4 -1
- data/lib/capybara/rspec/matchers.rb +8 -3
- data/lib/capybara/selector.rb +1 -2
- data/lib/capybara/selenium/driver.rb +2 -2
- data/lib/capybara/selenium/node.rb +9 -7
- data/lib/capybara/session.rb +47 -31
- data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
- data/lib/capybara/spec/public/test.js +1 -1
- data/lib/capybara/spec/session/all_spec.rb +60 -62
- data/lib/capybara/spec/session/assert_selector.rb +123 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
- data/lib/capybara/spec/session/body_spec.rb +21 -0
- data/lib/capybara/spec/session/check_spec.rb +67 -50
- data/lib/capybara/spec/session/choose_spec.rb +32 -21
- data/lib/capybara/spec/session/click_button_spec.rb +261 -221
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
- data/lib/capybara/spec/session/click_link_spec.rb +95 -81
- data/lib/capybara/spec/session/current_url_spec.rb +70 -60
- data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +118 -92
- data/lib/capybara/spec/session/find_button_spec.rb +16 -14
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
- data/lib/capybara/spec/session/find_field_spec.rb +23 -21
- data/lib/capybara/spec/session/find_link_spec.rb +15 -14
- data/lib/capybara/spec/session/find_spec.rb +96 -91
- data/lib/capybara/spec/session/first_spec.rb +53 -55
- data/lib/capybara/spec/session/has_button_spec.rb +22 -24
- data/lib/capybara/spec/session/has_css_spec.rb +190 -205
- data/lib/capybara/spec/session/has_field_spec.rb +167 -169
- data/lib/capybara/spec/session/has_link_spec.rb +26 -29
- data/lib/capybara/spec/session/has_select_spec.rb +175 -176
- data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
- data/lib/capybara/spec/session/has_table_spec.rb +22 -26
- data/lib/capybara/spec/session/has_text_spec.rb +159 -132
- data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
- data/lib/capybara/spec/session/headers.rb +4 -17
- data/lib/capybara/spec/session/html_spec.rb +15 -0
- data/lib/capybara/spec/session/node_spec.rb +172 -82
- data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
- data/lib/capybara/spec/session/response_code.rb +4 -17
- data/lib/capybara/spec/session/save_page_spec.rb +46 -0
- data/lib/capybara/spec/session/screenshot.rb +8 -24
- data/lib/capybara/spec/session/select_spec.rb +100 -89
- data/lib/capybara/spec/session/source_spec.rb +12 -0
- data/lib/capybara/spec/session/text_spec.rb +15 -17
- data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
- data/lib/capybara/spec/session/unselect_spec.rb +57 -52
- data/lib/capybara/spec/session/visit_spec.rb +58 -60
- data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
- data/lib/capybara/spec/session/within_spec.rb +119 -121
- data/lib/capybara/spec/session/within_window_spec.rb +29 -31
- data/lib/capybara/spec/spec_helper.rb +84 -0
- data/lib/capybara/spec/test_app.rb +5 -3
- data/lib/capybara/spec/views/form.erb +1 -0
- data/lib/capybara/spec/views/with_html.erb +6 -1
- data/lib/capybara/spec/views/with_js.erb +1 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +2 -2
- data/spec/capybara_spec.rb +9 -0
- data/spec/dsl_spec.rb +22 -10
- data/spec/rack_test_spec.rb +28 -23
- data/spec/result_spec.rb +51 -0
- data/spec/rspec/features_spec.rb +19 -0
- data/spec/rspec/matchers_spec.rb +6 -0
- data/spec/rspec_spec.rb +1 -1
- data/spec/selenium_spec.rb +11 -25
- data/spec/server_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -46
- metadata +41 -98
- data/lib/capybara/spec/session.rb +0 -183
- data/lib/capybara/spec/session/javascript.rb +0 -290
- data/lib/capybara/util/save_and_open_page.rb +0 -45
- data/spec/save_and_open_page_spec.rb +0 -155
|
@@ -1,68 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
Capybara::SpecHelper.spec "#check" do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
2
5
|
|
|
3
|
-
describe "
|
|
4
|
-
|
|
5
|
-
@session.
|
|
6
|
+
describe "'checked' attribute" do
|
|
7
|
+
it "should be true if checked" do
|
|
8
|
+
@session.check("Terms of Use")
|
|
9
|
+
@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
|
|
6
10
|
end
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@session.check("Terms of Use")
|
|
11
|
-
@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should be false if unchecked" do
|
|
15
|
-
@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
|
|
16
|
-
end
|
|
12
|
+
it "should be false if unchecked" do
|
|
13
|
+
@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
|
|
17
14
|
end
|
|
15
|
+
end
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
17
|
+
it "should trigger associated events", :requires => [:js] do
|
|
18
|
+
@session.visit('/with_js')
|
|
19
|
+
@session.check('checkbox_with_event')
|
|
20
|
+
@session.should have_css('#checkbox_event_triggered');
|
|
21
|
+
end
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
describe "checking" do
|
|
24
|
+
it "should not change an already checked checkbox" do
|
|
25
|
+
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
|
|
26
|
+
@session.check('form_pets_dog')
|
|
27
|
+
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
|
|
31
28
|
end
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
it "should check an unchecked checkbox" do
|
|
31
|
+
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
|
|
32
|
+
@session.check('form_pets_cat')
|
|
33
|
+
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
|
|
34
|
+
end
|
|
35
|
+
end
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
describe "unchecking" do
|
|
38
|
+
it "should not change an already unchecked checkbox" do
|
|
39
|
+
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
|
|
40
|
+
@session.uncheck('form_pets_cat')
|
|
41
|
+
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
|
|
45
42
|
end
|
|
46
43
|
|
|
47
|
-
it "should
|
|
48
|
-
@session.
|
|
49
|
-
@session.
|
|
50
|
-
|
|
44
|
+
it "should uncheck a checked checkbox" do
|
|
45
|
+
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
|
|
46
|
+
@session.uncheck('form_pets_dog')
|
|
47
|
+
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
|
|
51
48
|
end
|
|
49
|
+
end
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
it "should check a checkbox by id" do
|
|
52
|
+
@session.check("form_pets_cat")
|
|
53
|
+
@session.click_button('awesome')
|
|
54
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should check a checkbox by label" do
|
|
58
|
+
@session.check("Cat")
|
|
59
|
+
@session.click_button('awesome')
|
|
60
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "casts to string" do
|
|
64
|
+
@session.check(:"form_pets_cat")
|
|
65
|
+
@session.click_button('awesome')
|
|
66
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context "with a locator that doesn't exist" do
|
|
70
|
+
it "should raise an error" do
|
|
71
|
+
msg = "Unable to find checkbox \"does not exist\""
|
|
72
|
+
expect do
|
|
73
|
+
@session.check('does not exist')
|
|
74
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
57
75
|
end
|
|
76
|
+
end
|
|
58
77
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
end.should raise_error(Capybara::ElementNotFound, msg)
|
|
65
|
-
end
|
|
78
|
+
context "with a disabled checkbox" do
|
|
79
|
+
it "should raise an error" do
|
|
80
|
+
expect do
|
|
81
|
+
@session.check('Disabled Checkbox')
|
|
82
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
66
83
|
end
|
|
67
84
|
end
|
|
68
85
|
end
|
|
@@ -1,29 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
Capybara::SpecHelper.spec "#choose" do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
it "should choose a radio button by id" do
|
|
7
|
+
@session.choose("gender_male")
|
|
8
|
+
@session.click_button('awesome')
|
|
9
|
+
extract_results(@session)['gender'].should == 'male'
|
|
10
|
+
end
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
it "should choose a radio button by label" do
|
|
13
|
+
@session.choose("Both")
|
|
14
|
+
@session.click_button('awesome')
|
|
15
|
+
extract_results(@session)['gender'].should == 'both'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "casts to string" do
|
|
19
|
+
@session.choose("Both")
|
|
20
|
+
@session.click_button(:'awesome')
|
|
21
|
+
extract_results(@session)['gender'].should == 'both'
|
|
22
|
+
end
|
|
13
23
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
context "with a locator that doesn't exist" do
|
|
25
|
+
it "should raise an error" do
|
|
26
|
+
msg = "Unable to find radio button \"does not exist\""
|
|
27
|
+
expect do
|
|
28
|
+
@session.choose('does not exist')
|
|
29
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
18
30
|
end
|
|
31
|
+
end
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
end.should raise_error(Capybara::ElementNotFound, msg)
|
|
26
|
-
end
|
|
33
|
+
context "with a disabled radio button" do
|
|
34
|
+
it "should raise an error" do
|
|
35
|
+
expect do
|
|
36
|
+
@session.choose('Disabled Radio')
|
|
37
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
27
38
|
end
|
|
28
39
|
end
|
|
29
40
|
end
|
|
@@ -1,268 +1,226 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#click_button' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end
|
|
13
|
-
end
|
|
6
|
+
it "should wait for asynchronous load", :requires => [:js] do
|
|
7
|
+
@session.visit('/with_js')
|
|
8
|
+
@session.click_link('Click me')
|
|
9
|
+
@session.click_button('New Here')
|
|
10
|
+
end
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
it "casts to string" do
|
|
13
|
+
@session.click_button(:'Relative Action')
|
|
14
|
+
@session.current_path.should == '/relative'
|
|
15
|
+
extract_results(@session)['relative'].should == 'Relative Action'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "with multiple values with the same name" do
|
|
19
|
+
it "should use the latest given value" do
|
|
20
|
+
@session.check('Terms of Use')
|
|
21
|
+
@session.click_button('awesome')
|
|
22
|
+
extract_results(@session)['terms_of_use'].should == '1'
|
|
21
23
|
end
|
|
24
|
+
end
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
end
|
|
26
|
+
context "with a form that has a relative url as an action" do
|
|
27
|
+
it "should post to the correct url" do
|
|
28
|
+
@session.click_button('Relative Action')
|
|
29
|
+
@session.current_path.should == '/relative'
|
|
30
|
+
extract_results(@session)['relative'].should == 'Relative Action'
|
|
29
31
|
end
|
|
32
|
+
end
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
context "with a form that has no action specified" do
|
|
35
|
+
it "should post to the correct url" do
|
|
36
|
+
@session.click_button('No Action')
|
|
37
|
+
@session.current_path.should == '/form'
|
|
38
|
+
extract_results(@session)['no_action'].should == 'No Action'
|
|
39
|
+
end
|
|
40
|
+
end
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
context "with value given on a submit button" do
|
|
43
|
+
context "on a form with HTML5 fields" do
|
|
44
|
+
before do
|
|
45
|
+
@session.click_button('html5_submit')
|
|
46
|
+
@results = extract_results(@session)
|
|
47
|
+
end
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
it "should serialise and submit search fields" do
|
|
50
|
+
@results['html5_search'].should == 'what are you looking for'
|
|
51
|
+
end
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
it "should serialise and submit email fields" do
|
|
54
|
+
@results['html5_email'].should == 'person@email.com'
|
|
55
|
+
end
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
it "should serialise and submit url fields" do
|
|
58
|
+
@results['html5_url'].should == 'http://www.example.com'
|
|
59
|
+
end
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|
|
61
|
+
it "should serialise and submit tel fields" do
|
|
62
|
+
@results['html5_tel'].should == '911'
|
|
57
63
|
end
|
|
58
64
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
@session.click_button('awesome')
|
|
62
|
-
@results = extract_results(@session)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "should serialize and submit text fields" do
|
|
66
|
-
@results['first_name'].should == 'John'
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "should escape fields when submitting" do
|
|
70
|
-
@results['phone'].should == '+1 555 7021'
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should serialize and submit password fields" do
|
|
74
|
-
@results['password'].should == 'seeekrit'
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should serialize and submit hidden fields" do
|
|
78
|
-
@results['token'].should == '12345'
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should not serialize fields from other forms" do
|
|
82
|
-
@results['middle_name'].should be_nil
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should submit the button that was clicked, but not other buttons" do
|
|
86
|
-
@results['awesome'].should == 'awesome'
|
|
87
|
-
@results['crappy'].should be_nil
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "should serialize radio buttons" do
|
|
91
|
-
@results['gender'].should == 'female'
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "should serialize check boxes" do
|
|
95
|
-
@results['pets'].should include('dog', 'hamster')
|
|
96
|
-
@results['pets'].should_not include('cat')
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should serialize text areas" do
|
|
100
|
-
@results['description'].should == 'Descriptive text goes here'
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "should serialize select tag with values" do
|
|
104
|
-
@results['locale'].should == 'en'
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
it "should serialize select tag without values" do
|
|
108
|
-
@results['region'].should == 'Norway'
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it "should serialize first option for select tag with no selection" do
|
|
112
|
-
@results['city'].should == 'London'
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "should not serialize a select tag without options" do
|
|
116
|
-
@results['tendency'].should be_nil
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "should not submit disabled fields" do
|
|
120
|
-
@results['disabled_text_field'].should be_nil
|
|
121
|
-
@results['disabled_textarea'].should be_nil
|
|
122
|
-
@results['disabled_checkbox'].should be_nil
|
|
123
|
-
@results['disabled_radio'].should be_nil
|
|
124
|
-
@results['disabled_select'].should be_nil
|
|
125
|
-
@results['disabled_file'].should be_nil
|
|
126
|
-
end
|
|
65
|
+
it "should serialise and submit color fields" do
|
|
66
|
+
@results['html5_color'].should == '#FFFFFF'
|
|
127
67
|
end
|
|
128
68
|
end
|
|
129
69
|
|
|
130
|
-
context "
|
|
131
|
-
|
|
132
|
-
@session.click_button('
|
|
133
|
-
extract_results(@session)
|
|
70
|
+
context "on an HTML4 form" do
|
|
71
|
+
before do
|
|
72
|
+
@session.click_button('awesome')
|
|
73
|
+
@results = extract_results(@session)
|
|
134
74
|
end
|
|
135
75
|
|
|
136
|
-
it "should
|
|
137
|
-
@
|
|
138
|
-
@session.body.should include('You landed')
|
|
76
|
+
it "should serialize and submit text fields" do
|
|
77
|
+
@results['first_name'].should == 'John'
|
|
139
78
|
end
|
|
140
|
-
end
|
|
141
79
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
@session.click_button('What an Awesome Button')
|
|
145
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
80
|
+
it "should escape fields when submitting" do
|
|
81
|
+
@results['phone'].should == '+1 555 7021'
|
|
146
82
|
end
|
|
147
83
|
|
|
148
|
-
it "should
|
|
149
|
-
@
|
|
150
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
84
|
+
it "should serialize and submit password fields" do
|
|
85
|
+
@results['password'].should == 'seeekrit'
|
|
151
86
|
end
|
|
152
|
-
end
|
|
153
87
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
@session.click_button('oh hai thar')
|
|
157
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
88
|
+
it "should serialize and submit hidden fields" do
|
|
89
|
+
@results['token'].should == '12345'
|
|
158
90
|
end
|
|
159
91
|
|
|
160
|
-
it "should
|
|
161
|
-
@
|
|
162
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
92
|
+
it "should not serialize fields from other forms" do
|
|
93
|
+
@results['middle_name'].should be_nil
|
|
163
94
|
end
|
|
164
|
-
end
|
|
165
95
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
@
|
|
169
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
96
|
+
it "should submit the button that was clicked, but not other buttons" do
|
|
97
|
+
@results['awesome'].should == 'awesome'
|
|
98
|
+
@results['crappy'].should be_nil
|
|
170
99
|
end
|
|
171
100
|
|
|
172
|
-
it "should
|
|
173
|
-
@
|
|
174
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
101
|
+
it "should serialize radio buttons" do
|
|
102
|
+
@results['gender'].should == 'female'
|
|
175
103
|
end
|
|
176
|
-
end
|
|
177
104
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
@
|
|
181
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
105
|
+
it "should serialize check boxes" do
|
|
106
|
+
@results['pets'].should include('dog', 'hamster')
|
|
107
|
+
@results['pets'].should_not include('cat')
|
|
182
108
|
end
|
|
183
|
-
end
|
|
184
109
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
@session.click_button('Okay 556 Image')
|
|
188
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
110
|
+
it "should serialize text areas" do
|
|
111
|
+
@results['description'].should == 'Descriptive text goes here'
|
|
189
112
|
end
|
|
190
113
|
|
|
191
|
-
it "should
|
|
192
|
-
@
|
|
193
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
114
|
+
it "should serialize select tag with values" do
|
|
115
|
+
@results['locale'].should == 'en'
|
|
194
116
|
end
|
|
195
|
-
end
|
|
196
117
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
@session.click_button('Click me')
|
|
200
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
118
|
+
it "should serialize select tag without values" do
|
|
119
|
+
@results['region'].should == 'Norway'
|
|
201
120
|
end
|
|
202
121
|
|
|
203
|
-
it "should
|
|
204
|
-
@
|
|
205
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
122
|
+
it "should serialize first option for select tag with no selection" do
|
|
123
|
+
@results['city'].should == 'London'
|
|
206
124
|
end
|
|
207
|
-
end
|
|
208
125
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
@session.click_button('click_me_123')
|
|
212
|
-
extract_results(@session)['first_name'].should == 'John'
|
|
126
|
+
it "should not serialize a select tag without options" do
|
|
127
|
+
@results['tendency'].should be_nil
|
|
213
128
|
end
|
|
214
129
|
|
|
215
|
-
it "should
|
|
216
|
-
@
|
|
217
|
-
@
|
|
218
|
-
@results
|
|
219
|
-
@results['
|
|
220
|
-
@results['
|
|
130
|
+
it "should not submit disabled fields" do
|
|
131
|
+
@results['disabled_text_field'].should be_nil
|
|
132
|
+
@results['disabled_textarea'].should be_nil
|
|
133
|
+
@results['disabled_checkbox'].should be_nil
|
|
134
|
+
@results['disabled_radio'].should be_nil
|
|
135
|
+
@results['disabled_select'].should be_nil
|
|
136
|
+
@results['disabled_file'].should be_nil
|
|
221
137
|
end
|
|
222
138
|
end
|
|
139
|
+
end
|
|
223
140
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
141
|
+
context "with id given on a submit button" do
|
|
142
|
+
it "should submit the associated form" do
|
|
143
|
+
@session.click_button('awe123')
|
|
144
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
145
|
+
end
|
|
229
146
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
end
|
|
147
|
+
it "should work with partial matches" do
|
|
148
|
+
@session.click_button('Go')
|
|
149
|
+
@session.should have_content('You landed')
|
|
234
150
|
end
|
|
151
|
+
end
|
|
235
152
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
153
|
+
context "with title given on a submit button" do
|
|
154
|
+
it "should submit the associated form" do
|
|
155
|
+
@session.click_button('What an Awesome Button')
|
|
156
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
157
|
+
end
|
|
241
158
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
end
|
|
159
|
+
it "should work with partial matches" do
|
|
160
|
+
@session.click_button('What an Awesome')
|
|
161
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
246
162
|
end
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
context "with alt given on an image button" do
|
|
166
|
+
it "should submit the associated form" do
|
|
167
|
+
@session.click_button('oh hai thar')
|
|
168
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
254
169
|
end
|
|
255
170
|
|
|
256
|
-
it "should
|
|
257
|
-
@session.click_button('
|
|
258
|
-
|
|
259
|
-
@results['no_value'].should_not be_nil
|
|
171
|
+
it "should work with partial matches" do
|
|
172
|
+
@session.click_button('hai')
|
|
173
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
260
174
|
end
|
|
175
|
+
end
|
|
261
176
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
@
|
|
265
|
-
@
|
|
177
|
+
context "with value given on an image button" do
|
|
178
|
+
it "should submit the associated form" do
|
|
179
|
+
@session.click_button('okay')
|
|
180
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should work with partial matches" do
|
|
184
|
+
@session.click_button('kay')
|
|
185
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
context "with id given on an image button" do
|
|
190
|
+
it "should submit the associated form" do
|
|
191
|
+
@session.click_button('okay556')
|
|
192
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
context "with title given on an image button" do
|
|
197
|
+
it "should submit the associated form" do
|
|
198
|
+
@session.click_button('Okay 556 Image')
|
|
199
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it "should work with partial matches" do
|
|
203
|
+
@session.click_button('Okay 556')
|
|
204
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
context "with text given on a button defined by <button> tag" do
|
|
209
|
+
it "should submit the associated form" do
|
|
210
|
+
@session.click_button('Click me')
|
|
211
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "should work with partial matches" do
|
|
215
|
+
@session.click_button('Click')
|
|
216
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
context "with id given on a button defined by <button> tag" do
|
|
221
|
+
it "should submit the associated form" do
|
|
222
|
+
@session.click_button('click_me_123')
|
|
223
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
266
224
|
end
|
|
267
225
|
|
|
268
226
|
it "should serialize and send GET forms" do
|
|
@@ -272,24 +230,106 @@ shared_examples_for "click_button" do
|
|
|
272
230
|
@results['middle_name'].should == 'Darren'
|
|
273
231
|
@results['foo'].should be_nil
|
|
274
232
|
end
|
|
233
|
+
end
|
|
275
234
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
@session.
|
|
279
|
-
@session.
|
|
235
|
+
context "with value given on a button defined by <button> tag" do
|
|
236
|
+
it "should submit the associated form" do
|
|
237
|
+
@session.click_button('click_me')
|
|
238
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
280
239
|
end
|
|
281
240
|
|
|
282
|
-
it "should
|
|
283
|
-
@session.
|
|
284
|
-
@session.
|
|
285
|
-
|
|
241
|
+
it "should work with partial matches" do
|
|
242
|
+
@session.click_button('ck_me')
|
|
243
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
context "with title given on a button defined by <button> tag" do
|
|
248
|
+
it "should submit the associated form" do
|
|
249
|
+
@session.click_button('Click Title button')
|
|
250
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
286
251
|
end
|
|
287
252
|
|
|
288
|
-
it "should
|
|
289
|
-
@session.
|
|
290
|
-
@session.
|
|
291
|
-
@session.body.should include('Postback')
|
|
253
|
+
it "should work with partial matches" do
|
|
254
|
+
@session.click_button('Click Title')
|
|
255
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
292
256
|
end
|
|
293
257
|
end
|
|
258
|
+
context "with a locator that doesn't exist" do
|
|
259
|
+
it "should raise an error" do
|
|
260
|
+
msg = "Unable to find button \"does not exist\""
|
|
261
|
+
expect do
|
|
262
|
+
@session.click_button('does not exist')
|
|
263
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it "should serialize and send valueless buttons that were clicked" do
|
|
268
|
+
@session.click_button('No Value!')
|
|
269
|
+
@results = extract_results(@session)
|
|
270
|
+
@results['no_value'].should_not be_nil
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it "should not send image buttons that were not clicked" do
|
|
274
|
+
@session.click_button('Click me!')
|
|
275
|
+
@results = extract_results(@session)
|
|
276
|
+
@results['okay'].should be_nil
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
it "should serialize and send GET forms" do
|
|
280
|
+
@session.visit('/form')
|
|
281
|
+
@session.click_button('med')
|
|
282
|
+
@results = extract_results(@session)
|
|
283
|
+
@results['middle_name'].should == 'Darren'
|
|
284
|
+
@results['foo'].should be_nil
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it "should follow redirects" do
|
|
288
|
+
@session.click_button('Go FAR')
|
|
289
|
+
@session.current_url.should match(%r{/landed$})
|
|
290
|
+
@session.should have_content('You landed')
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it "should post pack to the same URL when no action given" do
|
|
294
|
+
@session.visit('/postback')
|
|
295
|
+
@session.click_button('With no action')
|
|
296
|
+
@session.should have_content('Postback')
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
it "should post pack to the same URL when blank action given" do
|
|
300
|
+
@session.visit('/postback')
|
|
301
|
+
@session.click_button('With blank action')
|
|
302
|
+
@session.should have_content('Postback')
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it "ignores disabled buttons" do
|
|
306
|
+
expect do
|
|
307
|
+
@session.click_button('Disabled button')
|
|
308
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
it "should encode complex field names, like array[][value]" do
|
|
312
|
+
@session.visit('/form')
|
|
313
|
+
@session.fill_in('address1_city', :with =>'Paris')
|
|
314
|
+
@session.fill_in('address1_street', :with =>'CDG')
|
|
315
|
+
@session.fill_in('address1_street', :with =>'CDG')
|
|
316
|
+
@session.select("France", :from => 'address1_country')
|
|
294
317
|
|
|
318
|
+
@session.fill_in('address2_city', :with => 'Mikolaiv')
|
|
319
|
+
@session.fill_in('address2_street', :with => 'PGS')
|
|
320
|
+
@session.select("Ukraine", :from => 'address2_country')
|
|
321
|
+
|
|
322
|
+
@session.click_button "awesome"
|
|
323
|
+
|
|
324
|
+
addresses=extract_results(@session)["addresses"]
|
|
325
|
+
addresses.should have(2).addresses
|
|
326
|
+
|
|
327
|
+
addresses[0]["street"].should == 'CDG'
|
|
328
|
+
addresses[0]["city"].should == 'Paris'
|
|
329
|
+
addresses[0]["country"].should == 'France'
|
|
330
|
+
|
|
331
|
+
addresses[1]["street"].should == 'PGS'
|
|
332
|
+
addresses[1]["city"].should == 'Mikolaiv'
|
|
333
|
+
addresses[1]["country"].should == 'Ukraine'
|
|
334
|
+
end
|
|
295
335
|
end
|