Search in sources :

Example 16 with ViewPage

use of org.xwiki.test.ui.po.ViewPage in project xwiki-platform by xwiki.

the class CopyPageTest method testCopyOverwritePage.

@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void testCopyOverwritePage() throws Exception {
    String sourceSpaceName = getTestClassName();
    String sourcePageName = getTestMethodName();
    String targetSpaceName = getTestClassName() + "Copy";
    String targetPageName = getTestMethodName() + "Copy";
    // Delete page that may already exist
    getUtil().rest().deletePage(sourceSpaceName, sourcePageName);
    getUtil().rest().deletePage(targetSpaceName, targetPageName);
    // Create a new page that will be overwritten.
    getUtil().rest().savePage(new LocalDocumentReference(targetSpaceName, targetPageName), OVERWRITTEN_PAGE_CONTENT, targetPageName);
    // Create a new page that will be copied.
    ViewPage viewPage = getUtil().createPage(sourceSpaceName, sourcePageName, PAGE_CONTENT, sourcePageName);
    // Click on Copy from the Page top menu.
    viewPage.copy();
    CopyPage copyPage = new CopyPage();
    // Fill the target destination the page to be copied to.
    DocumentPicker documentPicker = copyPage.getDocumentPicker();
    documentPicker.setTitle(targetPageName);
    documentPicker.browseDocuments();
    DocumentPickerModal documentPickerModal = new DocumentPickerModal();
    documentPickerModal.waitForDocumentSelected(sourceSpaceName, "WebHome").selectDocument(targetSpaceName, "WebHome");
    documentPicker.waitForLocation(Arrays.asList("", targetSpaceName, targetPageName));
    Assert.assertEquals(targetSpaceName, copyPage.getTargetSpaceName());
    // Click copy button
    CopyOverwritePromptPage copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    // Check overwrite warning
    Assert.assertEquals(OVERWRITE_PROMPT1 + targetSpaceName + '.' + targetPageName + OVERWRITE_PROMPT2, copyOverwritePrompt.getWarningMessage());
    // Cancel the copy
    viewPage = copyOverwritePrompt.clickCancelButton();
    // Verify that we have been sent back to the original page
    Assert.assertEquals(sourcePageName, viewPage.getDocumentTitle());
    // Click on Copy from the Page top menu.
    viewPage.copy();
    copyPage = new CopyPage();
    // Fill the target destination the page to be copied to.
    copyPage.getDocumentPicker().toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
    // Click copy button
    copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    // Click change target
    copyOverwritePrompt.clickChangeTargetButton();
    copyPage = new CopyPage();
    // Check the source document
    Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), copyPage.getSourceLocation().getPath());
    Assert.assertEquals(sourceSpaceName, copyPage.getSourceSpaceName());
    Assert.assertEquals(sourcePageName, copyPage.getSourcePageName());
    // Check the default target document.
    documentPicker = copyPage.getDocumentPicker();
    Assert.assertEquals(sourcePageName, documentPicker.getTitle());
    Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), documentPicker.getLocation().getPath());
    Assert.assertEquals(sourceSpaceName, copyPage.getTargetSpaceName());
    Assert.assertEquals(sourcePageName, copyPage.getTargetPageName());
    // Fill the target destination the page to be copied to.
    documentPicker.setTitle("My copy").toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
    // Copy and confirm overwrite
    copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    CopyOrRenameStatusPage copyStatusPage = copyOverwritePrompt.clickCopyButton().waitUntilFinished();
    // Check successful copy confirmation
    Assert.assertEquals(COPY_SUCCESSFUL, copyStatusPage.getInfoMessage());
    viewPage = copyStatusPage.gotoNewPage();
    // Verify that the title of the copy has been updated (independent from the name of the copy).
    Assert.assertEquals("My copy", viewPage.getDocumentTitle());
    Assert.assertEquals(PAGE_CONTENT, viewPage.getContent());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) CopyOrRenameStatusPage(org.xwiki.test.ui.po.CopyOrRenameStatusPage) CopyPage(org.xwiki.index.test.po.CopyPage) DocumentPickerModal(org.xwiki.index.tree.test.po.DocumentPickerModal) CopyOverwritePromptPage(org.xwiki.test.ui.po.CopyOverwritePromptPage) ViewPage(org.xwiki.test.ui.po.ViewPage) DocumentPicker(org.xwiki.test.ui.po.DocumentPicker) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Example 17 with ViewPage

use of org.xwiki.test.ui.po.ViewPage in project xwiki-platform by xwiki.

the class EditClassTest method testAddProperty.

@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void testAddProperty() {
    // We verify that we can click on Edit Class from View Page (we need to test this at
    // least once to ensure the UI works).
    getUtil().gotoPage("Test", "EditObjectsTestClass", "view", "spaceRedirect=false");
    ClassEditPage cep = new ViewPage().editClass();
    // Create a class with a string property
    cep.addProperty("prop", "String");
    cep.clickSaveAndView();
    // Create object page
    ViewPage vp = getUtil().createPage("Test", "EditObjectsTestObject", "this is the content: {{velocity}}$doc.display('prop'){{/velocity}}", getTestMethodName());
    // Add an object of the class created
    ObjectEditPage oep = vp.editObjects();
    FormElement objectForm = oep.addObject("Test.EditObjectsTestClass");
    objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop"), "testing value");
    vp = oep.clickSaveAndView();
    Assert.assertEquals("this is the content: testing value", vp.getContent());
}
Also used : ClassEditPage(org.xwiki.test.ui.po.editor.ClassEditPage) ObjectEditPage(org.xwiki.test.ui.po.editor.ObjectEditPage) ViewPage(org.xwiki.test.ui.po.ViewPage) FormElement(org.xwiki.test.ui.po.FormElement) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Example 18 with ViewPage

use of org.xwiki.test.ui.po.ViewPage in project xwiki-platform by xwiki.

the class EditClassTest method testDeleteProperty.

@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void testDeleteProperty() {
    // Create a class with two string properties
    getUtil().addClassProperty("Test", "EditObjectsTestClass", "prop1", "String");
    getUtil().addClassProperty("Test", "EditObjectsTestClass", "prop2", "String");
    // Create object page
    ViewPage vp = getUtil().createPage("Test", "EditObjectsTestObject", "this is the content: {{velocity}}$doc.display('prop1')/$doc.display('prop2')/" + "$!doc.getObject('Test.EditObjectsTestClass').getProperty('prop1').value{{/velocity}}", getTestMethodName());
    // Add an object of the class created
    ObjectEditPage oep = vp.editObjects();
    FormElement objectForm = oep.addObject("Test.EditObjectsTestClass");
    objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop1"), "testing value 1");
    objectForm.setFieldValue(By.id("Test.EditObjectsTestClass_0_prop2"), "testing value 2");
    vp = oep.clickSaveAndView();
    Assert.assertEquals("this is the content: testing value 1/testing value 2/testing value 1", vp.getContent());
    // Delete the first property from the class
    ClassEditPage cep = getUtil().editClass("Test", "EditObjectsTestClass");
    cep.deleteProperty("prop1");
    cep.clickSaveAndView();
    vp = getUtil().gotoPage("Test", "EditObjectsTestObject");
    Assert.assertEquals("this is the content: /testing value 2/testing value 1", vp.getContent());
    oep = vp.editObjects();
    Assert.assertNotNull(getDriver().findElement(By.className("deprecatedProperties")));
    Assert.assertNotNull(getDriver().findElement(By.cssSelector(".deprecatedProperties label")));
    Assert.assertEquals("prop1:", getDriver().findElement(By.cssSelector(".deprecatedProperties label")).getText());
    // Remove deprecated properties
    oep.removeAllDeprecatedProperties();
    vp = oep.clickSaveAndView();
    Assert.assertEquals("this is the content: /testing value 2/", vp.getContent());
}
Also used : ClassEditPage(org.xwiki.test.ui.po.editor.ClassEditPage) ObjectEditPage(org.xwiki.test.ui.po.editor.ObjectEditPage) ViewPage(org.xwiki.test.ui.po.ViewPage) FormElement(org.xwiki.test.ui.po.FormElement) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Example 19 with ViewPage

use of org.xwiki.test.ui.po.ViewPage in project xwiki-platform by xwiki.

the class ClassSheetTest method createClass.

/**
 * Tests the process of creating a class, its template, its sheet and an instance.
 */
@Test
public void createClass() {
    // TODO: rewrite the test to not rely on the breadcrumb based on parent/child mechanism.
    getUtil().setHierarchyMode("parentchild");
    try {
        String spaceName = getTestClassName();
        String className = RandomStringUtils.randomAlphabetic(5);
        String classDocName = className + "Class";
        String classTitle = className + " Class";
        String pageName = getTestMethodName();
        // Make sure the document doesn't exist.
        getUtil().deletePage(spaceName, pageName);
        // Create the class document.
        DataTypesPage dataTypesPage = DataTypesPage.gotoPage().waitUntilPageIsLoaded();
        String dataTypesPageTitle = dataTypesPage.getDocumentTitle();
        Assert.assertTrue(dataTypesPage.isClassListed("XWiki", "XWikiRights"));
        Assert.assertFalse(dataTypesPage.isClassListed(spaceName, classDocName));
        ClassSheetPage classSheetPage = dataTypesPage.createClass(spaceName, className).waitUntilPageIsLoaded();
        Assert.assertEquals(classTitle, classSheetPage.getDocumentTitle());
        Assert.assertTrue(classSheetPage.hasBreadcrumbContent(dataTypesPageTitle, false));
        // Add a property.
        ClassEditPage classEditor = classSheetPage.clickDefineClassLink();
        classEditor.addProperty("color", "String").setPrettyName("Your favorite color");
        classEditor.clickSaveAndView();
        // Add a new property.
        classEditor = classSheetPage.waitUntilPageIsLoaded().clickEditClassLink();
        classEditor.addProperty("age", "Number").setPrettyName("Your current age");
        classEditor.clickSaveAndView();
        // We have to wait for the page to load because Selenium doesn't do it all the time when we click on Save & View
        // (even if the Save & View button triggers a plain form submit; there must be something with the JavaScript
        // code that is executed on submit that interferes with Selenium).
        classSheetPage.waitUntilPageIsLoaded();
        // Assert that the properties are listed.
        Assert.assertTrue(classSheetPage.hasProperty("color", "Your favorite color", "String"));
        Assert.assertTrue(classSheetPage.hasProperty("age", "Your current age", "Number"));
        // Create and bind a sheet.
        classSheetPage = classSheetPage.clickCreateSheetButton().waitUntilPageIsLoaded().clickBindSheetLink().waitUntilPageIsLoaded();
        ViewPage sheetPage = classSheetPage.clickSheetLink();
        Assert.assertEquals(className + " Sheet", sheetPage.getDocumentTitle());
        sheetPage.clickBreadcrumbLink(classTitle);
        classSheetPage.waitUntilPageIsLoaded();
        // Create the template.
        classSheetPage = classSheetPage.clickCreateTemplateButton().waitUntilPageIsLoaded().clickAddObjectToTemplateLink().waitUntilPageIsLoaded();
        ViewPage templatePage = classSheetPage.clickTemplateLink();
        Assert.assertEquals(className + " Template", templatePage.getDocumentTitle());
        // The default edit button should take us to the In-line edit mode.
        templatePage.edit();
        InlinePage editPage = new InlinePage();
        editPage.setValue("color", "red");
        editPage.setValue("age", "13");
        editPage.clickSaveAndContinue();
        editPage.clickBreadcrumbLink(classTitle);
        classSheetPage.waitUntilPageIsLoaded();
        // Create a document based on the class template.
        Assert.assertEquals(spaceName, classSheetPage.getNewPagePicker().getParentInput().getAttribute("value"));
        editPage = classSheetPage.createNewDocument(spaceName, pageName);
        Assert.assertEquals(pageName, editPage.getDocumentTitle());
        Assert.assertEquals("red", editPage.getValue("color"));
        Assert.assertEquals("13", editPage.getValue("age"));
        editPage.setValue("color", "blue");
        editPage.setValue("age", "27");
        ViewPage viewPage = editPage.clickSaveAndView();
        Assert.assertEquals(pageName, viewPage.getDocumentTitle());
        Assert.assertEquals("Your favorite color\nblue\nYour current age\n27", viewPage.getContent());
        viewPage.clickBreadcrumbLink(classTitle);
        classSheetPage.waitUntilPageIsLoaded();
        // Assert the created document is listed.
        Assert.assertTrue(classSheetPage.hasDocument(pageName));
    } finally {
        getUtil().setHierarchyMode("reference");
    }
}
Also used : ClassEditPage(org.xwiki.test.ui.po.editor.ClassEditPage) InlinePage(org.xwiki.test.ui.po.InlinePage) ClassSheetPage(org.xwiki.xclass.test.po.ClassSheetPage) ViewPage(org.xwiki.test.ui.po.ViewPage) DataTypesPage(org.xwiki.xclass.test.po.DataTypesPage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Example 20 with ViewPage

use of org.xwiki.test.ui.po.ViewPage in project xwiki-platform by xwiki.

the class CreatePageIT method createPagesFromTemplate.

/**
 * Tests if a new page can be created from a template.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void createPagesFromTemplate() throws Exception {
    // Step 0: Setup the correct environment for the test
    // All these pages are created during this test
    getUtil().deleteSpace(getTestClassName());
    getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
    EntityReference templateInstanceReference = getUtil().resolveDocumentReference(getTestClassName() + "." + TEMPLATE_NAME + "Instance" + ".WebHome");
    getUtil().rest().delete(templateInstanceReference);
    getUtil().rest().deletePage(getTestClassName(), "NewPage");
    getUtil().rest().deletePage(getTestClassName(), TEMPLATE_NAME + "UnexistingInstance");
    getUtil().rest().deletePage(getTestClassName(), "EmptyPage");
    String templateContent = "Test Template Content";
    String templateTitle = "Test Template Title";
    String templateProviderName = TEMPLATE_NAME + "Provider";
    String templateProviderFullName = getTestClassName() + "." + templateProviderName;
    // Step 1: Create a Template and a Template Provider and try to create a new page by using the Add Menu and
    // using the created Template
    ViewPage templateProviderView = createTemplateAndTemplateProvider(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";
    createPagePage.getDocumentPicker().toggleLocationAdvancedEdit();
    EditPage templateInstanceEditWysiwyg = createPagePage.createPageFromTemplate(templateInstanceName, getTestClassName(), null, templateProviderFullName);
    WikiEditPage templateInstanceEdit = templateInstanceEditWysiwyg.clickSaveAndView().editWiki();
    // Verify template instance location and content
    assertEquals(templateInstanceName, templateInstanceEdit.getTitle());
    assertEquals(getTestClassName() + "." + templateInstanceName, templateInstanceEdit.getMetaDataValue("space"));
    assertEquals("WebHome", templateInstanceEdit.getMetaDataValue("page"));
    assertEquals(templateContent, templateInstanceEdit.getContent());
    // check the parent of the template instance
    assertEquals(templateProviderFullName, templateInstanceEdit.getParent());
    // Step 2: Create a wanted link and verify that clicking it displays the Template and that we can use it.
    // Put a wanted link in the template instance
    templateInstanceEdit.setContent("[[doc:NewPage]]");
    ViewPage vp = templateInstanceEdit.clickSaveAndView();
    // Verify that clicking on the wanted link pops up a box to choose the template.
    EntityReference wantedLinkReference = getUtil().resolveDocumentReference(getTestClassName() + "." + TEMPLATE_NAME + "Instance" + ".NewPage");
    vp.clickWantedLink(wantedLinkReference, true);
    // TODO: a page object should be better here
    List<WebElement> templates = getDriver().findElements(By.xpath("//input[@name='type' and @data-type='template']"));
    // Note: We need to remove 1 to exclude the "Empty Page" template entry
    assertEquals(availableTemplateSize, templates.size());
    assertTrue(createPagePage.getAvailableTemplates().contains(templateProviderFullName));
    // Step 3: Create a new page when located on a non-existing page
    getUtil().gotoPage(getTestClassName(), TEMPLATE_NAME + "UnexistingInstance", "view", "spaceRedirect=false");
    vp = new ViewPage();
    assertFalse(vp.exists());
    DocumentDoesNotExistPage unexistingPage = new DocumentDoesNotExistPage();
    unexistingPage.clickEditThisPageToCreate();
    CreatePagePage createUnexistingPage = new CreatePagePage();
    // Make sure we're in create mode.
    assertTrue(getUtil().isInCreateMode());
    // count the available templates, make sure they're as many as before and that our template is among them
    assertEquals(availableTemplateSize, createUnexistingPage.getAvailableTemplateSize());
    assertTrue(createUnexistingPage.getAvailableTemplates().contains(templateProviderFullName));
    // select it
    createUnexistingPage.setTemplate(templateProviderFullName);
    createUnexistingPage.setTerminalPage(true);
    // and create
    createUnexistingPage.clickCreate();
    EditPage ep = new EditPage();
    WikiEditPage unexistingPageEdit = ep.clickSaveAndView().editWiki();
    // Verify template instance location and content
    assertEquals(getTestClassName(), templateInstanceEdit.getMetaDataValue("space"));
    assertEquals(TEMPLATE_NAME + "UnexistingInstance", templateInstanceEdit.getMetaDataValue("page"));
    assertEquals(TEMPLATE_NAME + "UnexistingInstance", unexistingPageEdit.getTitle());
    assertEquals(templateContent, unexistingPageEdit.getContent());
    // test that this page has no parent
    assertEquals("Main.WebHome", unexistingPageEdit.getParent());
    // Step 4: Create an empty new page when there are Templates available
    // Make sure we are on a page that exists so that Add > Page will show the space and page fields
    CreatePagePage createEmptyPage = unexistingPageEdit.clickCancel().createPage();
    assertTrue(createEmptyPage.getAvailableTemplateSize() > 0);
    createEmptyPage.getDocumentPicker().toggleLocationAdvancedEdit();
    EditPage editEmptyPage = createEmptyPage.createPage(getTestClassName(), "EmptyPage");
    ViewPage emptyPage = editEmptyPage.clickSaveAndView();
    // make sure it's empty
    assertEquals("", emptyPage.getContent());
    // make sure parent is the right one
    assertEquals("/" + getTestClassName() + "/EmptyPage", emptyPage.getBreadcrumbContent());
    // mare sure title is the right one
    assertEquals("EmptyPage", emptyPage.getDocumentTitle());
    // Step 5: Verify that restricting a Template to a space works
    // 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.setVisibilityRestrictions(allowedSpaces);
    templateProviderInline.setCreationRestrictions(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.
    assertTrue(getUtil().isInCreateMode());
    assertEquals(availableTemplateSize, createPagePage.getAvailableTemplateSize());
    assertTrue(createPagePage.getAvailableTemplates().contains(templateProviderFullName));
    // Modify the target space and verify the form can't be submitted
    createPagePage.setTemplate(templateProviderFullName);
    createPagePage.getDocumentPicker().toggleLocationAdvancedEdit();
    createPagePage.getDocumentPicker().setParent("Foo");
    createPagePage.getDocumentPicker().setName("Bar");
    String currentURL = getDriver().getCurrentUrl();
    createPagePage.clickCreate();
    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.
    CreatePagePage.gotoPage();
    // make sure that the template provider is not in the list of templates
    assertFalse(createPagePage.getAvailableTemplates().contains(templateProviderFullName));
}
Also used : CreatePagePage(org.xwiki.test.ui.po.CreatePagePage) ArrayList(java.util.ArrayList) ViewPage(org.xwiki.test.ui.po.ViewPage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) EditPage(org.xwiki.test.ui.po.editor.EditPage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) WebElement(org.openqa.selenium.WebElement) DocumentDoesNotExistPage(org.xwiki.test.ui.po.DocumentDoesNotExistPage) EntityReference(org.xwiki.model.reference.EntityReference) TemplateProviderInlinePage(org.xwiki.administration.test.po.TemplateProviderInlinePage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest)

Aggregations

ViewPage (org.xwiki.test.ui.po.ViewPage)93 Test (org.junit.Test)75 AbstractTest (org.xwiki.test.ui.AbstractTest)41 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)26 WikiEditPage (org.xwiki.test.ui.po.editor.WikiEditPage)18 ObjectEditPage (org.xwiki.test.ui.po.editor.ObjectEditPage)11 IgnoreBrowser (org.xwiki.test.ui.browser.IgnoreBrowser)10 DocumentReference (org.xwiki.model.reference.DocumentReference)8 CreatePagePage (org.xwiki.test.ui.po.CreatePagePage)8 FormElement (org.xwiki.test.ui.po.FormElement)7 HistoryPane (org.xwiki.test.ui.po.HistoryPane)7 ClassEditPage (org.xwiki.test.ui.po.editor.ClassEditPage)7 WebElement (org.openqa.selenium.WebElement)6 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)6 AttachmentsPane (org.xwiki.test.ui.po.AttachmentsPane)6 URL (java.net.URL)5 ApplicationClassEditPage (org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage)5 ClassFieldEditPane (org.xwiki.appwithinminutes.test.po.ClassFieldEditPane)5 ExtensionId (org.xwiki.extension.ExtensionId)5 ExtensionAdministrationPage (org.xwiki.extension.test.po.ExtensionAdministrationPage)5