david-capybara 0.3.8

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.
Files changed (88) hide show
  1. data/History.txt +87 -0
  2. data/README.rdoc +389 -0
  3. data/lib/capybara.rb +52 -0
  4. data/lib/capybara/cucumber.rb +32 -0
  5. data/lib/capybara/driver/base.rb +48 -0
  6. data/lib/capybara/driver/celerity_driver.rb +143 -0
  7. data/lib/capybara/driver/culerity_driver.rb +25 -0
  8. data/lib/capybara/driver/rack_test_driver.rb +272 -0
  9. data/lib/capybara/driver/selenium_driver.rb +156 -0
  10. data/lib/capybara/dsl.rb +60 -0
  11. data/lib/capybara/node.rb +60 -0
  12. data/lib/capybara/rails.rb +17 -0
  13. data/lib/capybara/save_and_open_page.rb +33 -0
  14. data/lib/capybara/searchable.rb +54 -0
  15. data/lib/capybara/server.rb +114 -0
  16. data/lib/capybara/session.rb +262 -0
  17. data/lib/capybara/spec/driver.rb +162 -0
  18. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  19. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  20. data/lib/capybara/spec/public/canvas.jpg +0 -0
  21. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  22. data/lib/capybara/spec/public/jquery.js +19 -0
  23. data/lib/capybara/spec/public/test.js +33 -0
  24. data/lib/capybara/spec/session.rb +81 -0
  25. data/lib/capybara/spec/session/all_spec.rb +69 -0
  26. data/lib/capybara/spec/session/attach_file_spec.rb +64 -0
  27. data/lib/capybara/spec/session/check_spec.rb +67 -0
  28. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  29. data/lib/capybara/spec/session/click_button_spec.rb +236 -0
  30. data/lib/capybara/spec/session/click_link_spec.rb +118 -0
  31. data/lib/capybara/spec/session/click_spec.rb +24 -0
  32. data/lib/capybara/spec/session/current_url_spec.rb +8 -0
  33. data/lib/capybara/spec/session/fill_in_spec.rb +108 -0
  34. data/lib/capybara/spec/session/find_button_spec.rb +16 -0
  35. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -0
  36. data/lib/capybara/spec/session/find_field_spec.rb +22 -0
  37. data/lib/capybara/spec/session/find_link_spec.rb +17 -0
  38. data/lib/capybara/spec/session/find_spec.rb +57 -0
  39. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  40. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  41. data/lib/capybara/spec/session/has_css_spec.rb +107 -0
  42. data/lib/capybara/spec/session/has_field_spec.rb +96 -0
  43. data/lib/capybara/spec/session/has_link_spec.rb +33 -0
  44. data/lib/capybara/spec/session/has_select_spec.rb +89 -0
  45. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  46. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  47. data/lib/capybara/spec/session/headers.rb +19 -0
  48. data/lib/capybara/spec/session/javascript.rb +204 -0
  49. data/lib/capybara/spec/session/locate_spec.rb +59 -0
  50. data/lib/capybara/spec/session/select_spec.rb +83 -0
  51. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  52. data/lib/capybara/spec/session/unselect_spec.rb +54 -0
  53. data/lib/capybara/spec/session/within_spec.rb +153 -0
  54. data/lib/capybara/spec/test_app.rb +75 -0
  55. data/lib/capybara/spec/views/buttons.erb +4 -0
  56. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  57. data/lib/capybara/spec/views/form.erb +235 -0
  58. data/lib/capybara/spec/views/frame_one.erb +8 -0
  59. data/lib/capybara/spec/views/frame_two.erb +8 -0
  60. data/lib/capybara/spec/views/postback.erb +13 -0
  61. data/lib/capybara/spec/views/tables.erb +122 -0
  62. data/lib/capybara/spec/views/with_html.erb +46 -0
  63. data/lib/capybara/spec/views/with_js.erb +39 -0
  64. data/lib/capybara/spec/views/with_scope.erb +36 -0
  65. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  66. data/lib/capybara/spec/views/within_frames.erb +10 -0
  67. data/lib/capybara/version.rb +3 -0
  68. data/lib/capybara/wait_until.rb +28 -0
  69. data/lib/capybara/xpath.rb +180 -0
  70. data/spec/capybara_spec.rb +18 -0
  71. data/spec/driver/celerity_driver_spec.rb +16 -0
  72. data/spec/driver/culerity_driver_spec.rb +12 -0
  73. data/spec/driver/rack_test_driver_spec.rb +17 -0
  74. data/spec/driver/remote_culerity_driver_spec.rb +23 -0
  75. data/spec/driver/remote_selenium_driver_spec.rb +18 -0
  76. data/spec/driver/selenium_driver_spec.rb +11 -0
  77. data/spec/dsl_spec.rb +140 -0
  78. data/spec/save_and_open_page_spec.rb +43 -0
  79. data/spec/searchable_spec.rb +66 -0
  80. data/spec/server_spec.rb +53 -0
  81. data/spec/session/celerity_session_spec.rb +27 -0
  82. data/spec/session/culerity_session_spec.rb +25 -0
  83. data/spec/session/rack_test_session_spec.rb +33 -0
  84. data/spec/session/selenium_session_spec.rb +25 -0
  85. data/spec/spec_helper.rb +19 -0
  86. data/spec/wait_until_spec.rb +28 -0
  87. data/spec/xpath_spec.rb +180 -0
  88. metadata +260 -0
@@ -0,0 +1,153 @@
1
+ shared_examples_for "within" do
2
+ describe '#within' do
3
+ before do
4
+ @session.visit('/with_scope')
5
+ end
6
+
7
+ context "with CSS selector" do
8
+ it "should click links in the given scope" do
9
+ @session.within(:css, "ul li[contains('With Simple HTML')]") do
10
+ @session.click_link('Go')
11
+ end
12
+ @session.body.should include('Bar')
13
+ end
14
+ end
15
+
16
+ context "with XPath selector" do
17
+ it "should click links in the given scope" do
18
+ @session.within(:xpath, "//li[contains(.,'With Simple HTML')]") do
19
+ @session.click_link('Go')
20
+ end
21
+ @session.body.should include('Bar')
22
+ end
23
+ end
24
+
25
+ context "with the default selector" do
26
+ it "should use XPath" do
27
+ @session.within("//li[contains(., 'With Simple HTML')]") do
28
+ @session.click_link('Go')
29
+ end
30
+ @session.body.should include('Bar')
31
+ end
32
+ end
33
+
34
+ context "with the default selector set to CSS" do
35
+ before { Capybara.default_selector = :css }
36
+ it "should use CSS" do
37
+ @session.within("ul li[contains('With Simple HTML')]") do
38
+ @session.click_link('Go')
39
+ end
40
+ @session.body.should include('Bar')
41
+ end
42
+ after { Capybara.default_selector = :xpath }
43
+ end
44
+
45
+ context "with click_link" do
46
+ it "should click links in the given scope" do
47
+ @session.within("//li[contains(.,'With Simple HTML')]") do
48
+ @session.click_link('Go')
49
+ end
50
+ @session.body.should include('Bar')
51
+ end
52
+
53
+ context "with nested scopes" do
54
+ it "should respect the inner scope" do
55
+ @session.within("//div[@id='for_bar']") do
56
+ @session.within("//li[contains(.,'Bar')]") do
57
+ @session.click_link('Go')
58
+ end
59
+ end
60
+ @session.body.should include('Another World')
61
+ end
62
+
63
+ it "should respect the outer scope" do
64
+ @session.within("//div[@id='another_foo']") do
65
+ @session.within("//li[contains(.,'With Simple HTML')]") do
66
+ @session.click_link('Go')
67
+ end
68
+ end
69
+ @session.body.should include('Hello world')
70
+ end
71
+ end
72
+
73
+ it "should raise an error if the scope is not found on the page" do
74
+ running {
75
+ @session.within("//div[@id='doesnotexist']") do
76
+ end
77
+ }.should raise_error(Capybara::ElementNotFound)
78
+ end
79
+
80
+ it "should restore the scope when an error is raised" do
81
+ running {
82
+ @session.within("//div[@id='for_bar']") do
83
+ running {
84
+ running {
85
+ @session.within("//div[@id='doesnotexist']") do
86
+ end
87
+ }.should raise_error(Capybara::ElementNotFound)
88
+ }.should_not change { @session.has_xpath?("//div[@id='another_foo']") }.from(false)
89
+ end
90
+ }.should_not change { @session.has_xpath?("//div[@id='another_foo']") }.from(true)
91
+ end
92
+ end
93
+
94
+ context "with forms" do
95
+ it "should fill in a field and click a button" do
96
+ @session.within("//li[contains(.,'Bar')]") do
97
+ @session.click_button('Go')
98
+ end
99
+ extract_results(@session)['first_name'].should == 'Peter'
100
+ @session.visit('/with_scope')
101
+ @session.within("//li[contains(.,'Bar')]") do
102
+ @session.fill_in('First Name', :with => 'Dagobert')
103
+ @session.click_button('Go')
104
+ end
105
+ extract_results(@session)['first_name'].should == 'Dagobert'
106
+ end
107
+ end
108
+ end
109
+
110
+ describe '#within_fieldset' do
111
+ before do
112
+ @session.visit('/fieldsets')
113
+ end
114
+
115
+ it "should restrict scope to a fieldset given by id" do
116
+ @session.within_fieldset("villain_fieldset") do
117
+ @session.fill_in("Name", :with => 'Goldfinger')
118
+ @session.click_button("Create")
119
+ end
120
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
121
+ end
122
+
123
+ it "should restrict scope to a fieldset given by legend" do
124
+ @session.within_fieldset("Villain") do
125
+ @session.fill_in("Name", :with => 'Goldfinger')
126
+ @session.click_button("Create")
127
+ end
128
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
129
+ end
130
+ end
131
+
132
+ describe '#within_table' do
133
+ before do
134
+ @session.visit('/tables')
135
+ end
136
+
137
+ it "should restrict scope to a fieldset given by id" do
138
+ @session.within_table("girl_table") do
139
+ @session.fill_in("Name", :with => 'Christmas')
140
+ @session.click_button("Create")
141
+ end
142
+ extract_results(@session)['girl_name'].should == 'Christmas'
143
+ end
144
+
145
+ it "should restrict scope to a fieldset given by legend" do
146
+ @session.within_table("Villain") do
147
+ @session.fill_in("Name", :with => 'Quantum')
148
+ @session.click_button("Create")
149
+ end
150
+ extract_results(@session)['villain_name'].should == 'Quantum'
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,75 @@
1
+ require 'sinatra/base'
2
+ require 'rack'
3
+ require 'yaml'
4
+
5
+ class TestApp < Sinatra::Base
6
+ set :root, File.dirname(__FILE__)
7
+ set :static, true
8
+
9
+ get '/' do
10
+ 'Hello world!'
11
+ end
12
+
13
+ get '/foo' do
14
+ 'Another World'
15
+ end
16
+
17
+ get '/redirect' do
18
+ redirect '/redirect_again'
19
+ end
20
+
21
+ get '/redirect_again' do
22
+ redirect '/landed'
23
+ end
24
+
25
+ get '/landed' do
26
+ "You landed"
27
+ end
28
+
29
+ get '/with-quotes' do
30
+ %q{"No," he said, "you can't do that."}
31
+ end
32
+
33
+ get '/form/get' do
34
+ '<pre id="results">' + params[:form].to_yaml + '</pre>'
35
+ end
36
+
37
+ get '/favicon.ico' do
38
+ nil
39
+ end
40
+
41
+ post '/redirect' do
42
+ redirect '/redirect_again'
43
+ end
44
+
45
+ delete "/delete" do
46
+ "The requested object was deleted"
47
+ end
48
+
49
+ get '/redirect_back' do
50
+ redirect back
51
+ end
52
+
53
+ get '/:view' do |view|
54
+ erb view.to_sym
55
+ end
56
+
57
+ post '/form' do
58
+ '<pre id="results">' + params[:form].to_yaml + '</pre>'
59
+ end
60
+
61
+ post '/upload' do
62
+ begin
63
+ buffer = []
64
+ buffer << "Content-type: #{params[:form][:document][:type]}"
65
+ buffer << "File content: #{params[:form][:document][:tempfile].read}"
66
+ buffer.join(' | ')
67
+ rescue
68
+ 'No file uploaded'
69
+ end
70
+ end
71
+ end
72
+
73
+ if __FILE__ == $0
74
+ Rack::Handler::Mongrel.run TestApp, :Port => 8070
75
+ end
@@ -0,0 +1,4 @@
1
+ <h1>Buttons</h1>
2
+ <button>Click me!</button>
3
+ <button id="click_me_123">Click me by id!</button>
4
+ <button value="click_me">Click me by value!</button>
@@ -0,0 +1,29 @@
1
+ <form action="/form" method="post">
2
+ <fieldset id="agent_fieldset">
3
+ <legend>Agent</legend>
4
+
5
+ <p>
6
+ <label for="form_agent_name">Name</label>
7
+ <input type="text" name="form[agent_name]" value="James" id="form_agent_name"/>
8
+ </p>
9
+
10
+ <p>
11
+ <input type="submit" value="Create"/>
12
+ </p>
13
+ </fieldset>
14
+ </form>
15
+
16
+ <form action="/form" method="post">
17
+ <fieldset id="villain_fieldset">
18
+ <legend>Villain</legend>
19
+
20
+ <p>
21
+ <label for="form_villain_name">Name</label>
22
+ <input type="text" name="form[villain_name]" value="Ernst" id="form_villain_name"/>
23
+ </p>
24
+
25
+ <p>
26
+ <input type="submit" value="Create"/>
27
+ </p>
28
+ </fieldset>
29
+ </form>
@@ -0,0 +1,235 @@
1
+ <h1>Form</h1>
2
+
3
+ <form action="/form" method="post">
4
+
5
+ <p>
6
+ <label for="form_title">Title</label>
7
+ <select name="form[title]" id="form_title">
8
+ <option>Mrs</option>
9
+ <option>Mr</option>
10
+ <option>Miss</option>
11
+ </select>
12
+ </p>
13
+
14
+ <p>
15
+ <label for="form_first_name">
16
+ First Name
17
+ <input type="text" name="form[first_name]" value="John" id="form_first_name"/>
18
+ </label>
19
+ </p>
20
+
21
+ <p>
22
+ <label for="form_last_name">Last Name</label>
23
+ <input type="text" name="form[last_name]" value="Smith" id="form_last_name"/>
24
+ </p>
25
+
26
+ <p>
27
+ <label for="form_name_explanation">Explanation of Name</label>
28
+ <textarea name="form[name_explanation]" id="form_name_explanation"></textarea>
29
+ </p>
30
+
31
+ <p>
32
+ <label for="form_name">Name</label>
33
+ <input type="text" name="form[name]" value="John Smith" id="form_name"/>
34
+ </p>
35
+
36
+ <p>
37
+ <label for="form_schmooo">Schmooo</label>
38
+ <input type="schmooo" name="form[schmooo]" value="This is Schmooo!" id="form_schmooo"/>
39
+ </p>
40
+
41
+ <p>
42
+ <label>Street<br/>
43
+ <input type="text" name="form[street]" value="Sesame street 66"/>
44
+ </label>
45
+ </p>
46
+
47
+ <p>
48
+ <label for="form_phone">Phone</label>
49
+ <input type="text" name="form[phone]" value="+1 555 7021" id="form_phone"/>
50
+ </p>
51
+
52
+ <p>
53
+ <label for="form_password">Password</label>
54
+ <input type="password" name="form[password]" value="seeekrit" id="form_password"/>
55
+ </p>
56
+
57
+ <p>
58
+ <label for="form_terms_of_use">Terms of Use</label>
59
+ <input type="hidden" name="form[terms_of_use]" value="0" id="form_terms_of_use_default">
60
+ <input type="checkbox" name="form[terms_of_use]" value="1" id="form_terms_of_use">
61
+ </p>
62
+
63
+ <p>
64
+ <label for="form_image">Image</label>
65
+ <input type="file" name="form[image]" id="form_image"/>
66
+ </p>
67
+
68
+ <p>
69
+ <input type="hidden" name="form[token]" value="12345" id="form_token"/>
70
+ </p>
71
+
72
+ <p>
73
+ <label for="form_locale">Locale</label>
74
+ <select name="form[locale]" id="form_locale">
75
+ <option value="sv">Swedish</option>
76
+ <option selected="selected" value="en">English</option>
77
+ <option value="fi">Finish</option>
78
+ <option value="no">Norwegian</option>
79
+ <option value="jo">John's made-up language</option>
80
+ <option value="jbo"> Lojban </option>
81
+ </select>
82
+ </p>
83
+
84
+ <p>
85
+ <label for="form_region">Region</label>
86
+ <select name="form[region]" id="form_region">
87
+ <option>Sweden</option>
88
+ <option selected="selected">Norway</option>
89
+ <option>Finland</option>
90
+ </select>
91
+ </p>
92
+
93
+ <p>
94
+ <label for="form_city">City</label>
95
+ <select name="form[city]" id="form_city">
96
+ <option>London</option>
97
+ <option>Stockholm</option>
98
+ <option>Paris</option>
99
+ </select>
100
+ </p>
101
+
102
+ <p>
103
+ <label for="form_tendency">Tendency</label>
104
+ <select name="form[tendency]" id="form_tendency"></select>
105
+ </p>
106
+
107
+ <p>
108
+ <label for="form_description">Description</label></br>
109
+ <textarea name="form[description]" id="form_description">Descriptive text goes here</textarea>
110
+ <p>
111
+
112
+ <p>
113
+ <input type="radio" name="form[gender]" value="male" id="gender_male"/>
114
+ <label for="gender_male">Male</label>
115
+ <input type="radio" name="form[gender]" value="female" id="gender_female" checked="checked"/>
116
+ <label for="gender_female">Female</label>
117
+ <input type="radio" name="form[gender]" value="both" id="gender_both"/>
118
+ <label for="gender_both">Both</label>
119
+ </p>
120
+
121
+ <p>
122
+ <input type="checkbox" value="dog" name="form[pets][]" id="form_pets_dog" checked="checked"/>
123
+ <label for="form_pets_dog">Dog</label>
124
+ <input type="checkbox" value="cat" name="form[pets][]" id="form_pets_cat"/>
125
+ <label for="form_pets_cat">Cat</label>
126
+ <input type="checkbox" value="hamster" name="form[pets][]" id="form_pets_hamster" checked="checked"/>
127
+ <label for="form_pets_hamster">Hamster</label>
128
+ </p>
129
+
130
+ <p>
131
+ <label for="form_languages">Languages</label>
132
+ <select name="form[languages][]" id="form_languages" multiple="multiple">
133
+ <option>Ruby</option>
134
+ <option>SQL</option>
135
+ <option>HTML</option>
136
+ <option>Javascript</option>
137
+ </select>
138
+ </p>
139
+
140
+ <p>
141
+ <label for="form_underwear">Underwear</label>
142
+ <select name="form[underwear][]" id="form_underwear" multiple="multiple">
143
+ <option selected="selected">Boxer Briefs</option>
144
+ <option>Boxers</option>
145
+ <option selected="selected">Briefs</option>
146
+ <option selected="selected">Commando</option>
147
+ <option selected="selected">Frenchman's Pantalons</option>
148
+ </select>
149
+ </p>
150
+
151
+ <div style="display:none;">
152
+ <label for="form_first_name_hidden">
153
+ Super Secret
154
+ <input type="text" name="form[super_secret]" value="test123" id="form_super_secret"/>
155
+ </label>
156
+ </div>
157
+
158
+ <p>
159
+ <input type="button" name="form[fresh]" id="fresh_btn" value="i am fresh"/>
160
+ <input type="submit" name="form[awesome]" id="awe123" value="awesome"/>
161
+ <input type="submit" name="form[crappy]" id="crap321" value="crappy"/>
162
+ <input type="image" name="form[okay]" id="okay556" value="okay" alt="oh hai thar"/>
163
+ <button type="submit" id="click_me_123" value="click_me">Click me!</button>
164
+ <button type="submit" name="form[no_value]">No Value!</button>
165
+ </p>
166
+ </form>
167
+
168
+ <form action="/form/get?foo=bar" method="get">
169
+ <p>
170
+ <label for="form_middle_name">Middle Name</label>
171
+ <input type="text" name="form[middle_name]" value="Darren" id="form_middle_name"/>
172
+ </p>
173
+
174
+ <p>
175
+ <input type="submit" name="form[mediocre]" id="mediocre" value="med"/>
176
+ <p>
177
+ </form>
178
+
179
+ <form action="/upload" method="post" enctype="multipart/form-data">
180
+ <p>
181
+ <label for="form_file_name">File Name</label>
182
+ <input type="file" name="form[file_name]" id="form_file_name"/>
183
+ </p>
184
+
185
+ <p>
186
+ <label for="form_document">Document</label>
187
+ <input type="file" name="form[document]" id="form_document"/>
188
+ </p>
189
+
190
+ <p>
191
+ <input type="submit" value="Upload"/>
192
+ <p>
193
+ </form>
194
+
195
+ <form action="/redirect" method="post">
196
+ <p>
197
+ <input type="submit" value="Go FAR"/>
198
+ </p>
199
+ </form>
200
+
201
+ <form action="/form" method="post">
202
+ <p>
203
+ <label for="html5_email">Html5 Email</label>
204
+ <input type="email" name="form[html5_email]" value="person@email.com" id="html5_email"/>
205
+ </p>
206
+ <p>
207
+ <label for="html5_url">Html5 Url</label>
208
+ <input type="url" name="form[html5_url]" value="http://www.example.com" id="html5_url"/>
209
+ </p>
210
+ <p>
211
+ <label for="html5_search">Html5 Search</label>
212
+ <input type="search" name="form[html5_search]" value="what are you looking for" id="html5_search"/>
213
+ </p>
214
+ <p>
215
+ <label for="html5_tel">Html5 Tel</label>
216
+ <input type="tel" name="form[html5_tel]" value="911" id="html5_tel"/>
217
+ </p>
218
+ <p>
219
+ <label for="html5_color">Html5 Color</label>
220
+ <input type="color" name="form[html5_color]" value="#FFF" id="html5_color"/>
221
+ </p>
222
+
223
+ <p>
224
+ <input type="submit" name="form[html5_submit]" value="html5_submit"/>
225
+ </p>
226
+ </form>
227
+
228
+ <form action="/form" method="post">
229
+ <p>
230
+ <button type="submit" name="form[button]" value="button_first">Just an input that came first</button>
231
+ <button type="submit" name="form[button]" value="button_second">Just an input</button>
232
+ <input type="submit" name="form[button]" value="Just a button that came first"/>
233
+ <input type="submit" name="form[button]" value="Just a button"/>
234
+ </p>
235
+ </form>