@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(); } }
@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()); }
@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()); }