Login into the blog
Let us now create a test to login into the blog.
- Create a new scenario, call it Login, and paste the following contents into it.
Login:
- login as "username" with "password"
- verify that the "username" has logged in
- logout from the blog
- verify that the "username" has logged out
Notice that the scenario describes the intent and not the details of how to interact with the user interface. For example, you could have written the scenario as follows:
Login:
- type "username" in the username field
- type "password" in the password field
- click submit
- verify that the page contains a logout link
- click the logout link
- verify that the page does not contain a logout link
- The scenario is now very closely tied to the user interface.
- It is not easy to understand the purpose of the scenario, unless you are intimately familiar with the user interface yourself.
- Use Ctrl+1 to create underlying code for your workflow steps. Type in the necessary code to simulate typing in username, password and so on.
Your class will now look like the following:
public class Login { private TwistSelenium selenium; public Login(TwistSelenium selenium) { this.selenium = selenium; selenium.open("/blog"); } public void loginAsWith(String user, String pass) { selenium.type("j_username", user); selenium.type("j_password", pass); selenium.submit("loginForm"); } public void verifyThatTheHasLoggedIn(String user) { assertTrue(selenium.isTextPresent("Logged in as " + user)); assertTrue(selenium.isTextPresent("Logout")); } public void logoutFromTheBlog() { selenium.click("link=Logout"); } public void verifyThatTheHasLoggedOut(String user) { assertFalse(selenium.isTextPresent("Logged in as " + user)); assertFalse(selenium.isTextPresent("Logout")); } ... code omitted for clarity ... }
Proceed to Login into the blog after changing passwords.