Home arrow Ruby-on-Rails arrow Page 5 - Recording Acceptance Tests
RUBY-ON-RAILS

Recording Acceptance Tests


In this conclusion to a three-part article series on acceptance testing with Ruby on Rails, you'll learn how to use the Selenium IDE and how (and why) to record the results of your acceptance tests. This article is excerpted from chapter 11 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
July 30, 2010
TABLE OF CONTENTS:
  1. · Recording Acceptance Tests
  2. · Recording the View Forum Acceptance Test
  3. · Recording the Post to Forum Acceptance Test
  4. · Recording the Show Post Acceptance Test
  5. · Recording the Reply to Post Acceptance Test

print this article
SEARCH DEVARTICLES

Recording Acceptance Tests - Recording the Reply to Post Acceptance Test
(Page 5 of 5 )

The Reply to Post acceptance test is run after the Show Post test, and it is used to verify that replying to the post works. The Reply to Post user story is similar to the Post to Forum user story. Record it by following these steps:

  1. Select File -> New Test from the Selenium IDE menu. Verify that Selenium IDE is recording, by checking that the red record button is activated.
  2. We want to verify that we are on the page where the previous acceptance test left us. Right-click somewhere on the page and choose assertTitle 'The Dice Man' from the pop-up menu.   




    Note  If step 2 adds an open command to the acceptance test, remove it from the list. You need to get rid of it because it contains the unique id of the post, which won't be the same when you run the test again. 



  3. Click the Reply link. You should now see the reply to post page.
  4. Type a name (for example, George) in the Name field.
  5. Type a subject (for example, Lets play) in the Subject field.  
  6. Type a message (for example, Im starting today!) in the Body field.  
  7. Click the Reply button. You are taken to the forum main page.  
  8. Select the text ("Let's play by George" in our example), right-click it, and select verifyTextPresent Let's play by George from the pop-up menu.  
  9. Switch to the Source view by clicking the Source tab. Add the following to the end of the test: |assertLocation|/forum||.
  10. Save the test as test/selenium/forum/04_reply_to_post.sel (by selecting File -> Save Test from the menu). 
  11.  
     

The test should now contain the text shown here:

|assertTitle|'The Dice Man'|| |clickAndWait|link=Reply||
|type|post[name]|George|
|type|post[subject]|Let's play|
|type|post[body]|I'm starting today!| |clickAndWait|commit|| |verifyTextPresent|Let's play by George|| |assertLocation|/forum||

We have now created acceptance tests for all of the forum-related user stories. Let's show George the wonder of automation by executing the complete set of Selenium acceptance tests:

$ rake test:acceptance

Firefox starts up, and Selenium then executing our acceptance tests one by one. Figure 11-11 shows the result page, which appears after the tests have run. All tests should be green, which indicates that they passed.


Figure 11-11.  Running the recorded acceptance tests

Next, click the Walk radio button in the Execute Tests section of TestRunner window, and then click the All button beneath it to run the tests again. Selenium now runs the tests in a slow-motion mode that allows you to see each command being executed.

You can also try stepping through the tests, by clicking the Step radio button in the Execute Tests section and clicking the All button. Instead of executing the whole test, Selenium stops after each executed command. To continue the test, click the Continue button. This is useful when you're debugging a test.   

Summary

In this chapter, you learned how to write automated acceptance tests using Selenium and the Selenium on Rails plugin. By automating acceptance tests, you not only remove manual work, but you also raise your confidence that your application works according to the requirements. We also showed you how to simplify the process of writing acceptance tests by using the Selenium IDE Firefox extension to record the tests.

In the next chapter, well show you how to deploy your application to production. There shouldn't be any surprises, as we have implemented a full set of automated tests that exercise almost all parts of the application.   


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials