Search in sources :

Example 31 with ViewPage

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

the class MailTest method testMail.

@Test
public void testMail() throws Exception {
    // Step 0: Delete all pre-existing mails to start clean. This also verifies the deleteAll() script service
    // API.
    String content = "{{velocity}}$services.mailstorage.deleteAll(){{/velocity}}";
    ViewPage deleteAllPage = getUtil().createPage(getTestClassName(), "DeleteAll", content, "");
    // Verify that the page doesn't display any content (unless there's an error!)
    assertEquals("", deleteAllPage.getContent());
    // Step 1: Verify that there are 2 email sections in the Mail category
    AdministrationPage wikiAdministrationPage = AdministrationPage.gotoPage();
    Assert.assertTrue(wikiAdministrationPage.hasSection("Mail", "Mail Sending"));
    Assert.assertTrue(wikiAdministrationPage.hasSection("Mail", "Mail Sending Status"));
    Assert.assertTrue(wikiAdministrationPage.hasSection("Mail", "Advanced"));
    // Verify we can click on Mail > Advanced
    wikiAdministrationPage.clickSection("Mail", "Advanced");
    // Step 2: Before validating that we can send email, let's verify that we can report errors when the mail
    // setup is not correct
    // Make sure there's an invalid mail server set.
    wikiAdministrationPage.clickSection("Mail", "Mail Sending");
    SendMailAdministrationSectionPage sendMailPage = new SendMailAdministrationSectionPage();
    sendMailPage.setHost("invalidmailserver");
    sendMailPage.clickSave();
    // Send the mail that's supposed to fail and validate that it fails
    sendMailWithInvalidMailSetup();
    // Step 3: Navigate to each mail section and set the mail sending parameters (SMTP host/port)
    wikiAdministrationPage = AdministrationPage.gotoPage();
    wikiAdministrationPage.clickSection("Mail", "Mail Sending");
    sendMailPage = new SendMailAdministrationSectionPage();
    sendMailPage.setHost("localhost");
    sendMailPage.setPort("3025");
    // Make sure we don't wait between email sending in order to speed up the test (and not incur timeouts when
    // we wait to receive the mails)
    sendMailPage.setSendWaitTime("0");
    // Keep all mail statuses including successful ones (so that we verify this works fine)
    sendMailPage.setDiscardSuccessStatuses(false);
    sendMailPage.clickSave();
    // Step 3: Verify that there are no admin email sections when administering a space
    // Select XWiki space administration.
    AdministrationPage spaceAdministrationPage = AdministrationPage.gotoSpaceAdministrationPage("XWiki");
    // 2018-01-31: Got a failure on CI showing that the first assert below this line was failing because the
    // current page was still the one before move to the XWiki space admin. Thus taking extra step to ensure we
    // wait. However I don't understand why this happens since getDriver().url() called by
    // gotoSpaceAdministrationPage() should wait for the page to be loaded before returning.
    getDriver().waitUntilCondition(driver -> spaceAdministrationPage.getMetaDataValue("reference").equals("xwiki:XWiki.WebPreferences"));
    // All those sections should not be present
    Assert.assertTrue(spaceAdministrationPage.hasNotSection("Mail", "Mail Sending"));
    Assert.assertTrue(spaceAdministrationPage.hasNotSection("Mail", "Mail Sending Status"));
    Assert.assertTrue(spaceAdministrationPage.hasNotSection("Mail", "Advanced"));
    // Step 4: Prepare a Template Mail
    getUtil().deletePage(getTestClassName(), "MailTemplate");
    // Create a Wiki page containing a Mail Template (ie a XWiki.Mail object)
    getUtil().createPage(getTestClassName(), "MailTemplate", "", "");
    // Note: We use the following bindings in the Template subject and content so that we ensure that they are
    // provided by default:
    // - "$xwiki"
    // - "$xcontext"
    // - "$escapetool"
    // - "$services"
    // - "$request"
    // Note: We also use the $name and $doc bindings to show that the user can add new bindings ($doc is not bound
    // by default since there isn't always a notion of current doc in all places where mail sending is done).
    // Note: We use $xwiki.getURL() in the content to verify that we generate full external URLs.
    String velocityContent = "Hello $name from $escapetool.xml($services.model.resolveDocument(" + "$xcontext.getUser()).getName()) - Served from $request.getRequestURL().toString() - " + "url: $xwiki.getURL('Main.WebHome')";
    getUtil().addObject(getTestClassName(), "MailTemplate", "XWiki.Mail", "subject", "#if ($xwiki.exists($doc.documentReference))Status for $name on $doc.fullName#{else}wrong#end", "language", "en", "html", "<strong>" + velocityContent + "</strong>", "text", velocityContent);
    // We also add an attachment to the Mail Template page to verify that it is sent in the mail
    ByteArrayInputStream bais = new ByteArrayInputStream("Content of attachment".getBytes());
    getUtil().attachFile(getTestClassName(), "MailTemplate", "something.txt", bais, true, new UsernamePasswordCredentials("superadmin", "pass"));
    // Step 5: Send a template email (with an attachment) to a single email address
    sendTemplateMailToEmail();
    // Step 6: Send a template email to all the users in the XWikiAllGroup Group (we'll create 2 users) + to
    // two other users (however since they're part of the group they'll receive only one mail each, we thus test
    // deduplicatio!).
    sendTemplateMailToUsersAndGroup();
    // Step 7: Navigate to the Mail Sending Status Admin page and assert that the Livetable displays the entry for
    // the sent mails
    wikiAdministrationPage = AdministrationPage.gotoPage();
    wikiAdministrationPage.clickSection("Mail", "Mail Sending Status");
    MailStatusAdministrationSectionPage statusPage = new MailStatusAdministrationSectionPage();
    LiveTableElement liveTableElement = statusPage.getLiveTable();
    liveTableElement.filterColumn("xwiki-livetable-sendmailstatus-filter-3", "Test");
    liveTableElement.filterColumn("xwiki-livetable-sendmailstatus-filter-5", "send_success");
    liveTableElement.filterColumn("xwiki-livetable-sendmailstatus-filter-6", "xwiki");
    // Let's wait till we have at least 3 rows. Note that we wait because we could have received the mails above
    // but the last mail's status in the database may not have been updated yet. Note that The first 2 are
    // guaranteed to have been updated since we send mail in one thread one after another and we update the
    // database after sending each mail.
    liveTableElement.waitUntilRowCountGreaterThan(3);
    liveTableElement.filterColumn("xwiki-livetable-sendmailstatus-filter-4", "john@doe.com");
    assertTrue(liveTableElement.getRowCount() > 0);
    assertTrue(liveTableElement.hasRow("Error", ""));
}
Also used : AdministrationPage(org.xwiki.administration.test.po.AdministrationPage) LiveTableElement(org.xwiki.test.ui.po.LiveTableElement) SendMailAdministrationSectionPage(org.xwiki.mail.test.po.SendMailAdministrationSectionPage) ByteArrayInputStream(java.io.ByteArrayInputStream) ViewPage(org.xwiki.test.ui.po.ViewPage) MailStatusAdministrationSectionPage(org.xwiki.mail.test.po.MailStatusAdministrationSectionPage) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 32 with ViewPage

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

the class ReleaseTest method testRelease.

@Test
public void testRelease() {
    // Create a user and log in with it so that we test the application with a standard user
    // Note that using the superadmin user would also fail since the uservatar macro doesn't work with it.
    getUtil().createUserAndLogin(getTestClassName() + "User", "password");
    // Delete pages that we create in the test (we have to be logged in).
    getUtil().deletePage("Release", RELEASE_PAGE_NAME);
    // Navigate to the Release app by clicking in the Application Panel.
    // This verifies that the Release application is registered in the Applications Panel.
    // It also verifies that the Translation is registered properly.
    ApplicationsPanel applicationPanel = ApplicationsPanel.gotoPage();
    ViewPage vp = applicationPanel.clickApplication("Release");
    // Verify we're on the right page!
    Assert.assertEquals(ReleaseHomePage.getSpace(), vp.getMetaDataValue("space"));
    Assert.assertEquals(ReleaseHomePage.getPage(), vp.getMetaDataValue("page"));
    ReleaseHomePage homePage = new ReleaseHomePage();
    // Add new Release
    ReleaseEntryEditPage entryPage = homePage.addRelease(RELEASE_VERSION);
    vp = entryPage.waitUntilPageIsLoaded().clickSaveAndView();
    // Go back to the home page by clicking in the breadcrumb
    vp.clickBreadcrumbLink("Releases");
    homePage.waitUntilPageIsLoaded();
    // Assert Livetable:
    // - verify that the Translation has been applied by checking the Translated livetable column name
    // - verify that the Livetable contains our new Release entry
    LiveTableElement lt = homePage.getReleaseLiveTable();
    Assert.assertTrue(lt.hasRow("Version", RELEASE_VERSION));
}
Also used : LiveTableElement(org.xwiki.test.ui.po.LiveTableElement) ApplicationsPanel(org.xwiki.panels.test.po.ApplicationsPanel) ReleaseEntryEditPage(org.xwiki.release.test.po.ReleaseEntryEditPage) ViewPage(org.xwiki.test.ui.po.ViewPage) ReleaseHomePage(org.xwiki.release.test.po.ReleaseHomePage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Example 33 with ViewPage

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

the class TestUtils method createPageWithAttachment.

/**
 * @since 7.2M2
 */
public ViewPage createPageWithAttachment(List<String> spaces, String page, String content, String title, String syntaxId, String parentFullPageName, String attachmentName, InputStream attachmentData, UsernamePasswordCredentials credentials) throws Exception {
    ViewPage vp = createPage(spaces, page, content, title, syntaxId, parentFullPageName);
    attachFile(spaces, page, attachmentName, attachmentData, false, credentials);
    return vp;
}
Also used : ViewPage(org.xwiki.test.ui.po.ViewPage)

Example 34 with ViewPage

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

the class TestUtils method createPageWithAttachment.

/**
 * @since 5.1M2
 */
public ViewPage createPageWithAttachment(String space, String page, String content, String title, String attachmentName, InputStream attachmentData, UsernamePasswordCredentials credentials) throws Exception {
    ViewPage vp = createPage(space, page, content, title);
    attachFile(space, page, attachmentName, attachmentData, false, credentials);
    return vp;
}
Also used : ViewPage(org.xwiki.test.ui.po.ViewPage)

Example 35 with ViewPage

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

the class WebJarsTest method testWebJars.

@Test
public void testWebJars() throws Exception {
    // Delete pages that we create in the test
    getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
    // Create a page in which:
    // - we install a webjar in the main wiki
    // - we use the WebJars Script Service to generate a URL for a resource inside that webjar
    // - we create a link to that resource
    // Then we click that link and verify we get the resource content.
    // 
    // This test validates both the ability to generate webjars URL, the serving of webjars through the webjars URL
    // and the ability to access a webjars installed in a specific wiki.
    String content = "{{velocity}}\n" + "#set ($job = $services.extension.install('org.webjars:AjaxQ', '0.0.2', 'wiki:mywiki'))\n" + "#set ($discard = $job.join())\n" + "installed: $services.extension.installed.getInstalledExtension('org.webjars:AjaxQ', 'wiki:mywiki').id\n" + "[[AjaxQ>>path:$services.webjars.url('org.webjars:AjaxQ', 'ajaxq.js', {'wiki' : 'mywiki'})]]\n" + "{{/velocity}}";
    ViewPage vp = getUtil().createPage(getTestClassName(), getTestMethodName(), content, "WebJars Test");
    assertTrue(vp.getContent().contains("installed: org.webjars:AjaxQ/0.0.2"));
    // Click the link!
    // Note: For understanding why there's a r=1 query string, see WebJarsScriptService#getResourceReference()
    WebElement link = getDriver().findElementWithoutWaiting(By.xpath("//a[@href = '/xwiki/webjars/wiki%3Amywiki/AjaxQ/0.0.2/ajaxq.js?r=1']"));
    link.click();
    // Verify that the served resource is the one from the webjars
    assertTrue(getDriver().getPageSource().contains("// AjaxQ jQuery Plugin"));
}
Also used : ViewPage(org.xwiki.test.ui.po.ViewPage) WebElement(org.openqa.selenium.WebElement) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

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