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).
Recording Acceptance Tests - Recording the Post to Forum Acceptance Test (Page 3 of 5 )
In the acceptance test for the Post to Forum user story, which describes how a post is created, we want to verify that posting to the forum works and that the post is shown on the forum main page.
Record the acceptance test by following these steps:
Select File -> New Test from the Selenium IDE menu. Verify that Selenium IDE is recording, by checking that the red record button is activated.
Open http://localhost:3000/forum in your browser. Line 1 should now contain an open command. You should also see the posts that were created by the previous test case.
Click the New post link at the top of the page. You should see a clickAndWait command inserted at line 2.
On the new post page, type a name (for example, Luke Rhinehart) in the Name field.
In the Subject field, type a post subject (for example, The Dice Man).
In the Body field, type a message (for example, Roll the die!).
Click the Post button. You should be redirected to the main page of the forum, where you should see the post.
Select the text ("The Dice Man by Luke Rhinehart" in our example).
Right-click the selected text and select verifyTextPresent The Dice Man by Luke Rhinehart from the pop-up menu.
Save the recorded test as test/selenium/forum/02_post_to_forum.sel (by selecting File -> Save Test from the Selenium IDE menu).
Run the test by clicking the run button in Selenium IDE. You should see the test succeed (all rows are green), as shown in Figure 11-9.
Figure 11-9. The Post to Forum acceptance test in Selenium IDE
If you open 02_post_to_forum.sel in an editor, you should see something like the following:
|open|/forum|| |clickAndWait|link=New post|| |type|post[name]|Luke Rhinehart| |type|post[subject]|The Dice Man| |type|post[body]|Roll the die!| |clickAndWait|commit|| |verifyTextPresent|The Dice Man by Luke Rhinehart||
Now test that the View Forum and Post to Forum acceptance tests work when both are run in succession by executing the following: