Skip to content

Commit

Permalink
feat(e2e): Introducing E2E tests to the CICD pipeline for both maven …
Browse files Browse the repository at this point in the history
…modules: `dotcms-e2e-java` and `dotcms-e2e-node` (#30071)

Pipeline will run in a parallel way both maven E2E modules and adding
test results to the test phase life cycle.
For the moment E2E tests will run in regular PR-check as well.

Refs: #29846
  • Loading branch information
victoralfaro-dotcms authored Sep 25, 2024
1 parent b28591f commit 15a0421
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cli: &cli
- *full_build_test
- *backend

sdk_libs: &sdk_libs
sdk_libs:
- 'core-web/libs/sdk/**'

jvm_unit_test:
Expand All @@ -44,4 +44,4 @@ jvm_unit_test:
build:
- *backend
- *cli
- *frontend
- *frontend
2 changes: 2 additions & 0 deletions .github/workflows/cicd_1-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ jobs:
postman: ${{ needs.initialize.outputs.backend == 'true' }}
frontend: ${{ needs.initialize.outputs.frontend == 'true' }}
cli: ${{ needs.initialize.outputs.cli == 'true' }}
# TODO: remove this param after testing E2E tests invocation
e2e: true
secrets:
DOTCMS_LICENSE: ${{ secrets.DOTCMS_LICENSE }}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cicd_3-trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
with:
run-all-tests: ${{ inputs.run-all-tests || false }}
artifact-run-id: ${{ needs.initialize.outputs.artifact-run-id }}
e2e: true
secrets:
DOTCMS_LICENSE: ${{ secrets.DOTCMS_LICENSE }}
permissions:
Expand Down
39 changes: 37 additions & 2 deletions .github/workflows/cicd_comp_test-phase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ on:
required: false
type: boolean
default: false
e2e:
required: false
type: boolean
default: false
secrets:
DOTCMS_LICENSE:
required: true
Expand Down Expand Up @@ -154,7 +158,7 @@ jobs:
# Postman Tests
linux-postman-tests:
name: Run Postman Tests - ${{matrix.collection_group}}
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
if: inputs.postman || inputs.run-all-tests
strategy:
fail-fast: false
Expand All @@ -175,4 +179,35 @@ jobs:
needs-docker-image: true
github-token: ${{ secrets.GITHUB_TOKEN }}
artifacts-from: ${{ env.ARTIFACT_RUN_ID }}
cleanup-runner: true
cleanup-runner: true

# E2E Tests
linux-e2e-tests:
name: E2E Tests ${{matrix.suites.name}}
runs-on: ubuntu-24.04
if: inputs.e2e || inputs.run-all-tests
timeout-minutes: 240
env:
MAVEN_OPTS: -Xmx2048m
strategy:
fail-fast: false
matrix:
suites:
- { name: "JVM E2E Suite", pathName: "jvme2etestsuite", maven_args: '-Dit.test=E2eTestSuite -Dci=true -pl :dotcms-e2e-java' }
- { name: "Node.js E2E Suite", pathName: "nodee2etestsuite", maven_args: '-De2e.test.env=ci -pl :dotcms-e2e-node' }
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/core-cicd/maven-job
with:
stage-name: "E2E ${{ matrix.suites.name }}"
maven-args: "verify -Pcoverage -De2e.test.skip=false ${{ matrix.suites.maven_args}}"
generates-test-results: true
dotcms-license: ${{ secrets.DOTCMS_LICENSE }}
requires-node: true
needs-docker-image: true
github-token: ${{ secrets.GITHUB_TOKEN }}
artifacts-from: ${{ env.ARTIFACT_RUN_ID }}
cleanup-runner: true
1 change: 0 additions & 1 deletion dotcms-postman/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ async function main() {
if (summaryResults.failures > 0) {
console.error('Some collections failed.');
process.exit(0);
//process.exit(1);
}
} catch (error) {
console.error('An error occurred:', error);
Expand Down
41 changes: 30 additions & 11 deletions e2e/dotcms-e2e-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<skip>${e2e.test.skip}</skip>
</configuration>
<executions>
<execution>
<id>install-playwright</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./mvnw</executable>
<arguments>
<argument>exec:java</argument>
<argument>-e</argument>
<argument>-Dexec.mainClass=com.microsoft.playwright.CLI</argument>
<argument>-Dexec.args="install-deps"</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand All @@ -165,7 +190,11 @@
</configuration>
<executions>
<execution>
<id>default</id>
<id>integration-test</id>
<phase>none</phase> <!-- This disables automatic test execution in the integration-test phase -->
</execution>
<execution>
<id>verify</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
Expand Down Expand Up @@ -247,16 +276,6 @@
</goals>
<phase>verify</phase>
</execution>
<!--<execution>
<id>docker-stop</id>
<goals>
<goal>stop</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<skip>${e2e.test.skip}</skip>
</configuration>
</execution>-->
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
*/
@Suite
@SelectClasses({
LoginTests.class,
LoginTests.class/*,
ContentPagesTests.class,
ContentSearchTests.class,
SiteLayoutContainersTests.class
SiteLayoutContainersTests.class*/
})
public class E2eTestSuite {
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,25 @@
* <li>{@link #close(AutoCloseable...)} - Closes the provided resources.</li>
* <li>{@link #createContextAndPage(Browser)} - Creates a new browser context and page.</li>
* <li>{@link #resolveBrowser(Playwright, String)} - Resolves the browser type from a string.</li>
* <li>{@link #visibleTimeout(double)} - Creates visibility timeout options for assertions.</li>
* <li>{@link #assertVisibleTimeout(double)} - Creates visibility timeout options for assertions.</li>
* </ul>
*
* @author vico
*/
public class PlaywrightSupport {

private static final double DEFAULT_TIMEOUT = 10000;

private static final PlaywrightSupport INSTANCE = new PlaywrightSupport();

public static PlaywrightSupport get() {
return INSTANCE;
}

private final boolean ci;

private PlaywrightSupport() {
ci = Boolean.parseBoolean(EnvironmentService.get().getProperty(E2eKeys.CI_KEY));
}

/**
Expand All @@ -70,7 +75,7 @@ public Playwright playwright() {
* @return true if the current environment is a CI environment, false otherwise
*/
public boolean isCi() {
return Boolean.parseBoolean(EnvironmentService.get().getProperty(E2eKeys.CI_KEY));
return ci;
}

/**
Expand Down Expand Up @@ -153,8 +158,17 @@ public com.microsoft.playwright.BrowserType resolveBrowser(final Playwright play
* @param timeout the timeout value in milliseconds
* @return the visibility timeout options
*/
public LocatorAssertions.IsVisibleOptions visibleTimeout(final double timeout) {
public LocatorAssertions.IsVisibleOptions assertVisibleTimeout(final double timeout) {
return new LocatorAssertions.IsVisibleOptions().setTimeout(timeout);
}

/**
* Creates visibility timeout options for assertions.
*
* @return the visibility timeout options
*/
public LocatorAssertions.IsVisibleOptions assertVisibleTimeout() {
return assertVisibleTimeout(DEFAULT_TIMEOUT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ private EnvironmentService() {
* @return the property value or the default value if not found
*/
public String getProperty(final String key, final String defaultValue) {
final String propValue = props.getProperty(key);
String propValue = props.getProperty(key);
if (StringUtils.isNotBlank(propValue)) {
return propValue;
}

propValue = System.getProperty(key);
if (StringUtils.isNotBlank(propValue)) {
return propValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.dotcms.e2e.page.MenuNavigation;
import com.dotcms.e2e.page.PagesPage;
import com.dotcms.e2e.page.ToolEntries;
import com.dotcms.e2e.playwright.PlaywrightSupport;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;
Expand Down Expand Up @@ -65,7 +66,8 @@ public void test_addPage() throws Exception {
pagesPage.fillPagesForm(pagesDetailFrame, "Testing Page", "Default Template");
// validations
assertThat(page.locator("li")
.filter(new Locator.FilterOptions().setHasText("Testing Page"))).isVisible();
.filter(new Locator.FilterOptions().setHasText("Testing Page")))
.isVisible(PlaywrightSupport.get().assertVisibleTimeout());
}


Expand Down Expand Up @@ -104,7 +106,7 @@ public void test_removePage() throws Exception {
new Page.GetByRoleOptions().setName("Status"))).isVisible();
//execute the delete action
pagesPage.executePagesWorkflow("Testing Page", "Delete");
assertThat(page.getByText("Workflow executed")).isVisible();
assertThat(page.getByText("Workflow executed")).isVisible(PlaywrightSupport.get().assertVisibleTimeout());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void test_loginWrongUser() {
@Test
public void test_loginWrongPass() {
loginPage.login("[email protected]", "winteriscoming");
assertThat(page.getByTestId("message")).isVisible(PlaywrightSupport.get().visibleTimeout(10000));
assertThat(page.getByTestId("message")).isVisible(PlaywrightSupport.get().assertVisibleTimeout());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private StringToolbox() {
* @return the converted snake_case string
*/
public static String camelToSnake(String str) {
return str.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase();
return str.replaceAll("([a-z])([A-Z]+)", "$1_$2").toUpperCase();
}

}
9 changes: 8 additions & 1 deletion e2e/dotcms-e2e-node/frontend/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dotenv from 'dotenv';
import * as path from "node:path";
import { defineConfig, devices } from '@playwright/test';


const resolveEnvs = () => {
const envFiles = ['.env'];

Expand All @@ -19,7 +20,12 @@ const resolveEnvs = () => {
});
};

const prepareForTesting = () => {

};

resolveEnvs();
prepareForTesting();

/**
* See https://playwright.dev/docs/test-configuration.
Expand All @@ -35,12 +41,13 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: [['junit', { outputFile: '../target/failsafe-reports/failsafe-summary.xml' }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: process.env.BASE_URL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
headless: process.env.CI === 'true',
},
/* Configure projects for major browsers */
projects: [
Expand Down
Loading

0 comments on commit 15a0421

Please sign in to comment.