Writing the first test
To quickly write some tests that you can use as a foundation for your automated
tests, you can use Selenium IDE to get started. Selenium IDE is a plug-in for
Firefox that lets you record tests. You can then export the recorded tests
so that you can add fanciness to them—conditions, iterations, and so on.
To get started with Selenium IDE, download it from the link in Resources. Install it as a Firefox plug-in by
clicking the link. Firefox should prompt you to install the plug-in, and then you must
restart the browser for the changes to take effect.
After you have the plug-in installed, start your server so you can begin using your web
application. Open Selenium IDE by clicking Tools > Selenium IDE
in Firefox. When Selenium IDE is open, click Record. After Selenium
IDE is recording, it will remember all of the actions that you take in the browser. To
log in to your sample application, perform the following steps:
With Selenium IDE recording, navigate to the index.jsp web page.Type your user name.Type the valid password in the Password box.Click Login.
Upon successful login, your web application should go to the enterInfo.jsp page. At
this point, your test has the actions in it, but so far, there is nothing to verify
that your actions worked. Selenium needs to know what to look for in order to
know that your enterInfo.jsp page is being rendered as expected.
You can add verify actions to make sure your application is displaying the correct
content. While Selenium is still recording, perform the following steps:
Right-click one of the HTML elements, such as the
Your name label, and then click
verifyTextPresent Your name:.Repeat step 1 with the Your birth date label.Click Record to stop recording.
If you want to see your test in action, click Run All (see
Figure 1). The test will execute and pass.
Figure 1. Clicking Run All
|