rsel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ Gemfile.lock
2
2
  .yardoc/*
3
3
  .rvmrc
4
4
  selenium-rc.log
5
+ pkg/*
data/docs/history.md ADDED
@@ -0,0 +1,15 @@
1
+ Rsel History
2
+ ============
3
+
4
+ 0.0.2
5
+ -----
6
+
7
+ - Added `dropdown_includes` and `dropdown_equals`
8
+ - Added `link_exists` and `button_exists`
9
+
10
+
11
+ 0.0.1
12
+ -----
13
+
14
+ - Basic visibility, navigation, form fill-in and validation methods
15
+
data/docs/index.md CHANGED
@@ -10,4 +10,5 @@ you to use a natural English syntax to write web application tests.
10
10
  - [Customization](custom.md)
11
11
  - [Development](development.md)
12
12
  - [To-do list](todo.md)
13
+ - [History](history.md)
13
14
 
data/docs/todo.md CHANGED
@@ -7,9 +7,8 @@ To-do list
7
7
  mark the step as failed)
8
8
  - Find a way to abort a test if something goes catastrophically wrong (such as
9
9
  being unable to connect to the Selenium server)
10
+ - Verify the presence of images, links, buttons, checkboxes, etc.
11
+ - Click on images
12
+ - Support scoping qualifiers (somewhat like Kelp does)
10
13
 
11
- Some additional step methods needed:
12
-
13
- - dropdown_includes
14
- - dropdown_equals
15
-
14
+ Next: [History](history.md)
@@ -114,7 +114,7 @@ module Rsel
114
114
  # Reload the current page.
115
115
  #
116
116
  # @example
117
- # | refresh page |
117
+ # | Refresh page |
118
118
  #
119
119
  def refresh_page
120
120
  return_error_status do
@@ -126,7 +126,7 @@ module Rsel
126
126
  # Maximize the browser window. May not work in some browsers.
127
127
  #
128
128
  # @example
129
- # | maximize browser |
129
+ # | Maximize browser |
130
130
  #
131
131
  def maximize_browser
132
132
  @browser.window_maximize
@@ -186,6 +186,38 @@ module Rsel
186
186
  end
187
187
 
188
188
 
189
+ # Ensure that a link exists on the page.
190
+ #
191
+ # @param [String] locator
192
+ # Text or id of the link, or image alt text
193
+ #
194
+ # @example
195
+ # | Link | Logout | exists |
196
+ # | Link exists | Logout |
197
+ #
198
+ # @since 0.0.2
199
+ #
200
+ def link_exists(locator)
201
+ return @browser.element?(xpath('link', locator))
202
+ end
203
+
204
+
205
+ # Ensure that a button exists on the page.
206
+ #
207
+ # @param [String] locator
208
+ # Text, value, or id of the button
209
+ #
210
+ # @example
211
+ # | Button | Search | exists |
212
+ # | Button exists | Search |
213
+ #
214
+ # @since 0.0.2
215
+ #
216
+ def button_exists(locator)
217
+ return @browser.element?(xpath('button', locator))
218
+ end
219
+
220
+
189
221
  # Type a value into the given field.
190
222
  #
191
223
  # @param [String] text
@@ -271,53 +303,38 @@ module Rsel
271
303
  # Click on a link.
272
304
  #
273
305
  # @param [String] locator
274
- # Link text or id of the anchor element
306
+ # Text or id of the link, or image alt text
275
307
  #
276
308
  # @example
277
309
  # | Click | Logout | link |
278
310
  # | Click link | Logout |
311
+ # | Follow | Logout |
279
312
  #
280
313
  def click_link(locator)
281
314
  return_error_status do
282
315
  @browser.click(xpath('link', locator))
283
316
  end
284
317
  end
285
-
286
-
287
- # Alias for {#click_link}.
288
- #
289
- # @example
290
- # | Follow | Logout |
291
- #
292
- def follow(locator)
293
- click_link(locator)
294
- end
318
+ alias_method :follow, :click_link
295
319
 
296
320
 
297
321
  # Press a button.
298
322
  #
299
323
  # @param [String] locator
300
- # Button text, value, or id of the button
324
+ # Text, value, or id of the button
301
325
  #
302
326
  # @example
303
- # | Click | Login | button |
304
- # | Click button | Login |
327
+ # | Click | Search | button |
328
+ # | Click button | Search |
329
+ # | Press | Login |
305
330
  #
306
331
  def click_button(locator)
332
+ # TODO: Make this fail when the button is disabled
307
333
  return_error_status do
308
334
  @browser.click(xpath('button', locator))
309
335
  end
310
336
  end
311
-
312
-
313
- # Alias for {#click_button}
314
- #
315
- # @example
316
- # | Press | Search |
317
- #
318
- def press(locator)
319
- click_button(locator)
320
- end
337
+ alias_method :press, :click_button
321
338
 
322
339
 
323
340
  # Enable (check) a checkbox.
@@ -360,6 +377,8 @@ module Rsel
360
377
  # @example
361
378
  # | Checkbox is enabled | send me spam |
362
379
  # | Checkbox | send me spam | is enabled |
380
+ # | Radio is enabled | medium |
381
+ # | Radio | medium | is enabled |
363
382
  #
364
383
  def checkbox_is_enabled(locator)
365
384
  begin
@@ -370,6 +389,7 @@ module Rsel
370
389
  return enabled
371
390
  end
372
391
  end
392
+ alias_method :radio_is_enabled, :checkbox_is_enabled
373
393
 
374
394
 
375
395
  # Verify that a given checkbox or radiobutton is disabled (unchecked)
@@ -379,6 +399,9 @@ module Rsel
379
399
  #
380
400
  # @example
381
401
  # | Checkbox is disabled | send me spam |
402
+ # | Checkbox | send me spam | is disabled |
403
+ # | Radio is disabled | medium |
404
+ # | Radio | medium | is disabled |
382
405
  #
383
406
  def checkbox_is_disabled(locator)
384
407
  begin
@@ -389,6 +412,7 @@ module Rsel
389
412
  return !enabled
390
413
  end
391
414
  end
415
+ alias_method :radio_is_disabled, :checkbox_is_disabled
392
416
 
393
417
 
394
418
  # Select a radio button.
@@ -407,42 +431,63 @@ module Rsel
407
431
  end
408
432
 
409
433
 
410
- # Alias for {#checkbox_is_disabled}
434
+ # Select an option from a dropdown/combo box.
435
+ #
436
+ # @param [String] option
437
+ # The option to choose from the dropdown
438
+ # @param [String] locator
439
+ # Label, name, or id of the dropdown
411
440
  #
412
441
  # @example
413
- # | Radio is disabled | medium |
414
- # | Radio | medium | is disabled |
442
+ # | Select | Tall | from | Height | dropdown |
443
+ # | Select | Tall | from dropdown | Height |
415
444
  #
416
- def radio_is_disabled(locator)
417
- checkbox_is_disabled(locator)
445
+ def select_from_dropdown(option, locator)
446
+ return_error_status do
447
+ @browser.select(xpath('select', locator), option)
448
+ end
418
449
  end
419
450
 
420
451
 
421
- # Alias for {#checkbox_is_enabled}
452
+ # Check whether an option exists in a dropdown/combo box.
453
+ #
454
+ # @param [String] locator
455
+ # Label, name, or id of the dropdown
456
+ # @param [String] option
457
+ # The option to look for
422
458
  #
423
459
  # @example
424
- # | Radio is enabled | medium |
425
- # | Radio | medium | is enabled |
460
+ # | Dropdown | Height | includes | Tall |
461
+ #
462
+ # @since 0.0.2
426
463
  #
427
- def radio_is_enabled(locator)
428
- checkbox_is_enabled(locator)
464
+ def dropdown_includes(locator, option)
465
+ dropdown = XPath::HTML.select(locator)
466
+ opt = dropdown[XPath::HTML.option(option)]
467
+ opt_str = opt.to_xpaths.join(' | ')
468
+ return @browser.element?("xpath=#{opt_str}")
429
469
  end
430
470
 
431
471
 
432
- # Select a value from a dropdown/combo box.
472
+ # Check whether an option is currently selected in a dropdown/combo box.
433
473
  #
434
- # @param [String] value
435
- # The value to choose from the dropdown
436
474
  # @param [String] locator
437
475
  # Label, name, or id of the dropdown
476
+ # @param [String] option
477
+ # The option you expect to be selected
438
478
  #
439
479
  # @example
440
- # | select | Tall | from | Height | dropdown |
441
- # | select | Tall | from dropdown | Height |
480
+ # | Dropdown | Height | equals | Tall |
442
481
  #
443
- def select_from_dropdown(value, locator)
444
- return_error_status do
445
- @browser.select(xpath('select', locator), value)
482
+ # @since 0.0.2
483
+ #
484
+ def dropdown_equals(locator, option)
485
+ begin
486
+ selected = @browser.get_selected_label(xpath('select', locator))
487
+ rescue
488
+ return false
489
+ else
490
+ return selected == option
446
491
  end
447
492
  end
448
493
 
@@ -497,6 +542,7 @@ module Rsel
497
542
  end
498
543
  end
499
544
 
545
+
500
546
  # Return a Selenium-style xpath for the given locator.
501
547
  #
502
548
  # @param [String] kind
data/rsel.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rsel"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.summary = "Runs Selenium tests from FitNesse"
5
5
  s.description = <<-EOS
6
6
  Rsel provides a Slim fixture for running Selenium tests, with
@@ -1,25 +1,25 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
2
 
3
3
  describe Rsel::SeleniumTest do
4
- context 'initialization' do
4
+ context "initialization" do
5
5
  before(:each) do
6
- @st.visit('/')
6
+ @st.visit("/")
7
7
  end
8
8
 
9
9
  it "sets correct default configuration" do
10
- @st.url.should == 'http://localhost:8070/'
11
- @st.browser.host.should == 'localhost'
10
+ @st.url.should == "http://localhost:8070/"
11
+ @st.browser.host.should == "localhost"
12
12
  @st.browser.port.should == 4444
13
13
  end
14
14
  end
15
15
 
16
16
 
17
- context 'checkbox' do
17
+ context "checkbox" do
18
18
  before(:each) do
19
- @st.visit('/form').should be_true
19
+ @st.visit("/form").should be_true
20
20
  end
21
21
 
22
- context "enable" do
22
+ describe "#enable_checkbox" do
23
23
  context "passes when" do
24
24
  it "checkbox with the given label is present" do
25
25
  @st.enable_checkbox("I like cheese").should be_true
@@ -35,7 +35,7 @@ describe Rsel::SeleniumTest do
35
35
  end
36
36
  end
37
37
 
38
- context "disable" do
38
+ describe "#disable_checkbox" do
39
39
  context "passes when" do
40
40
  it "checkbox with the given label is present" do
41
41
  @st.disable_checkbox("I like cheese").should be_true
@@ -50,7 +50,7 @@ describe Rsel::SeleniumTest do
50
50
  end
51
51
  end
52
52
 
53
- context "is enabled" do
53
+ describe "#checkbox_is_enabled" do
54
54
  context "passes when" do
55
55
  it "checkbox with the given label exists and is checked" do
56
56
  @st.enable_checkbox("I like cheese").should be_true
@@ -70,7 +70,7 @@ describe Rsel::SeleniumTest do
70
70
  end
71
71
  end
72
72
 
73
- context "is disabled" do
73
+ describe "#checkbox_is_disabled" do
74
74
  context "passes when" do
75
75
  it "checkbox with the given label exists and is unchecked" do
76
76
  @st.disable_checkbox("I like cheese").should be_true
@@ -92,21 +92,21 @@ describe Rsel::SeleniumTest do
92
92
  end
93
93
 
94
94
 
95
- context 'dropdown' do
95
+ context "dropdowns" do
96
96
  before(:each) do
97
- @st.visit('/form').should be_true
97
+ @st.visit("/form").should be_true
98
98
  end
99
99
 
100
- context "select" do
100
+ context "#select_from_dropdown" do
101
101
  context "passes when" do
102
- it "value exists in a dropdown" do
102
+ it "option exists in the dropdown" do
103
103
  @st.select_from_dropdown("Tall", "Height").should be_true
104
104
  @st.select_from_dropdown("Medium", "Weight").should be_true
105
105
  end
106
106
  end
107
107
 
108
108
  context "fails when" do
109
- it "dropdown exists, but the value doesn't" do
109
+ it "dropdown exists, but the option doesn't" do
110
110
  @st.select_from_dropdown("Giant", "Height").should be_false
111
111
  @st.select_from_dropdown("Obese", "Weight").should be_false
112
112
  end
@@ -117,18 +117,69 @@ describe Rsel::SeleniumTest do
117
117
  end
118
118
  end
119
119
 
120
- context "verify" do
121
- # TODO
120
+ context "#dropdown_includes" do
121
+ context "passes when" do
122
+ it "option exists in the dropdown" do
123
+ @st.dropdown_includes("Height", "Tall").should be_true
124
+ @st.dropdown_includes("Weight", "Medium").should be_true
125
+ end
126
+ end
127
+
128
+ context "fails when" do
129
+ it "dropdown exists, but the option doesn't" do
130
+ @st.dropdown_includes("Height", "Giant").should be_false
131
+ @st.dropdown_includes("Weight", "Obese").should be_false
132
+ end
133
+
134
+ it "no such dropdown exists" do
135
+ @st.dropdown_includes("Eggs", "Over easy").should be_false
136
+ end
137
+ end
138
+ end
139
+
140
+ context "#dropdown_equals" do
141
+ context "passes when" do
142
+ it "option is selected in the dropdown" do
143
+ @st.select_from_dropdown("Short", "Height")
144
+ @st.dropdown_equals("Height", "Short").should be_true
145
+
146
+ @st.select_from_dropdown("Average", "Height")
147
+ @st.dropdown_equals("Height", "Average").should be_true
148
+
149
+ @st.select_from_dropdown("Tall", "Height")
150
+ @st.dropdown_equals("Height", "Tall").should be_true
151
+ end
152
+ end
153
+
154
+ context "fails when" do
155
+ it "dropdown exists, but the option is not selected" do
156
+ @st.select_from_dropdown("Short", "Height")
157
+ @st.dropdown_equals("Height", "Average").should be_false
158
+ @st.dropdown_equals("Height", "Tall").should be_false
159
+
160
+ @st.select_from_dropdown("Average", "Height")
161
+ @st.dropdown_equals("Height", "Short").should be_false
162
+ @st.dropdown_equals("Height", "Tall").should be_false
163
+
164
+ @st.select_from_dropdown("Tall", "Height")
165
+ @st.dropdown_equals("Height", "Short").should be_false
166
+ @st.dropdown_equals("Height", "Average").should be_false
167
+ end
168
+
169
+ it "no such dropdown exists" do
170
+ @st.dropdown_equals("Eggs", "Over easy").should be_false
171
+ end
172
+ end
122
173
  end
123
174
  end
124
175
 
125
176
 
126
- context 'navigation' do
177
+ context "navigation" do
127
178
  before(:each) do
128
- @st.visit('/').should be_true
179
+ @st.visit("/").should be_true
129
180
  end
130
181
 
131
- context "visit" do
182
+ describe "#visit" do
132
183
  context "passes when" do
133
184
  it "page exists" do
134
185
  @st.visit("/about").should be_true
@@ -146,7 +197,7 @@ describe Rsel::SeleniumTest do
146
197
  # TODO
147
198
  end
148
199
 
149
- context "go back to the previous page" do
200
+ describe "#click_back" do
150
201
  it "passes and loads the correct URL" do
151
202
  @st.visit("/about")
152
203
  @st.visit("/")
@@ -159,8 +210,15 @@ describe Rsel::SeleniumTest do
159
210
  # same session
160
211
  #end
161
212
  end
213
+ end
214
+
215
+
216
+ context "links" do
217
+ before(:each) do
218
+ @st.visit("/").should be_true
219
+ end
162
220
 
163
- context "clicking a link" do
221
+ describe "#click_link" do
164
222
  it "passes and loads the correct page when a link exists" do
165
223
  @st.click_link("About this site").should be_true
166
224
  @st.see_title("About this site").should be_true
@@ -168,18 +226,75 @@ describe Rsel::SeleniumTest do
168
226
  end
169
227
 
170
228
  it "fails when a link does not exist" do
171
- @st.follow("Bogus link").should be_false
229
+ @st.click_link("Bogus link").should be_false
230
+ end
231
+ end
232
+
233
+ describe "#link_exists" do
234
+ context "passes when" do
235
+ it "link with the given text exists" do
236
+ @st.link_exists("About this site").should be_true
237
+ @st.link_exists("Form test").should be_true
238
+ end
239
+ end
240
+
241
+ context "fails when" do
242
+ it "no such link exists" do
243
+ @st.link_exists("Welcome").should be_false
244
+ @st.link_exists("Don't click here").should be_false
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+
251
+ context "buttons" do
252
+ before(:each) do
253
+ @st.visit("/form").should be_true
254
+ end
255
+
256
+ describe "#click_button" do
257
+ context "passes when" do
258
+ it "button exists and is enabled" do
259
+ @st.click_button("Submit person form").should be_true
260
+ end
261
+ end
262
+
263
+ context "fails when" do
264
+ it "button does not exist" do
265
+ @st.click_button("No such button").should be_false
266
+ end
267
+
268
+ it "button exists but is disabled" do
269
+ # TODO
270
+ end
271
+ end
272
+ end
273
+
274
+ describe "#button_exists" do
275
+ context "passes when" do
276
+ it "button with the given text exists" do
277
+ @st.button_exists("Submit person form").should be_true
278
+ @st.button_exists("Save preferences").should be_true
279
+ end
280
+ end
281
+
282
+ context "fails when" do
283
+ it "no such button exists" do
284
+ @st.button_exists("Apple").should be_false
285
+ @st.button_exists("Big Red").should be_false
286
+ end
172
287
  end
173
288
  end
174
289
  end
175
290
 
176
291
 
177
- context 'text field' do
292
+ context "fields" do
178
293
  before(:each) do
179
- @st.visit('/form').should be_true
294
+ @st.visit("/form").should be_true
180
295
  end
181
296
 
182
- context "type into or fill in" do
297
+ describe "#type_into_field" do
183
298
  context "passes when" do
184
299
  it "text field with the given label exists" do
185
300
  @st.type_into_field("Eric", "First name").should be_true
@@ -210,7 +325,7 @@ describe Rsel::SeleniumTest do
210
325
  end
211
326
  end
212
327
 
213
- context "should contain" do
328
+ describe "#field_contains" do
214
329
  context "passes when" do
215
330
  it "textarea contains the text" do
216
331
  @st.fill_in_with("Life story", "Blah dee blah")
@@ -226,7 +341,7 @@ describe Rsel::SeleniumTest do
226
341
  end
227
342
  end
228
343
 
229
- context "should equal" do
344
+ describe "#field_equals" do
230
345
  context "passes when" do
231
346
  it "textarea equals the text" do
232
347
  @st.fill_in_with("Life story", "Blah dee blah")
@@ -244,50 +359,50 @@ describe Rsel::SeleniumTest do
244
359
  end
245
360
 
246
361
 
247
- context 'visibility' do
362
+ context "visibility" do
248
363
  before(:each) do
249
- @st.visit('/').should be_true
364
+ @st.visit("/").should be_true
250
365
  end
251
366
 
252
- context "should see" do
367
+ describe "#see" do
253
368
  context "passes when" do
254
369
  it "text is present" do
255
- @st.see('Welcome').should be_true
256
- @st.see('This is a Sinatra webapp').should be_true
370
+ @st.see("Welcome").should be_true
371
+ @st.see("This is a Sinatra webapp").should be_true
257
372
  end
258
373
  end
259
374
 
260
375
  context "fails when" do
261
376
  it "text is absent" do
262
- @st.see('Nonexistent').should be_false
263
- @st.see('Some bogus text').should be_false
377
+ @st.see("Nonexistent").should be_false
378
+ @st.see("Some bogus text").should be_false
264
379
  end
265
380
  end
266
381
 
267
382
  it "is case-sensitive" do
268
- @st.see('Sinatra webapp').should be_true
269
- @st.see('sinatra Webapp').should be_false
383
+ @st.see("Sinatra webapp").should be_true
384
+ @st.see("sinatra Webapp").should be_false
270
385
  end
271
386
  end
272
387
 
273
- context "should not see" do
388
+ describe "#do_not_see" do
274
389
  context "passes when" do
275
390
  it "text is absent" do
276
- @st.do_not_see('Nonexistent').should be_true
277
- @st.do_not_see('Some bogus text').should be_true
391
+ @st.do_not_see("Nonexistent").should be_true
392
+ @st.do_not_see("Some bogus text").should be_true
278
393
  end
279
394
  end
280
395
 
281
396
  context "fails when" do
282
397
  it "fails when test is present" do
283
- @st.do_not_see('Welcome').should be_false
284
- @st.do_not_see('This is a Sinatra webapp').should be_false
398
+ @st.do_not_see("Welcome").should be_false
399
+ @st.do_not_see("This is a Sinatra webapp").should be_false
285
400
  end
286
401
  end
287
402
 
288
403
  it "is case-sensitive" do
289
- @st.do_not_see('Sinatra webapp').should be_false
290
- @st.do_not_see('sinatra Webapp').should be_true
404
+ @st.do_not_see("Sinatra webapp").should be_false
405
+ @st.do_not_see("sinatra Webapp").should be_true
291
406
  end
292
407
  end
293
408
  end
data/test/app.rb CHANGED
@@ -21,6 +21,10 @@ class TestApp < Sinatra::Base
21
21
  erb :form
22
22
  end
23
23
 
24
+ get '/thanks' do
25
+ erb :thanks
26
+ end
27
+
24
28
  # Allow shutting down the app with a request
25
29
  get '/shutdown' do
26
30
  Process.kill('KILL', Process.pid)
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head><title>Thanks</title></head>
3
+ <body>
4
+ <h1>Thank You</h1>
5
+ <p>We appreciate your feedback</p>
6
+ </body>
7
+ </html>
8
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcus French
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-07-20 00:00:00 -06:00
20
+ date: 2011-07-21 00:00:00 -06:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -153,6 +153,7 @@ files:
153
153
  - Rakefile
154
154
  - docs/custom.md
155
155
  - docs/development.md
156
+ - docs/history.md
156
157
  - docs/index.md
157
158
  - docs/install.md
158
159
  - docs/todo.md
@@ -168,6 +169,7 @@ files:
168
169
  - test/views/about.erb
169
170
  - test/views/form.erb
170
171
  - test/views/index.erb
172
+ - test/views/thanks.erb
171
173
  - vendor/rubyslim-0.1.1/.gitignore
172
174
  - vendor/rubyslim-0.1.1/README.md
173
175
  - vendor/rubyslim-0.1.1/Rakefile