Skip to content

Commit

Permalink
Add functional tests xwikisas#16
Browse files Browse the repository at this point in the history
* Modified comments
* Modified execution condition
* Removed test for application panel as it is currently not working (will create a separate issue to address this)
* Code refactoring
  • Loading branch information
ChiuchiuSorin committed Dec 14, 2023
1 parent 214479e commit 38d87f8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-panels-test-pageobjects</artifactId>
<version>${platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/it</testSourceDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
package com.xwiki.admintools.test.ui;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
Expand All @@ -45,16 +43,11 @@ public class AdminToolsExecutionCondition implements ExecutionCondition
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context)
{
if (DockerTestUtils.isInAContainer()) {
List<ServletEngine> filteredServletEngines =
Stream.of(ServletEngine.values()).filter(engine -> !supportedServers.contains(engine))
.collect(Collectors.toList());
TestConfiguration configuration = DockerTestUtils.getTestConfiguration(context);
for (ServletEngine servletEngine : filteredServletEngines) {
if (servletEngine.equals(configuration.getServletEngine())) {
return ConditionEvaluationResult.disabled(String.format("Servlet engine [%s] is forbidden "
+ "when the PDF export tests are executed inside a Docker container, skipping.",
configuration.getServletEngine()));
}
if (!supportedServers.contains(configuration.getServletEngine())) {
return ConditionEvaluationResult.disabled(String.format("Servlet engine [%s] is forbidden "
+ "when the PDF export tests are executed inside a Docker container, skipping.",
configuration.getServletEngine()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.panels.test.po.ApplicationsPanel;
import org.xwiki.test.docker.junit5.TestConfiguration;
import org.xwiki.test.docker.junit5.UITest;
import org.xwiki.test.ui.TestUtils;
import org.xwiki.test.ui.po.ViewPage;

import com.xwiki.admintools.test.po.AdminToolsHomePage;
import com.xwiki.admintools.test.po.DashboardConfigurationSectionView;
Expand All @@ -61,25 +58,17 @@ class AdminToolsIT

private static final String PASSWORD = "pass";

private static boolean isSupportedServer = true;

private final List<String> supportedDatabases =
List.of("mysql", "hsql", "hsqldb", "mariadb", "postgresql", "oracle");

private final List<String> excludedLines =
List.of("environment.permanentDirectory", "rendering.linkLabelFormat", "core.defaultDocumentSyntax", "MISC");

@BeforeAll
static void setUp(TestUtils setup, TestConfiguration testConfiguration)
static void setUp(TestUtils setup)
{
setup.createUser(USER_NAME, PASSWORD, setup.getURLToNonExistentPage(), "first_name", "Jon", "last_name",
"Snow");
String serverType = testConfiguration.getServletEngine().name();
if (!supportedServers.contains(serverType)) {
isSupportedServer = false;
AdminToolsHomePage adminToolsHomePage = AdminToolsHomePage.gotoPage();
assertEquals(2, adminToolsHomePage.countWarningMessages());
}

// By default the minimal distribution used for the tests doesn't have any rights setup. Let's create an Admin
// user part of the Admin Group and make sure that this Admin Group has admin rights in the wiki. We could also
Expand All @@ -97,15 +86,6 @@ void goToPage()
AdminToolsHomePage.gotoPage();
}

@Test
void appEntryRedirectsToHomePage()
{
ApplicationsPanel applicationPanel = ApplicationsPanel.gotoPage();
ViewPage vp = applicationPanel.clickApplication("Admin Tools");
Assertions.assertTrue(
AdminToolsHomePage.isCurrentPage(vp));
}

@Test
@Order(1)
void adminToolsHomePageBackend(TestConfiguration testConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ public static AdminToolsHomePage gotoPage()
return new AdminToolsHomePage();
}

/**
* Check if the page is the same as Admin Tools WebHome.
*/
public static boolean isCurrentPage(ViewPage vp)
{
return vp.getMetaDataValue("page").equals(ADMIN_TOOLS_PAGE) && vp.getMetaDataValue("space")
.equals(ADMIN_TOOLS_SPACE);
}

/**
* Open the dashboard configuration section.
*/
Expand All @@ -68,13 +59,5 @@ public static DashboardFilesSectionView getFilesSection()
gotoPage();
return new DashboardFilesSectionView();
}

/**
* Count the warning messages on the homepage.
*/
public int countWarningMessages()
{
return getDriver().findElements(By.className("warningmessage")).size();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ public class DashboardConfigurationSectionView extends ViewPage
{
private static final String BACKEND_SECTION_VIEW_LAST_LOGS_MODAL_ID = "#configurationViewLastNLinesModal";

@FindBy(xpath = "//a[@data-target = '#configurationViewLastNLinesModal']")
@FindBy(css = "a[data-target='#configurationViewLastNLinesModal']")
public WebElement backendLogsHyperlink;

@FindBy(css = ".backend-section")
public WebElement backendContent;

@FindBy(css = ".warningmessage")
public List<WebElement> warningElements;

public String getText()
{
return backendContent.findElement(By.tagName("ul")).getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
package com.xwiki.admintools.test.po;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
Expand All @@ -40,19 +38,25 @@ public class DashboardFilesSectionView extends ViewPage
private WebElement downloadFilesModalHyperlink;

/**
* Open the download modal.
* Open the download files archive modal.
*/
public DownloadArchiveModalView clickDownloadModalHyperlink()
{
downloadFilesModalHyperlink.click();
return new DownloadArchiveModalView(By.id("downloadFilesModal"));
}

/**
* Navigate and click the link for viewing XWiki properties file.
*/
public void clickPropertiesHyperlink()
{
filesContent.findElement(By.id("filesProperties")).click();
}

/**
* Navigate and click the link for viewing XWiki configuration file.
*/
public void clickConfigurationHyperlink()
{
filesContent.findElement(By.id("filesConfig")).click();
Expand Down

0 comments on commit 38d87f8

Please sign in to comment.