View Javadoc

1   package org.itracker.selenium;
2   
3   import java.io.IOException;
4   import org.junit.Test;
5   
6   /**
7    * Verifies authorization to the system functionality.
8    * 
9    * @author Andrey Sergievskiy <seas@andreysergievskiy.com>
10   */
11  public class LoginTest extends AbstractSeleniumTestCase {
12  
13      
14      /**
15       * Verifies the successfull login case with valid login/password.
16       * 
17       * 1. Opens login page of an application.
18       * 2. Enters correct login and password into appropriate input fields.
19       * 3. Clicks "Login" button.
20       * 4. Waits for page reload.
21       * 5. Verifies if page contains ticket id input field, which means we
22       * are inside an application.
23       * @throws java.io.IOException
24       */
25      @Test
26      public void testLoginSuccessDefaultAdmin() throws IOException {
27          closeSession();
28          selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
29                  + applicationPath);
30  
31          assertTrue(selenium.isElementPresent("xpath=//.[@name='login']"));
32          assertTrue(selenium.isElementPresent("xpath=//.[@name='password']"));
33          assertTrue(selenium.isElementPresent("xpath=//.[@value='Login']"));
34          selenium.type("xpath=//.[@name='login']", "admin_test1");
35          selenium.type("xpath=//.[@name='password']", "admin_test1");
36          selenium.click("xpath=//.[@value='Login']");
37          selenium.waitForPageToLoad(SE_TIMEOUT);
38          assertTrue(selenium.isElementPresent("xpath=//.[@name='id']"));
39      }
40      
41      /**
42       * Verifies login failure case with invalid login/password.
43       * 
44       * 1. Opens login page of an application.
45       * 2. Enters incorrect login and password into appropriate input fields.
46       * 3. Clicks "Login" button.
47       * 4. Waits for page reload.
48       * 5. Verifies if page contains ticket id input field, which means we
49       * are inside an application.
50       * @throws java.io.IOException
51       */
52      @Test
53      public void testLoginFailure() throws IOException {
54          closeSession();
55          selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
56                  + applicationPath);
57          assertTrue(selenium.isElementPresent("xpath=//.[@name='login']"));
58          assertTrue(selenium.isElementPresent("xpath=//.[@name='password']"));
59          assertTrue(selenium.isElementPresent("xpath=//.[@value='Login']"));
60          selenium.type("xpath=//.[@name='login']", "wrong_login");
61          selenium.type("xpath=//.[@name='password']", "wrong_password");
62          selenium.click("xpath=//.[@value='Login']");
63          selenium.waitForPageToLoad(SE_TIMEOUT);
64  
65          assertFalse(selenium.isElementPresent("xpath=//.[@name='id']"));
66      }
67      
68      @Override
69      protected String[] getDataSetFiles() {
70          return new String[]{
71                  "dataset/languagebean_init_dataset.xml",
72                  "dataset/languagebean_dataset.xml",
73                  "dataset/userpreferencesbean_dataset.xml",
74                  "dataset/userbean_dataset.xml"
75          };
76      }
77  
78      @Override
79      protected String[] getConfigLocations() {
80          return new String[]{ "application-context.xml"};
81      }
82  }