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