bbc-capybara 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +325 -0
- data/License.txt +22 -0
- data/README.md +815 -0
- data/lib/capybara.rb +368 -0
- data/lib/capybara/cucumber.rb +25 -0
- data/lib/capybara/driver/base.rb +64 -0
- data/lib/capybara/driver/node.rb +74 -0
- data/lib/capybara/dsl.rb +50 -0
- data/lib/capybara/node/actions.rb +146 -0
- data/lib/capybara/node/base.rb +63 -0
- data/lib/capybara/node/document.rb +25 -0
- data/lib/capybara/node/element.rb +201 -0
- data/lib/capybara/node/finders.rb +154 -0
- data/lib/capybara/node/matchers.rb +442 -0
- data/lib/capybara/node/simple.rb +132 -0
- data/lib/capybara/query.rb +63 -0
- data/lib/capybara/rack_test/browser.rb +126 -0
- data/lib/capybara/rack_test/driver.rb +80 -0
- data/lib/capybara/rack_test/form.rb +80 -0
- data/lib/capybara/rack_test/node.rb +121 -0
- data/lib/capybara/rails.rb +17 -0
- data/lib/capybara/rspec.rb +26 -0
- data/lib/capybara/rspec/features.rb +22 -0
- data/lib/capybara/rspec/matchers.rb +152 -0
- data/lib/capybara/selector.rb +156 -0
- data/lib/capybara/selenium/driver.rb +169 -0
- data/lib/capybara/selenium/node.rb +91 -0
- data/lib/capybara/server.rb +87 -0
- data/lib/capybara/session.rb +322 -0
- data/lib/capybara/spec/driver.rb +329 -0
- data/lib/capybara/spec/fixtures/capybara.jpg +3 -0
- data/lib/capybara/spec/fixtures/test_file.txt +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +791 -0
- data/lib/capybara/spec/public/jquery.js +9046 -0
- data/lib/capybara/spec/public/test.js +43 -0
- data/lib/capybara/spec/session.rb +148 -0
- data/lib/capybara/spec/session/all_spec.rb +78 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +76 -0
- data/lib/capybara/spec/session/check_spec.rb +68 -0
- data/lib/capybara/spec/session/choose_spec.rb +29 -0
- data/lib/capybara/spec/session/click_button_spec.rb +305 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +37 -0
- data/lib/capybara/spec/session/click_link_spec.rb +120 -0
- data/lib/capybara/spec/session/current_url_spec.rb +83 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +127 -0
- data/lib/capybara/spec/session/find_button_spec.rb +18 -0
- data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
- data/lib/capybara/spec/session/find_field_spec.rb +26 -0
- data/lib/capybara/spec/session/find_link_spec.rb +19 -0
- data/lib/capybara/spec/session/find_spec.rb +168 -0
- data/lib/capybara/spec/session/first_spec.rb +105 -0
- data/lib/capybara/spec/session/has_button_spec.rb +32 -0
- data/lib/capybara/spec/session/has_css_spec.rb +243 -0
- data/lib/capybara/spec/session/has_field_spec.rb +192 -0
- data/lib/capybara/spec/session/has_link_spec.rb +37 -0
- data/lib/capybara/spec/session/has_select_spec.rb +129 -0
- data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
- data/lib/capybara/spec/session/has_table_spec.rb +34 -0
- data/lib/capybara/spec/session/has_text_spec.rb +138 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
- data/lib/capybara/spec/session/headers.rb +19 -0
- data/lib/capybara/spec/session/javascript.rb +312 -0
- data/lib/capybara/spec/session/response_code.rb +19 -0
- data/lib/capybara/spec/session/select_spec.rb +119 -0
- data/lib/capybara/spec/session/text_spec.rb +24 -0
- data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
- data/lib/capybara/spec/session/unselect_spec.rb +67 -0
- data/lib/capybara/spec/session/within_spec.rb +178 -0
- data/lib/capybara/spec/test_app.rb +156 -0
- data/lib/capybara/spec/views/buttons.erb +4 -0
- data/lib/capybara/spec/views/fieldsets.erb +29 -0
- data/lib/capybara/spec/views/form.erb +366 -0
- data/lib/capybara/spec/views/frame_one.erb +8 -0
- data/lib/capybara/spec/views/frame_two.erb +8 -0
- data/lib/capybara/spec/views/header_links.erb +7 -0
- data/lib/capybara/spec/views/host_links.erb +12 -0
- data/lib/capybara/spec/views/popup_one.erb +8 -0
- data/lib/capybara/spec/views/popup_two.erb +8 -0
- data/lib/capybara/spec/views/postback.erb +13 -0
- data/lib/capybara/spec/views/tables.erb +62 -0
- data/lib/capybara/spec/views/with_html.erb +75 -0
- data/lib/capybara/spec/views/with_html_entities.erb +1 -0
- data/lib/capybara/spec/views/with_js.erb +53 -0
- data/lib/capybara/spec/views/with_scope.erb +36 -0
- data/lib/capybara/spec/views/with_simple_html.erb +1 -0
- data/lib/capybara/spec/views/within_frames.erb +10 -0
- data/lib/capybara/spec/views/within_popups.erb +25 -0
- data/lib/capybara/util/save_and_open_page.rb +45 -0
- data/lib/capybara/util/timeout.rb +27 -0
- data/lib/capybara/version.rb +3 -0
- data/spec/basic_node_spec.rb +89 -0
- data/spec/capybara_spec.rb +46 -0
- data/spec/driver/rack_test_driver_spec.rb +90 -0
- data/spec/driver/selenium_driver_spec.rb +55 -0
- data/spec/dsl_spec.rb +255 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +8 -0
- data/spec/fixtures/selenium_driver_rspec_success.rb +8 -0
- data/spec/rspec/features_spec.rb +43 -0
- data/spec/rspec/matchers_spec.rb +564 -0
- data/spec/rspec_spec.rb +51 -0
- data/spec/save_and_open_page_spec.rb +155 -0
- data/spec/server_spec.rb +74 -0
- data/spec/session/rack_test_session_spec.rb +61 -0
- data/spec/session/selenium_session_spec.rb +26 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/timeout_spec.rb +28 -0
- metadata +297 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
var activeRequests = 0;
|
2
|
+
$(function() {
|
3
|
+
$('#change').text('I changed it');
|
4
|
+
$('#drag').draggable();
|
5
|
+
$('#drop').droppable({
|
6
|
+
drop: function(event, ui) {
|
7
|
+
ui.draggable.remove();
|
8
|
+
$(this).html('Dropped!');
|
9
|
+
}
|
10
|
+
});
|
11
|
+
$('#clickable').click(function() {
|
12
|
+
var link = $(this);
|
13
|
+
setTimeout(function() {
|
14
|
+
$(link).after('<a id="has-been-clicked" href="#">Has been clicked</a>');
|
15
|
+
$(link).after('<input type="submit" value="New Here">');
|
16
|
+
$(link).after('<input type="text" id="new_field">');
|
17
|
+
$('#change').remove();
|
18
|
+
}, 500);
|
19
|
+
return false;
|
20
|
+
});
|
21
|
+
$('#waiter').change(function() {
|
22
|
+
activeRequests = 1;
|
23
|
+
setTimeout(function() {
|
24
|
+
activeRequests = 0;
|
25
|
+
}, 500);
|
26
|
+
});
|
27
|
+
$('#with_focus_event').focus(function() {
|
28
|
+
$('body').append('<p id="focus_event_triggered">Focus Event triggered</p>');
|
29
|
+
});
|
30
|
+
$('#checkbox_with_event').click(function() {
|
31
|
+
$('body').append('<p id="checkbox_event_triggered">Checkbox event triggered</p>');
|
32
|
+
});
|
33
|
+
$('#fire_ajax_request').click(function() {
|
34
|
+
$.ajax({url: "/slow_response", context: document.body, success: function() {
|
35
|
+
$('body').append('<p id="ajax_request_done">Ajax request done</p>');
|
36
|
+
}});
|
37
|
+
});
|
38
|
+
$('#reload-link').click(function() {
|
39
|
+
setTimeout(function() {
|
40
|
+
$('#reload-me').replaceWith('<div id="reload-me"><em><a>RELOADED</a></em></div>');
|
41
|
+
}, 250)
|
42
|
+
});
|
43
|
+
});
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'capybara/spec/test_app'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
Dir[File.dirname(__FILE__)+'/session/*'].each { |group| require group }
|
5
|
+
|
6
|
+
shared_examples_for "session" do
|
7
|
+
def extract_results(session)
|
8
|
+
YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.text.lstrip
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
@session.reset_session!
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#visit' do
|
16
|
+
it "should fetch a response from the driver" do
|
17
|
+
@session.visit('/')
|
18
|
+
@session.body.should include('Hello world!')
|
19
|
+
@session.visit('/foo')
|
20
|
+
@session.body.should include('Another World')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#body' do
|
25
|
+
it "should return the unmodified page body" do
|
26
|
+
@session.visit('/')
|
27
|
+
@session.body.should include('Hello world!')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#html' do
|
32
|
+
it "should return the unmodified page body" do
|
33
|
+
# html and body should be aliased, but we can't just check for
|
34
|
+
# method(:html) == method(:body) because these shared examples get run
|
35
|
+
# against the DSL, which uses forwarding methods. So we test behavior.
|
36
|
+
@session.visit('/')
|
37
|
+
@session.body.should include('Hello world!')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#source' do
|
42
|
+
it "should return the unmodified page source" do
|
43
|
+
@session.visit('/')
|
44
|
+
@session.source.should include('Hello world!')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#reset_session!' do
|
49
|
+
it "removes cookies" do
|
50
|
+
@session.visit('/set_cookie')
|
51
|
+
@session.visit('/get_cookie')
|
52
|
+
@session.body.should include('test_cookie')
|
53
|
+
|
54
|
+
@session.reset_session!
|
55
|
+
@session.visit('/get_cookie')
|
56
|
+
@session.body.should_not include('test_cookie')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "resets current url, host, path" do
|
60
|
+
@session.visit '/foo'
|
61
|
+
@session.current_url.should_not be_empty
|
62
|
+
@session.current_host.should_not be_empty
|
63
|
+
@session.current_path.should == '/foo'
|
64
|
+
|
65
|
+
@session.reset_session!
|
66
|
+
[nil, '', 'about:blank'].should include @session.current_url
|
67
|
+
@session.current_host.should be_nil
|
68
|
+
@session.current_path.should be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "resets page body" do
|
72
|
+
@session.visit('/with_html')
|
73
|
+
@session.body.should include('This is a test')
|
74
|
+
@session.find('.//h1').text.should include('This is a test')
|
75
|
+
|
76
|
+
@session.reset_session!
|
77
|
+
@session.body.should_not include('This is a test')
|
78
|
+
@session.should have_no_selector('.//h1')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it_should_behave_like "all"
|
83
|
+
it_should_behave_like "first"
|
84
|
+
it_should_behave_like "attach_file"
|
85
|
+
it_should_behave_like "check"
|
86
|
+
it_should_behave_like "choose"
|
87
|
+
it_should_behave_like "click_link_or_button"
|
88
|
+
it_should_behave_like "click_button"
|
89
|
+
it_should_behave_like "click_link"
|
90
|
+
it_should_behave_like "fill_in"
|
91
|
+
it_should_behave_like "find_button"
|
92
|
+
it_should_behave_like "find_field"
|
93
|
+
it_should_behave_like "find_link"
|
94
|
+
it_should_behave_like "find_by_id"
|
95
|
+
it_should_behave_like "find"
|
96
|
+
it_should_behave_like "has_text"
|
97
|
+
it_should_behave_like "has_css"
|
98
|
+
it_should_behave_like "has_selector"
|
99
|
+
it_should_behave_like "has_xpath"
|
100
|
+
it_should_behave_like "has_link"
|
101
|
+
it_should_behave_like "has_button"
|
102
|
+
it_should_behave_like "has_field"
|
103
|
+
it_should_behave_like "has_select"
|
104
|
+
it_should_behave_like "has_table"
|
105
|
+
it_should_behave_like "select"
|
106
|
+
it_should_behave_like "text"
|
107
|
+
it_should_behave_like "uncheck"
|
108
|
+
it_should_behave_like "unselect"
|
109
|
+
it_should_behave_like "within"
|
110
|
+
it_should_behave_like "current_url"
|
111
|
+
|
112
|
+
it "should encode complex field names, like array[][value]" do
|
113
|
+
@session.visit('/form')
|
114
|
+
@session.fill_in('address1_city', :with =>'Paris')
|
115
|
+
@session.fill_in('address1_street', :with =>'CDG')
|
116
|
+
@session.fill_in('address1_street', :with =>'CDG')
|
117
|
+
@session.select("France", :from => 'address1_country')
|
118
|
+
|
119
|
+
@session.fill_in('address2_city', :with => 'Mikolaiv')
|
120
|
+
@session.fill_in('address2_street', :with => 'PGS')
|
121
|
+
@session.select("Ukraine", :from => 'address2_country')
|
122
|
+
|
123
|
+
@session.click_button "awesome"
|
124
|
+
|
125
|
+
addresses=extract_results(@session)["addresses"]
|
126
|
+
addresses.should have(2).addresses
|
127
|
+
|
128
|
+
addresses[0]["street"].should == 'CDG'
|
129
|
+
addresses[0]["city"].should == 'Paris'
|
130
|
+
addresses[0]["country"].should == 'France'
|
131
|
+
|
132
|
+
addresses[1]["street"].should == 'PGS'
|
133
|
+
addresses[1]["city"].should == 'Mikolaiv'
|
134
|
+
addresses[1]["country"].should == 'Ukraine'
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
describe Capybara::Session do
|
141
|
+
context 'with non-existant driver' do
|
142
|
+
it "should raise an error" do
|
143
|
+
running {
|
144
|
+
Capybara::Session.new(:quox, TestApp).driver
|
145
|
+
}.should raise_error(Capybara::DriverNotFoundError)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,78 @@
|
|
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 = XPath::HTML.fillable_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 all elements using the given selector" 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'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should find all elements when given a list of selectors" do
|
31
|
+
@session.all(:css, 'h1, p').should have(4).elements
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with xpath selectors" do
|
36
|
+
it "should find the first element using the given locator" do
|
37
|
+
@session.all(:xpath, '//h1').first.text.should == 'This is a test'
|
38
|
+
@session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with css as default selector" do
|
43
|
+
before { Capybara.default_selector = :css }
|
44
|
+
it "should find the first element using the given locator" do
|
45
|
+
@session.all('h1').first.text.should == 'This is a test'
|
46
|
+
@session.all("input[id='test_field']").first[:value].should == 'monkey'
|
47
|
+
end
|
48
|
+
after { Capybara.default_selector = :xpath }
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with visible filter" do
|
52
|
+
after { Capybara.ignore_hidden_elements = false }
|
53
|
+
it "should only find visible nodes" do
|
54
|
+
@session.all("//a[@title='awesome title']").should have(2).elements
|
55
|
+
@session.all("//a[@title='awesome title']", :visible => true).should have(1).elements
|
56
|
+
Capybara.ignore_hidden_elements = true
|
57
|
+
@session.all("//a[@title='awesome title']").should have(1).elements
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should only find invisible nodes" do
|
61
|
+
Capybara.ignore_hidden_elements = true
|
62
|
+
@session.all("//a[@title='awesome title']", :visible => false).should have(2).elements
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "within a scope" do
|
67
|
+
before do
|
68
|
+
@session.visit('/with_scope')
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should find any element using the given locator" do
|
72
|
+
@session.within(:xpath, "//div[@id='for_bar']") do
|
73
|
+
@session.all('.//li').should have(2).elements
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
shared_examples_for "attach_file" do
|
2
|
+
|
3
|
+
describe "#attach_file" do
|
4
|
+
before do
|
5
|
+
@test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
|
6
|
+
@test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
|
7
|
+
@session.visit('/form')
|
8
|
+
end
|
9
|
+
|
10
|
+
context "with normal form" do
|
11
|
+
it "should set a file path by id" do
|
12
|
+
@session.attach_file "form_image", __FILE__
|
13
|
+
@session.click_button('awesome')
|
14
|
+
extract_results(@session)['image'].should == File.basename(__FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set a file path by label" do
|
18
|
+
@session.attach_file "Image", __FILE__
|
19
|
+
@session.click_button('awesome')
|
20
|
+
extract_results(@session)['image'].should == File.basename(__FILE__)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with multipart form" do
|
25
|
+
it "should set a file path by id" do
|
26
|
+
@session.attach_file "form_document", @test_file_path
|
27
|
+
@session.click_button('Upload')
|
28
|
+
@session.body.should include(File.read(@test_file_path))
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set a file path by label" do
|
32
|
+
@session.attach_file "Document", @test_file_path
|
33
|
+
@session.click_button('Upload')
|
34
|
+
@session.body.should include(File.read(@test_file_path))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not break if no file is submitted" do
|
38
|
+
@session.click_button('Upload')
|
39
|
+
@session.body.should include('No file uploaded')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should send content type text/plain when uploading a text file" do
|
43
|
+
@session.attach_file "Document", @test_file_path
|
44
|
+
@session.click_button 'Upload'
|
45
|
+
@session.body.should include('text/plain')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should send content type image/jpeg when uploading an image" do
|
49
|
+
@session.attach_file "Document", @test_jpg_file_path
|
50
|
+
@session.click_button 'Upload'
|
51
|
+
@session.body.should include('image/jpeg')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not break when using HTML5 multiple file input" do
|
55
|
+
@session.attach_file "Multiple Documents", @test_file_path
|
56
|
+
@session.click_button('Upload Multiple')
|
57
|
+
@session.body.should include(File.read(@test_file_path))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with a locator that doesn't exist" do
|
62
|
+
it "should raise an error" do
|
63
|
+
msg = "no file field with id, name, or label 'does not exist' found"
|
64
|
+
running do
|
65
|
+
@session.attach_file('does not exist', @test_file_path)
|
66
|
+
end.should raise_error(Capybara::ElementNotFound, msg)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with a path that doesn't exist" do
|
71
|
+
it "should raise an error" do
|
72
|
+
running { @session.attach_file('Image', '/no_such_file.png') }.should raise_error(Capybara::FileNotFound)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
shared_examples_for "check" do
|
2
|
+
|
3
|
+
describe "#check" do
|
4
|
+
before do
|
5
|
+
@session.visit('/form')
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "'checked' attribute" do
|
9
|
+
it "should be true if checked" do
|
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
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "checking" do
|
20
|
+
it "should not change an already checked checkbox" do
|
21
|
+
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
|
22
|
+
@session.check('form_pets_dog')
|
23
|
+
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should check an unchecked checkbox" do
|
27
|
+
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
|
28
|
+
@session.check('form_pets_cat')
|
29
|
+
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "unchecking" do
|
34
|
+
it "should not change an already unchecked checkbox" do
|
35
|
+
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
|
36
|
+
@session.uncheck('form_pets_cat')
|
37
|
+
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should uncheck a checked checkbox" do
|
41
|
+
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
|
42
|
+
@session.uncheck('form_pets_dog')
|
43
|
+
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should check a checkbox by id" do
|
48
|
+
@session.check("form_pets_cat")
|
49
|
+
@session.click_button('awesome')
|
50
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should check a checkbox by label" do
|
54
|
+
@session.check("Cat")
|
55
|
+
@session.click_button('awesome')
|
56
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with a locator that doesn't exist" do
|
60
|
+
it "should raise an error" do
|
61
|
+
msg = "no checkbox with id, name, or label 'does not exist' found"
|
62
|
+
running do
|
63
|
+
@session.check('does not exist')
|
64
|
+
end.should raise_error(Capybara::ElementNotFound, msg)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
shared_examples_for "choose" do
|
2
|
+
|
3
|
+
describe "#choose" do
|
4
|
+
before do
|
5
|
+
@session.visit('/form')
|
6
|
+
end
|
7
|
+
|
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
|
13
|
+
|
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
|
19
|
+
|
20
|
+
context "with a locator that doesn't exist" do
|
21
|
+
it "should raise an error" do
|
22
|
+
msg = "no radio button with id, name, or label 'does not exist' found"
|
23
|
+
running do
|
24
|
+
@session.choose('does not exist')
|
25
|
+
end.should raise_error(Capybara::ElementNotFound, msg)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|