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