View Javadoc

1   package org.itracker.selenium;
2   
3   import java.io.IOException;
4   import org.junit.Test;
5   
6   /**
7    * Verifies security issues - that user, leaving a system cannot
8    * access its content anymore.
9    * 
10   * @author Andrey Sergievskiy <seas@andreysergievskiy.com>
11   */
12  public class LogoutTest extends AbstractSeleniumTestCase {
13      /**
14       * Verifies the successfull login case with valid login/password.
15       * 
16       * 0. Exit all available http sessions.
17       * 1. Open some page inside the system.
18       * 2. Verify, that browser was forwarded to login page.
19       * 3. Enters correct login and password into appropriate input fields.
20       * 4. Clicks "Login" button.
21       * 5. Waits for page reload.
22       * 6. Verifies if page contains ticket id input field, which means we
23       * are inside an application.
24       * 7. Verify if page contains Logout link and click it.
25       * 8. After page refresh, verify that it's login page.
26       * 9. Again, try to access some page inside the system.
27       * 10. Verify, that browser has been forwarded to login page again.
28       * @throws java.io.IOException
29       */
30      @Test
31      public void testLoginAndLogout() throws IOException {
32          SeleniumManager.closeSession(selenium);
33          selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
34                  + applicationPath + "/portalhome.do");
35  
36          assertFalse(selenium.isElementPresent("id"));
37          assertTrue(selenium.isElementPresent("login"));
38          assertTrue(selenium.isElementPresent("password"));
39          assertTrue(selenium.isElementPresent("xpath=//.[@type='submit']"));
40          selenium.type("login", "user_test1");
41          selenium.type("password", "user_test1");
42          selenium.click("xpath=//.[@type='submit']");
43          selenium.waitForPageToLoad(SE_TIMEOUT);
44  
45          assertTrue(selenium.isElementPresent("id"));
46          assertTrue(selenium.isElementPresent("logoff"));
47          selenium.click("logoff");
48          selenium.waitForPageToLoad(SE_TIMEOUT);
49  
50          assertFalse(selenium.isElementPresent("id"));
51          assertTrue(selenium.isElementPresent("login"));
52          assertTrue(selenium.isElementPresent("password"));
53          selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
54                  + applicationPath + "/portalhome.do");
55  
56          assertFalse(selenium.isElementPresent("id"));
57          assertTrue(selenium.isElementPresent("login"));
58          assertTrue(selenium.isElementPresent("password"));
59      }
60      
61      @Override
62      protected String[] getDataSetFiles() {
63          return new String[]{
64                  "dataset/languagebean_init_dataset.xml",
65                  "dataset/languagebean_dataset.xml",
66                  "dataset/userpreferencesbean_dataset.xml",
67                  "dataset/userbean_dataset.xml"
68          };
69      }
70  
71      @Override
72      protected String[] getConfigLocations() {
73          return new String[]{ "application-context.xml"};
74      }
75  }