/** http://jira.xwiki.org/browse/XWIKI-7913 */ @Test public void testJavascriptExtension() { // Create a doc WikiEditPage wep = WikiEditPage.gotoPage("Test", "SkinxTest"); wep.setContent("this is the content"); ViewPage vp = wep.clickSaveAndView(); // Add an XWikiGroups object ObjectEditPage oep = vp.editObjects(); FormElement objectForm = oep.addObject("XWiki.JavaScriptExtension"); objectForm.setFieldValue(By.id("XWiki.JavaScriptExtension_0_code"), SCRIPT); objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("always"); vp = oep.clickSaveAndView(); Assert.assertTrue(isScriptActive(vp)); vp = HomePage.gotoPage(); Assert.assertTrue(isScriptActive(vp)); oep = ObjectEditPage.gotoPage("Test", "SkinxTest"); objectForm = oep.getObjectsOfClass("XWiki.JavaScriptExtension").get(0); objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("currentPage"); vp = oep.clickSaveAndView(); Assert.assertTrue(isScriptActive(vp)); vp = HomePage.gotoPage(); Assert.assertFalse(isScriptActive(vp)); oep = ObjectEditPage.gotoPage("Test", "SkinxTest"); objectForm = oep.getObjectsOfClass("XWiki.JavaScriptExtension").get(0); objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("onDemand"); vp = oep.clickSaveAndView(); Assert.assertFalse(isScriptActive(vp)); }
@Test public void testWatchThisPageAndWholeSpace() throws Exception { // Clear the list of watched documents and spaces getUtil() .updateObject( "XWiki", this.profilePage.getUsername(), "XWiki.WatchListClass", 0, "spaces", "", "documents", ""); // Watch Test.TestWatchThisPage ViewPage page = getUtil().createPage("Test", "TestWatchThisPage", "TestWatchThisPage ui", null); page.watchDocument(); // Watch TestWatchWholeSpace.Test1 page = getUtil().createPage("TestWatchWholeSpace", "Test1", "TestWatchWholeSpace ui", null); page.watchSpace(); // Verify that the watched page & space are present in the watchlist manager this.watchlistPage = WatchlistUserProfilePage.gotoPage(this.watchlistPage.getUsername()); // TODO: use LiveTableElement instead but does not seems to work... // LiveTableElement watchlist = this.watchlistPage.getWatchList(); // watchlist.waitUntilReady(); this.watchlistPage.waitUntilElementIsVisible( By.xpath( "//tbody[@id='mywatchlist-display']/tr/td/a[@href='/xwiki/bin/view/Test/TestWatchThisPage']")); Assert.assertTrue(this.watchlistPage.isWatched("Test", "TestWatchThisPage")); Assert.assertTrue(this.watchlistPage.isWatched("TestWatchWholeSpace")); // Ensure that the watchlist notified is set to Daily since we're going to trigger that notifier // scheduler job WatchlistPreferencesEditPage watchlistPreferences = this.watchlistPage.editPreferences(); watchlistPreferences.setNotifierDaily(); watchlistPreferences.clickSaveAndContinue(); // Switch to Admin user and go to the scheduler home page SchedulerHomePage schedulerHomePage = new SchedulerHomePage(); getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(schedulerHomePage.getURL())); getUtil().recacheSecretToken(); // Trigger the notification for the Daily job schedulerHomePage.clickJobActionTrigger("WatchList daily notifier"); // Wait for the email with a timeout Assert.assertTrue("Mail not received", this.greenMail.waitForIncomingEmail(70000, 1)); // Verify email content String messageFromXWiki = GreenMailUtil.getBody(this.greenMail.getReceivedMessages()[0]); Assert.assertFalse(messageFromXWiki.contains("Exception")); Assert.assertTrue(messageFromXWiki.contains("TestWatchThisPage")); Assert.assertTrue(messageFromXWiki.contains("TestWatchWholeSpace")); }
/** * Tests the creation of a page from a save and edit template, tests that the page is indeed * saved. */ @Test @IgnoreBrowsers({ @IgnoreBrowser( value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser( value = "internet.*", version = "9\\.*", reason = "See http://jira.xwiki.org/browse/XE-1177") }) public void testCreatePageWithSaveAndEditTemplate() { String space = this.getClass().getSimpleName(); String newPageName = "NewPage"; getUtil().deletePage(space, newPageName); // create a template String templateProviderName = TEMPLATE_NAME + "Provider"; String templateContent = "Templates are fun"; String templateTitle = "Funny templates"; String templateProviderFullName = space + "." + templateProviderName; ViewPage templatePage = createTemplate(templateProviderName, templateContent, templateTitle, true); // create the page CreatePagePage createPage = templatePage.createPage(); WYSIWYGEditPage editCreatedPage = createPage.createPageFromTemplate(space, newPageName, templateProviderFullName, true); // ensure that we're indeed in edit mode Assert.assertTrue(getUtil().isInWYSIWYGEditMode()); // wait for editor to load (so that content is loaded) editCreatedPage.waitUntilPageIsLoaded(); // and now cancel it ViewPage newPage = editCreatedPage.clickCancel(); // make sure we're not in unexisting page Assert.assertTrue(newPage.exists()); // we should be in view mode (useless check since the impl of isNonExisting page calls it // anyway) Assert.assertTrue(getUtil().isInViewMode()); // make sure it's the page we want Assert.assertEquals(space, newPage.getMetaDataValue("space")); Assert.assertEquals(newPageName, newPage.getMetaDataValue("page")); // and now test the title is the name of the page and the content is the one from the template Assert.assertEquals(newPageName, newPage.getDocumentTitle()); Assert.assertEquals(templateContent, newPage.getContent()); // and the parent, it should be the template provider, since that's where we created it from Assert.assertTrue(newPage.hasBreadcrumbContent(templateProviderName, false)); }
/** See XWIKI-8781 */ @Test @IgnoreBrowsers({ @IgnoreBrowser( value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser( value = "internet.*", version = "9\\.*", reason = "See http://jira.xwiki.org/browse/XE-1177") }) public void testDeleteLatestVersion() throws Exception { getUtil().deletePage(SPACE_NAME, PAGE_NAME); // Create first version of the page ViewPage vp = getUtil().createPage(SPACE_NAME, PAGE_NAME, CONTENT1, TITLE); // Adds second version WikiEditPage wikiEditPage = vp.editWiki(); wikiEditPage.setContent(CONTENT2); wikiEditPage.clickSaveAndView(); // TODO: Remove when XWIKI-6688 (Possible race condition when clicking on a tab at the bottom of // a page in // view mode) is fixed. vp.waitForDocExtraPaneActive("comments"); // Verify and delete the latest version. HistoryPane historyTab = vp.openHistoryDocExtraPane(); Assert.assertEquals("2.1", historyTab.getCurrentVersion()); historyTab = historyTab.deleteVersion("2.1"); // Verify that the current version is now the previous one. Assert.assertEquals("1.1", historyTab.getCurrentVersion()); Assert.assertEquals("Administrator", historyTab.getCurrentAuthor()); }
@Test @IgnoreBrowsers({ @IgnoreBrowser( value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser( value = "internet.*", version = "9\\.*", reason = "See http://jira.xwiki.org/browse/XE-1177") }) public void testRollbackToFirstVersion() throws Exception { getUtil().deletePage(SPACE_NAME, PAGE_NAME); // Create first version of the page ViewPage vp = getUtil().createPage(SPACE_NAME, PAGE_NAME, CONTENT1, TITLE); // Adds second version WikiEditPage wikiEditPage = vp.editWiki(); wikiEditPage.setContent(CONTENT2); wikiEditPage.clickSaveAndView(); // TODO: Remove when XWIKI-6688 (Possible race condition when clicking on a tab at the bottom of // a page in // view mode) is fixed. vp.waitForDocExtraPaneActive("comments"); // Verify that we can rollback to the first version HistoryPane historyTab = vp.openHistoryDocExtraPane(); vp = historyTab.rollbackToVersion("1.1"); // Rollback doesn't wait... // Wait for the comment tab to be selected since we're currently on the history tab and rolling // back is going to load a new page and make the focus active on the comments tab. vp.waitForDocExtraPaneActive("comments"); Assert.assertEquals("First version of Content", vp.getContent()); historyTab = vp.openHistoryDocExtraPane(); Assert.assertEquals("Rollback to version 1.1", historyTab.getCurrentVersionComment()); Assert.assertEquals("Administrator", historyTab.getCurrentAuthor()); }
@Test @IgnoreBrowser( value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146") public void testKeyboardShortcuts() { ViewPage vp = util.gotoPage("Sandbox", "WebHome"); // Test default edit mode (WYSIWYG for sandbox webhome) key vp.sendKeys("e"); vp.waitUntilPageIsLoaded(); Assert.assertTrue(util.isInWYSIWYGEditMode()); // Test Cancel key vp.sendKeys(Keys.ALT, "c"); vp.waitUntilPageIsLoaded(); Assert.assertTrue(util.isInViewMode()); // Test Wiki edit key vp.sendKeys("k"); vp.waitUntilPageIsLoaded(); Assert.assertTrue(util.isInWikiEditMode()); // Test WYSIWYG edit mode key vp = this.util.gotoPage("Sandbox", "WebHome"); vp.sendKeys("e"); vp.waitUntilPageIsLoaded(); Assert.assertTrue(util.isInWYSIWYGEditMode()); // Test Inline edit mode key vp = this.util.gotoPage("Sandbox", "WebHome"); vp.sendKeys("f"); vp.waitUntilPageIsLoaded(); Assert.assertTrue(util.isInInlineEditMode()); // Test Rights edit mode key vp = this.util.gotoPage("Sandbox", "WebHome"); vp.sendKeys("r"); vp.waitUntilPageIsLoaded(); Assert.assertTrue(util.isInRightsEditMode()); // Test Object edit mode key vp = this.util.gotoPage("Sandbox", "WebHome"); vp.sendKeys("o"); vp.waitUntilPageIsLoaded(); Assert.assertTrue(util.isInObjectEditMode()); // Test Class edit mode key vp = this.util.gotoPage("Sandbox", "WebHome"); vp.sendKeys("s"); vp.waitUntilPageIsLoaded(); Assert.assertTrue(util.isInClassEditMode()); // Test Delete key vp = this.util.gotoPage("Sandbox", "WebHome"); vp.sendKeys(Keys.DELETE); Assert.assertTrue(util.isInDeleteMode()); // Test Rename key vp = this.util.gotoPage("Sandbox", "WebHome"); vp.sendKeys(Keys.F2); Assert.assertTrue(util.isInRenameMode()); }
private static boolean isScriptActive(ViewPage vp) { return "script active".equals(vp.getPageTitle()); }
/** Tests if a new page can be created from a template. */ @Test @IgnoreBrowsers({ @IgnoreBrowser( value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser( value = "internet.*", version = "9\\.*", reason = "See http://jira.xwiki.org/browse/XE-1177") }) public void testCreatePageFromTemplate() { // Setup the correct environment for the test getUtil().deletePage(getTestClassName(), getTestMethodName()); // all these pages are created during this test getUtil().deletePage(getTestClassName(), TEMPLATE_NAME + "Instance"); getUtil().deletePage(getTestClassName(), "NewPage"); getUtil().deletePage(getTestClassName(), TEMPLATE_NAME + "UnexistingInstance"); getUtil().deletePage(getTestClassName(), "EmptyPage"); String templateContent = "My Template Content"; String templateTitle = "My Template Title"; String templateProviderName = TEMPLATE_NAME + "Provider"; String templateProviderFullName = getTestClassName() + "." + templateProviderName; ViewPage templateProviderView = createTemplate(templateProviderName, templateContent, templateTitle, false); // Create the new document from template CreatePagePage createPagePage = templateProviderView.createPage(); // Save the number of available templates so that we can make some checks later on. int availableTemplateSize = createPagePage.getAvailableTemplateSize(); String templateInstanceName = TEMPLATE_NAME + "Instance"; WYSIWYGEditPage templateInstanceEditWysiwyg = createPagePage.createPageFromTemplate( getTestClassName(), templateInstanceName, templateProviderFullName, true); templateInstanceEditWysiwyg.waitUntilPageIsLoaded(); WikiEditPage templateInstanceEdit = templateInstanceEditWysiwyg.clickSaveAndView().editWiki(); // Verify template instance content Assert.assertEquals(templateInstanceName, templateInstanceEdit.getTitle()); Assert.assertEquals(templateContent, templateInstanceEdit.getContent()); // check the parent of the template instance Assert.assertEquals(templateProviderFullName, templateInstanceEdit.getParent()); // Put a wanted link in the template instance templateInstanceEdit.setContent("[[NewPage]]"); ViewPage vp = templateInstanceEdit.clickSaveAndView(); // Verify that clicking on the wanted link pops up a box to choose the template. vp.clickWantedLink(getTestClassName(), "NewPage", true); List<WebElement> templates = getDriver().findElements(By.name("templateprovider")); // Note: We need to remove 1 to exclude the "Empty Page" template entry Assert.assertEquals(availableTemplateSize, templates.size() - 1); Assert.assertTrue(createPagePage.getAvailableTemplates().contains(templateProviderFullName)); // Create a new page from template by going to a non-existing page // And make sure we're on a non-existing page getUtil() .gotoPage( getTestClassName(), TEMPLATE_NAME + "UnexistingInstance", "view", "spaceRedirect=false"); vp = new ViewPage(); Assert.assertFalse(vp.exists()); DocumentDoesNotExistPage unexistingPage = new DocumentDoesNotExistPage(); unexistingPage.clickEditThisPageToCreate(); CreatePagePage createUnexistingPage = new CreatePagePage(); // Make sure we're in create mode. Assert.assertTrue(getUtil().isInCreateMode()); // count the available templates, make sure they're as many as before and that our template is // among them templates = getDriver().findElements(By.name("templateprovider")); // Note: We need to remove 1 to exclude the "Empty Page" template entry Assert.assertEquals(availableTemplateSize, templates.size() - 1); Assert.assertTrue(createPagePage.getAvailableTemplates().contains(templateProviderFullName)); // select it createUnexistingPage.setTemplate(templateProviderFullName); // and create createUnexistingPage.clickCreate(); WYSIWYGEditPage unexistingPageEditWysiwyg = new WYSIWYGEditPage(); unexistingPageEditWysiwyg.waitUntilPageIsLoaded(); WikiEditPage unexistingPageEdit = unexistingPageEditWysiwyg.clickSaveAndView().editWiki(); // Verify template instance content Assert.assertEquals(TEMPLATE_NAME + "UnexistingInstance", unexistingPageEdit.getTitle()); Assert.assertEquals(templateContent, unexistingPageEdit.getContent()); // test that this page has no parent Assert.assertEquals("Main.WebHome", unexistingPageEdit.getParent()); // create an empty page when there is a template available, make sure it's empty CreatePagePage createEmptyPage = CreatePagePage.gotoPage(); Assert.assertTrue(createEmptyPage.getAvailableTemplateSize() > 0); WYSIWYGEditPage editEmptyPage = createEmptyPage.createPage(getTestClassName(), "EmptyPage"); Assert.assertTrue(getUtil().isInWYSIWYGEditMode()); // wait to load editor to make sure that what we're saving is the content that is supposed to be // in this // document editEmptyPage.waitUntilPageIsLoaded(); ViewPage emptyPage = editEmptyPage.clickSaveAndView(); // make sure it's empty Assert.assertEquals("", emptyPage.getContent()); // make sure parent is the right one Assert.assertTrue(emptyPage.hasBreadcrumbContent("Wiki Home", false)); // mare sure title is the right one Assert.assertEquals("EmptyPage", emptyPage.getDocumentTitle()); // Restrict the template to its own space templateProviderView = getUtil().gotoPage(getTestClassName(), TEMPLATE_NAME + "Provider"); templateProviderView.editInline(); TemplateProviderInlinePage templateProviderInline = new TemplateProviderInlinePage(); List<String> allowedSpaces = new ArrayList<String>(); allowedSpaces.add(getTestClassName()); templateProviderInline.setSpaces(allowedSpaces); templateProviderView = templateProviderInline.clickSaveAndView(); // Verify we can still create a page from template in the test space createPagePage = templateProviderView.createPage(); // Make sure we get in create mode. Assert.assertTrue(getUtil().isInCreateMode()); Assert.assertEquals(availableTemplateSize, createPagePage.getAvailableTemplateSize()); Assert.assertTrue(createPagePage.getAvailableTemplates().contains(templateProviderFullName)); // Modify the target space and verify the form can't be submitted createPagePage.setTemplate(templateProviderFullName); createPagePage.setSpace("Foobar"); String currentURL = getDriver().getCurrentUrl(); createPagePage.clickCreate(); Assert.assertEquals(currentURL, getDriver().getCurrentUrl()); // and check that an error is displayed to the user createPagePage.waitForFieldErrorMessage(); // Verify the template we have removed is no longer available. createEmptyPage = CreatePagePage.gotoPage(); // make sure that the template provider is not in the list of templates Assert.assertFalse(createPagePage.getAvailableTemplates().contains(templateProviderFullName)); }
/** * Tests what happens when creating a page when no template is available in the specific space. */ @Test @IgnoreBrowsers({ @IgnoreBrowser( value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser( value = "internet.*", version = "9\\.*", reason = "See http://jira.xwiki.org/browse/XE-1177") }) public void testCreatePageWhenNoTemplateAvailable() { // prepare the test environment, create a test space and exclude all templates for this space String space = this.getClass().getSimpleName(); // create the home page of this space to make sure the space exists getUtil() .createPage( space, "WebHome", "You can have fun with templates here", "Welcome to the templates test space"); // we'll create all these pages during this test getUtil().deletePage(space, "NewUnexistingPage"); getUtil().deletePage(space, "NewPage"); getUtil().deletePage(space, "NewLinkedPage"); // go through all the templates and make sure they are disabled on this space TemplatesAdministrationSectionPage sectionPage = TemplatesAdministrationSectionPage.gotoPage(); // get the links to existing templates, navigate to each of them and disable the current space List<String> spacesToExclude = Collections.singletonList(space); List<WebElement> existingTemplatesLinks = sectionPage.getExistingTemplatesLinks(); for (int i = 0; i < existingTemplatesLinks.size(); i++) { WebElement link = existingTemplatesLinks.get(i); link.click(); ViewPage templateViewPage = new ViewPage(); templateViewPage.editInline(); TemplateProviderInlinePage providerEditPage = new TemplateProviderInlinePage(); // FIXME: Temporary until we remove the template provider type altogether and make all // providers page // template providers. if (!providerEditPage.isPageTemplate()) { providerEditPage.setPageTemplate(true); } providerEditPage.excludeSpaces(spacesToExclude); providerEditPage.clickSaveAndView(); // go back to the admin page, to leave this in a valid state sectionPage = TemplatesAdministrationSectionPage.gotoPage(); existingTemplatesLinks = sectionPage.getExistingTemplatesLinks(); } // TODO: should reset these template settings at the end of the test, to leave things in the // same state as they // were at the beginning of the test // and now start testing! // 1/ create a page from the link in the page displayed when navigating to a non-existing page getUtil().gotoPage(space, "NewUnexistingPage", "view", "spaceRedirect=false"); ViewPage newUnexistentPage = new ViewPage(); Assert.assertFalse(newUnexistentPage.exists()); DocumentDoesNotExistPage nonExistingPage = new DocumentDoesNotExistPage(); nonExistingPage.clickEditThisPageToCreate(); // make sure we're not in create mode anymore Assert.assertFalse(getUtil().isInCreateMode()); // make sure we're directly in edit mode Assert.assertTrue(getUtil().isInWYSIWYGEditMode()); // TODO: check that we're indeed in the edit mode of space.NewUnexitingPage WYSIWYGEditPage editNewUnexistingPage = new WYSIWYGEditPage(); Assert.assertEquals(space, editNewUnexistingPage.getMetaDataValue("space")); Assert.assertEquals("NewUnexistingPage", editNewUnexistingPage.getMetaDataValue("page")); // 2/ create a page from the create menu on an existing page, by filling in space and name ViewPage spaceHomePage = getUtil().gotoPage(space, "WebHome"); CreatePagePage createNewPage = spaceHomePage.createPage(); // we expect no templates available Assert.assertEquals(0, createNewPage.getAvailableTemplateSize()); // fill in data and create the page createNewPage.setSpace(space); createNewPage.setPage("NewPage"); createNewPage.setTerminalPage(true); createNewPage.clickCreate(); // we expect to go to the edit mode of the new page Assert.assertFalse(getUtil().isInCreateMode()); Assert.assertTrue(getUtil().isInWYSIWYGEditMode()); WYSIWYGEditPage editNewPage = new WYSIWYGEditPage(); editNewPage.waitUntilPageIsLoaded(); Assert.assertEquals(space, editNewPage.getMetaDataValue("space")); Assert.assertEquals("NewPage", editNewPage.getMetaDataValue("page")); // 3/ create a page from a link in another page WikiEditPage editNewPageWiki = editNewPage.clickSaveAndView().editWiki(); // put a link to the new page to create editNewPageWiki.setContent("[[NewLinkedPage]]"); ViewPage newPage = editNewPageWiki.clickSaveAndView(); // no templates are available, so we don't expect a panel with a list of templates, we just // expect it goes // directly to edit mode of the new page // it would be nice to be able to test here that the create page panel is not displayed, ever. // However, we can't // since we need to wait for that time, and we don't know how much is never. newPage.clickWantedLink(space, "NewLinkedPage", false); WYSIWYGEditPage editNewLinkedPage = new WYSIWYGEditPage(); // since the edit mode loads as a result of a redirect that comes from a async call made by the // click, we need // to wait for the page to load getDriver() .waitUntilElementIsVisible( By.xpath( "//div[@id='mainEditArea']//div[@class='gwt-Label' and contains(text(), 'WYSIWYG')]")); // make sure we're in edit mode (of the new page) Assert.assertTrue(getUtil().isInWYSIWYGEditMode()); Assert.assertEquals(space, editNewLinkedPage.getMetaDataValue("space")); Assert.assertEquals("NewLinkedPage", editNewLinkedPage.getMetaDataValue("page")); }