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,37 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#click_link_or_button' do
|
|
2
|
+
it "should click on a link" do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
@session.click_link_or_button('labore')
|
|
5
|
+
@session.should have_content('Bar')
|
|
6
|
+
end
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
it "should click on a button" do
|
|
9
|
+
@session.visit('/form')
|
|
10
|
+
@session.click_link_or_button('awe123')
|
|
11
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
12
|
+
end
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
it "should click on a button with no type attribute" do
|
|
15
|
+
@session.visit('/form')
|
|
16
|
+
@session.click_link_or_button('no_type')
|
|
17
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
18
|
+
end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
it "should be aliased as click_on" do
|
|
21
|
+
@session.visit('/form')
|
|
22
|
+
@session.click_on('awe123')
|
|
23
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should wait for asynchronous load", :requires => [:js] do
|
|
27
|
+
@session.visit('/with_js')
|
|
28
|
+
@session.click_link('Click me')
|
|
29
|
+
@session.click_link_or_button('Has been clicked')
|
|
30
|
+
end
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
it "casts to string" do
|
|
33
|
+
@session.visit('/form')
|
|
34
|
+
@session.click_link_or_button(:'awe123')
|
|
35
|
+
extract_results(@session)['first_name'].should == 'John'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "with a locator that doesn't exist" do
|
|
39
|
+
it "should raise an error" do
|
|
40
|
+
@session.visit('/with_html')
|
|
41
|
+
msg = "Unable to find link or button \"does not exist\""
|
|
42
|
+
expect do
|
|
43
|
+
@session.click_link_or_button('does not exist')
|
|
44
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
35
45
|
end
|
|
36
46
|
end
|
|
37
47
|
end
|
|
@@ -1,105 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#click_link' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
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_link('Has been clicked')
|
|
10
|
+
end
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
12
|
+
it "casts to string" do
|
|
13
|
+
@session.click_link(:'foo')
|
|
14
|
+
@session.should have_content('Another World')
|
|
15
|
+
end
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
context "with id given" do
|
|
18
|
+
it "should take user to the linked page" do
|
|
19
|
+
@session.click_link('foo')
|
|
20
|
+
@session.should have_content('Another World')
|
|
24
21
|
end
|
|
22
|
+
end
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should accept partial matches" do
|
|
33
|
-
@session.click_link('some tit')
|
|
34
|
-
@session.body.should include('Bar')
|
|
35
|
-
end
|
|
24
|
+
context "with text given" do
|
|
25
|
+
it "should take user to the linked page" do
|
|
26
|
+
@session.click_link('labore')
|
|
27
|
+
@session.should have_content('Bar')
|
|
36
28
|
end
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
@session.body.should include('Bar')
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "should take user to the linked page" do
|
|
45
|
-
@session.click_link('some imag')
|
|
46
|
-
@session.body.should include('Bar')
|
|
47
|
-
end
|
|
30
|
+
it "should accept partial matches" do
|
|
31
|
+
@session.click_link('abo')
|
|
32
|
+
@session.should have_content('Bar')
|
|
48
33
|
end
|
|
34
|
+
end
|
|
49
35
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@session.click_link('does not exist')
|
|
55
|
-
end.should raise_error(Capybara::ElementNotFound, msg)
|
|
56
|
-
end
|
|
36
|
+
context "with title given" do
|
|
37
|
+
it "should take user to the linked page" do
|
|
38
|
+
@session.click_link('awesome title')
|
|
39
|
+
@session.should have_content('Bar')
|
|
57
40
|
end
|
|
58
41
|
|
|
59
|
-
it "should
|
|
60
|
-
@session.
|
|
61
|
-
@session.
|
|
62
|
-
@session.body.should include('This is a test')
|
|
42
|
+
it "should accept partial matches" do
|
|
43
|
+
@session.click_link('some titl')
|
|
44
|
+
@session.should have_content('Bar')
|
|
63
45
|
end
|
|
46
|
+
end
|
|
64
47
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
@session.
|
|
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.should have_content('Bar')
|
|
68
52
|
end
|
|
69
53
|
|
|
70
|
-
it "should
|
|
71
|
-
@session.click_link('
|
|
72
|
-
@session.
|
|
54
|
+
it "should accept partial matches" do
|
|
55
|
+
@session.click_link('some imag')
|
|
56
|
+
@session.should have_content('Bar')
|
|
73
57
|
end
|
|
58
|
+
end
|
|
74
59
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
context "with a locator that doesn't exist" do
|
|
61
|
+
it "should raise an error" do
|
|
62
|
+
msg = "Unable to find link \"does not exist\""
|
|
63
|
+
expect do
|
|
64
|
+
@session.click_link('does not exist')
|
|
65
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
78
66
|
end
|
|
67
|
+
end
|
|
79
68
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
@session.find_field("test_field").value.should == 'blah'
|
|
86
|
-
end
|
|
69
|
+
it "should follow relative links" do
|
|
70
|
+
@session.visit('/')
|
|
71
|
+
@session.click_link('Relative')
|
|
72
|
+
@session.should have_content('This is a test')
|
|
73
|
+
end
|
|
87
74
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
end
|
|
75
|
+
it "should follow protocol relative links" do
|
|
76
|
+
@session.click_link('Protocol')
|
|
77
|
+
@session.should have_content('Another World')
|
|
78
|
+
end
|
|
93
79
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
it "should follow redirects" do
|
|
81
|
+
@session.click_link('Redirect')
|
|
82
|
+
@session.should have_content('You landed')
|
|
83
|
+
end
|
|
98
84
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
85
|
+
it "should follow redirects" do
|
|
86
|
+
@session.click_link('BackToMyself')
|
|
87
|
+
@session.should have_content('This is a test')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should add query string to current URL with naked query string" do
|
|
91
|
+
@session.click_link('Naked Query String')
|
|
92
|
+
@session.should have_content('Query String sent')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "should do nothing on anchor links" do
|
|
96
|
+
@session.fill_in("test_field", :with => 'blah')
|
|
97
|
+
@session.click_link('Normal Anchor')
|
|
98
|
+
@session.find_field("test_field").value.should == 'blah'
|
|
99
|
+
@session.click_link('Blank Anchor')
|
|
100
|
+
@session.find_field("test_field").value.should == 'blah'
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should do nothing on URL+anchor links for the same page" do
|
|
104
|
+
@session.fill_in("test_field", :with => 'blah')
|
|
105
|
+
@session.click_link('Anchor on same page')
|
|
106
|
+
@session.find_field("test_field").value.should == 'blah'
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should follow link on URL+anchor links for a different page" do
|
|
110
|
+
@session.click_link('Anchor on different page')
|
|
111
|
+
@session.should have_content('Bar')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "raise an error with links with no href" do
|
|
115
|
+
expect do
|
|
116
|
+
@session.click_link('No Href')
|
|
117
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
104
118
|
end
|
|
105
119
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
|
2
2
|
before :all do
|
|
3
3
|
@servers = 2.times.map { Capybara::Server.new(TestApp.clone).boot }
|
|
4
4
|
# sanity check
|
|
@@ -10,74 +10,84 @@ shared_examples_for "current_url" do
|
|
|
10
10
|
@servers.map { |s| "http://#{s.host}:#{s.port}" }
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@session.body.should include("Current host is #{scheme}://#{s.host}:#{s.port}")
|
|
23
|
-
end
|
|
13
|
+
def should_be_on server_index, path="/host", scheme="http"
|
|
14
|
+
# Check that we are on /host on the given server
|
|
15
|
+
s = @servers[server_index]
|
|
16
|
+
@session.current_url.chomp('?').should == "#{scheme}://#{s.host}:#{s.port}#{path}"
|
|
17
|
+
@session.current_host.should == "#{scheme}://#{s.host}" # no port
|
|
18
|
+
@session.current_path.should == path
|
|
19
|
+
if path == '/host'
|
|
20
|
+
# Server should agree with us
|
|
21
|
+
@session.should have_content("Current host is #{scheme}://#{s.host}:#{s.port}")
|
|
24
22
|
end
|
|
23
|
+
end
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
def visit_host_links
|
|
26
|
+
@session.visit("#{bases[0]}/host_links?absolute_host=#{bases[1]}")
|
|
27
|
+
end
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
it "is affected by visiting a page directly" do
|
|
30
|
+
@session.visit("#{bases[0]}/host")
|
|
31
|
+
should_be_on 0
|
|
32
|
+
end
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
it "returns to the app host when visiting a relative url" do
|
|
35
|
+
Capybara.app_host = bases[1]
|
|
36
|
+
@session.visit("#{bases[0]}/host")
|
|
37
|
+
should_be_on 0
|
|
38
|
+
@session.visit('/host')
|
|
39
|
+
should_be_on 1
|
|
40
|
+
Capybara.app_host = nil
|
|
41
|
+
end
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
it "is affected by setting Capybara.app_host" do
|
|
44
|
+
Capybara.app_host = bases[0]
|
|
45
|
+
@session.visit("/host")
|
|
46
|
+
should_be_on 0
|
|
47
|
+
Capybara.app_host = bases[1]
|
|
48
|
+
@session.visit("/host")
|
|
49
|
+
should_be_on 1
|
|
50
|
+
Capybara.app_host = nil
|
|
51
|
+
end
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
it "is unaffected by following a relative link" do
|
|
54
|
+
visit_host_links
|
|
55
|
+
@session.click_link("Relative Host")
|
|
56
|
+
should_be_on 0
|
|
57
|
+
end
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
it "is affected by following an absolute link" do
|
|
60
|
+
visit_host_links
|
|
61
|
+
@session.click_link("Absolute Host")
|
|
62
|
+
should_be_on 1
|
|
63
|
+
end
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
it "is unaffected by posting through a relative form" do
|
|
66
|
+
visit_host_links
|
|
67
|
+
@session.click_button("Relative Host")
|
|
68
|
+
should_be_on 0
|
|
69
|
+
end
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
it "is affected by posting through an absolute form" do
|
|
72
|
+
visit_host_links
|
|
73
|
+
@session.click_button("Absolute Host")
|
|
74
|
+
should_be_on 1
|
|
75
|
+
end
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
end
|
|
77
|
+
it "is affected by following a redirect" do
|
|
78
|
+
@session.visit("#{bases[0]}/redirect")
|
|
79
|
+
should_be_on 0, "/landed"
|
|
82
80
|
end
|
|
81
|
+
|
|
82
|
+
it "is affected by pushState", :requires => [:js] do
|
|
83
|
+
@session.visit("/with_js")
|
|
84
|
+
@session.execute_script("window.history.pushState({}, '', '/pushed')")
|
|
85
|
+
@session.current_path.should == "/pushed"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "is affected by replaceState", :requires => [:js] do
|
|
89
|
+
@session.visit("/with_js")
|
|
90
|
+
@session.execute_script("window.history.replaceState({}, '', '/replaced')")
|
|
91
|
+
@session.current_path.should == "/replaced"
|
|
92
|
+
end
|
|
83
93
|
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec "#execute_script", :requires => [:js] do
|
|
2
|
+
it "should execute the given script and return nothing" do
|
|
3
|
+
@session.visit('/with_js')
|
|
4
|
+
@session.execute_script("$('#change').text('Funky Doodle')").should be_nil
|
|
5
|
+
@session.should have_css('#change', :text => 'Funky Doodle')
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -1,115 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec "#fill_in" do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
it "should fill in a text field by id" do
|
|
7
|
+
@session.fill_in('form_first_name', :with => 'Harry')
|
|
8
|
+
@session.click_button('awesome')
|
|
9
|
+
extract_results(@session)['first_name'].should == 'Harry'
|
|
10
|
+
end
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
it "should fill in a text field by name" do
|
|
13
|
+
@session.fill_in('form[last_name]', :with => 'Green')
|
|
14
|
+
@session.click_button('awesome')
|
|
15
|
+
extract_results(@session)['last_name'].should == 'Green'
|
|
16
|
+
end
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
it "should fill in a text field by label without for" do
|
|
19
|
+
@session.fill_in('First Name', :with => 'Harry')
|
|
20
|
+
@session.click_button('awesome')
|
|
21
|
+
extract_results(@session)['first_name'].should == 'Harry'
|
|
22
|
+
end
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
it "should fill in a url field by label without for" do
|
|
25
|
+
@session.fill_in('Html5 Url', :with => 'http://www.avenueq.com')
|
|
26
|
+
@session.click_button('html5_submit')
|
|
27
|
+
extract_results(@session)['html5_url'].should == 'http://www.avenueq.com'
|
|
28
|
+
end
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
it "should fill in a textarea by id" do
|
|
31
|
+
@session.fill_in('form_description', :with => 'Texty text')
|
|
32
|
+
@session.click_button('awesome')
|
|
33
|
+
extract_results(@session)['description'].should == 'Texty text'
|
|
34
|
+
end
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
it "should fill in a textarea by label" do
|
|
37
|
+
@session.fill_in('Description', :with => 'Texty text')
|
|
38
|
+
@session.click_button('awesome')
|
|
39
|
+
extract_results(@session)['description'].should == 'Texty text'
|
|
40
|
+
end
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
it "should fill in a textarea by name" do
|
|
43
|
+
@session.fill_in('form[description]', :with => 'Texty text')
|
|
44
|
+
@session.click_button('awesome')
|
|
45
|
+
extract_results(@session)['description'].should == 'Texty text'
|
|
46
|
+
end
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
it "should fill in a password field by id" do
|
|
49
|
+
@session.fill_in('form_password', :with => 'supasikrit')
|
|
50
|
+
@session.click_button('awesome')
|
|
51
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
|
52
|
+
end
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
it "should fill in a field with a custom type" do
|
|
55
|
+
@session.fill_in('Schmooo', :with => 'Schmooo is the game')
|
|
56
|
+
@session.click_button('awesome')
|
|
57
|
+
extract_results(@session)['schmooo'].should == 'Schmooo is the game'
|
|
58
|
+
end
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
it "should fill in a field without a type" do
|
|
61
|
+
@session.fill_in('Phone', :with => '+1 555 7022')
|
|
62
|
+
@session.click_button('awesome')
|
|
63
|
+
extract_results(@session)['phone'].should == '+1 555 7022'
|
|
64
|
+
end
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
it "should fill in a text field respecting its maxlength attribute" do
|
|
67
|
+
@session.fill_in('Zipcode', :with => '52071350')
|
|
68
|
+
@session.click_button('awesome')
|
|
69
|
+
extract_results(@session)['zipcode'].should == '52071'
|
|
70
|
+
end
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
it "should fill in a password field by name" do
|
|
73
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
|
74
|
+
@session.click_button('awesome')
|
|
75
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
|
76
|
+
end
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
it "should fill in a password field by label" do
|
|
79
|
+
@session.fill_in('Password', :with => 'supasikrit')
|
|
80
|
+
@session.click_button('awesome')
|
|
81
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should fill in a password field by name" do
|
|
85
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
|
86
|
+
@session.click_button('awesome')
|
|
87
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
|
88
|
+
end
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
it "should throw an exception if a hash containing 'with' is not provided" do
|
|
91
|
+
lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should wait for asynchronous load", :requires => [:js] do
|
|
95
|
+
@session.visit('/with_js')
|
|
96
|
+
@session.click_link('Click me')
|
|
97
|
+
@session.fill_in('new_field', :with => 'Testing...')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "casts to string" do
|
|
101
|
+
@session.fill_in(:'form_first_name', :with => :'Harry')
|
|
102
|
+
@session.click_button('awesome')
|
|
103
|
+
extract_results(@session)['first_name'].should == 'Harry'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context 'on a pre-populated textfield with a reformatting onchange', :requires => [:js] do
|
|
107
|
+
it 'should only trigger onchange once' do
|
|
108
|
+
@session.visit('/with_js')
|
|
109
|
+
@session.fill_in('with_change_event', :with => 'some value')
|
|
110
|
+
@session.find(:css, '#with_change_event').value.should == 'some value'
|
|
89
111
|
end
|
|
112
|
+
end
|
|
90
113
|
|
|
91
|
-
|
|
92
|
-
|
|
114
|
+
context "with ignore_hidden_fields" do
|
|
115
|
+
before { Capybara.ignore_hidden_elements = true }
|
|
116
|
+
after { Capybara.ignore_hidden_elements = false }
|
|
117
|
+
it "should not find a hidden field" do
|
|
118
|
+
msg = "Unable to find field \"Super Secret\""
|
|
119
|
+
expect do
|
|
120
|
+
@session.fill_in('Super Secret', :with => '777')
|
|
121
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
93
122
|
end
|
|
123
|
+
end
|
|
94
124
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
@session.fill_in('Super Secret', :with => '777')
|
|
102
|
-
end.should raise_error(Capybara::ElementNotFound, msg)
|
|
103
|
-
end
|
|
125
|
+
context "with a locator that doesn't exist" do
|
|
126
|
+
it "should raise an error" do
|
|
127
|
+
msg = "Unable to find field \"does not exist\""
|
|
128
|
+
expect do
|
|
129
|
+
@session.fill_in('does not exist', :with => 'Blah blah')
|
|
130
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
104
131
|
end
|
|
132
|
+
end
|
|
105
133
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
end.should raise_error(Capybara::ElementNotFound, msg)
|
|
112
|
-
end
|
|
134
|
+
context "on a disabled field" do
|
|
135
|
+
it "should raise an error" do
|
|
136
|
+
expect do
|
|
137
|
+
@session.fill_in('Disabled Text Field', :with => 'Blah blah')
|
|
138
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
113
139
|
end
|
|
114
140
|
end
|
|
115
141
|
end
|