Ejemplo n.º 1
0
  @Test
  public void testRedirectBackAfterLogin() {
    try {
      LoginPage loginPage = this.homePage.login();
      loginPage.loginAsAdmin();

      AdministrationPage admin = new AdministrationPage();
      admin.gotoPage();
      GlobalRightsAdministrationSectionPage sectionPage = admin.clickGlobalRightsSection();
      sectionPage.forceAuthenticatedView();

      getUtil().gotoPage("Blog", "Categories");
      loginPage.logout();
      getDriver().manage().deleteAllCookies();
      loginPage.loginAsAdmin();
      // We use startsWith since the URL contains a jsessionid and a srid.
      Assert.assertTrue(
          getDriver().getCurrentUrl().startsWith(getUtil().getURL("Blog", "Categories")));
    } finally {
      AdministrationPage admin = new AdministrationPage();
      admin.gotoPage();
      if (!admin.isAuthenticated()) {
        admin.login().loginAsAdmin();
        admin.gotoPage();
      }
      GlobalRightsAdministrationSectionPage sectionPage = admin.clickGlobalRightsSection();
      sectionPage.unforceAuthenticatedView();
    }
  }
Ejemplo n.º 2
0
 @Test
 public void testRedirectPreservesPOSTParameters() throws InterruptedException {
   String test = "Test string " + System.currentTimeMillis();
   final String space = "Main";
   final String page = "POSTTest";
   LoginPage loginPage = this.homePage.login();
   loginPage.loginAsAdmin();
   // start editing a page
   WikiEditPage editPage = new WikiEditPage();
   editPage.switchToEdit(space, page);
   editPage.setTitle(test);
   editPage.setContent(test);
   // emulate expired session: delete the cookies
   getDriver().manage().deleteAllCookies();
   // try to save
   editPage.clickSaveAndView();
   // we should have been redirected to login
   Assert.assertTrue(
       getDriver().getCurrentUrl().startsWith(getUtil().getURL("XWiki", "XWikiLogin", "login")));
   loginPage.loginAsAdmin();
   // we should have been redirected back to view, and the page should have been saved
   Assert.assertTrue(getDriver().getCurrentUrl().startsWith(getUtil().getURL(space, page)));
   editPage.switchToEdit(space, page);
   Assert.assertEquals(test, editPage.getTitle());
   Assert.assertEquals(test, editPage.getContent());
 }
Ejemplo n.º 3
0
  @Test
  public void testLoginLogout() {
    LoginPage loginPage = this.homePage.login();
    loginPage.loginAsAdmin();

    // Verify that after logging in we're redirected to the page on which the login button was
    // clicked, i.e. the
    // home page here.
    Assert.assertTrue(this.homePage.isOnHomePage());

    Assert.assertTrue(this.homePage.isAuthenticated());
    Assert.assertEquals("Administrator", this.homePage.getCurrentUser());

    // Test Logout and verify we stay on the home page
    this.homePage.logout();
    Assert.assertFalse(this.homePage.isAuthenticated());
    Assert.assertTrue(this.homePage.isOnHomePage());
  }
Ejemplo n.º 4
0
 @Test
 public void testLoginWithInvalidUsername() {
   LoginPage loginPage = this.homePage.login();
   loginPage.loginAs("non existent user", "admin");
   Assert.assertTrue(loginPage.hasInvalidCredentialsErrorMessage());
 }
Ejemplo n.º 5
0
 @Test
 public void testLoginWithInvalidCredentials() {
   LoginPage loginPage = this.homePage.login();
   loginPage.loginAs("Admin", "wrong password");
   Assert.assertTrue(loginPage.hasInvalidCredentialsErrorMessage());
 }