Skip to content

Commit

Permalink
CQ-4353443: Add cypress ui tests (#1111)
Browse files Browse the repository at this point in the history
* two ui test frameworks

* parametrize ui framework

* remove e2e form tests if flag not set

* console error cypress test

* remove cypress files in selenium module

* update READMEs

* update READMEs

* change ui.tests to be opt-in again

* add WDIO back to archetype IT tests

---------

Co-authored-by: Alejandro Ramirez <ramirezc@adobe.com>
Co-authored-by: Andrei Dulvac <andrei.dulvac@gmail.com>
  • Loading branch information
3 people committed Aug 21, 2023
1 parent ed65877 commit dd01179
Show file tree
Hide file tree
Showing 405 changed files with 2,608 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Name | Default | Description
`enableSSR` | `n` | Option to enable SSR for the front-end project
`precompiledScripts` | `n` | Option to [precompile](https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/archetype/precompiled-bundled-scripts.html) the server-side scripts from `ui.apps` and attach them to the build as a secondary bundle artifact in the `ui.apps` project. `aemVersion` should be set to `cloud`.
`includeFormsheadless` | `n` | Includes [Forms Core Components](https://github.com/adobe/aem-core-forms-components) dependencies, ui.frontend.react.forms.af and headless artifacts.
`uiTestingFramework` | `cypress` | Testing framework used for generating UI tests (can be `cypress` or `wdio`).
## System Requirements

Archetype | AEM as a Cloud Service | AEM 6.5 | Java SE | Maven
Expand Down
4 changes: 2 additions & 2 deletions src/main/archetype/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ reports/

# Others
dispatcher/src/conf.d/variables/default.vars
ui.tests/test-module/assets/form/themes/**/*diff.png
ui.tests/test-module/assets/form/themes/**/*current.png
ui.tests.wdio/test-module/assets/form/themes/**/*diff.png
ui.tests.wdio/test-module/assets/form/themes/**/*current.png
15 changes: 4 additions & 11 deletions src/main/archetype/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ The main parts of the template are:
* ui.content: contains sample content using the components from the ui.apps
* ui.config: contains runmode specific OSGi configs for the project
* ui.frontend: an optional dedicated front-end build mechanism (Angular, React or general Webpack project)
* ui.tests: Selenium based UI tests
* ui.tests.cypress: Cypress based UI tests
* ui.tests.wdio: Selenium based UI tests
* all: a single content package that embeds all of the compiled modules (bundles and content packages) including any vendor dependencies
* analyse: this module runs analysis on the project which provides additional validation for deploying into AEMaaCS

Expand Down Expand Up @@ -95,17 +96,9 @@ can be found here https://github.com/adobe/aemanalyser-maven-plugin

### UI tests

They will test the UI layer of your AEM application using Selenium technology.
They will test the UI layer of your AEM application using either Cypress or Selenium technology.

To run them locally:

mvn clean verify -Pui-tests-local-execution

This default command requires:
* an AEM author instance available at http://localhost:4502 (with the whole project built and deployed on it, see `How to build` section above)
* Chrome browser installed at default location

Check README file in `ui.tests` module for more details.
Check README file in `ui.tests.cypress` or `ui.tests.wdio` module for more details.

## ClientLibs

Expand Down
1 change: 1 addition & 0 deletions src/main/archetype/archetype.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ enableDynamicMedia=${enableDynamicMedia}
enableSSR=${enableSSR}
precompiledScripts=${precompiledScripts}
includeFormsheadless=${includeFormsheadless}
uiTestingFramework=${uiTestingFramework}
32 changes: 32 additions & 0 deletions src/main/archetype/ui.tests.cypress/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2023 Adobe Systems Incorporated
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM cypress/included:12.12.0

ENV APP_PATH /usr/src/app
## Install dependencies
RUN apt -qqy update \
# Generic dependencies
&& apt -qqy --no-install-recommends install \
python \
build-essential
# <<< End EAAS Convention \

# Set Application Environment
WORKDIR ${APP_PATH}
COPY ./test-module ./
RUN npm install
# no need to wait for selenium
ENTRYPOINT ["bash","run.sh"]

68 changes: 68 additions & 0 deletions src/main/archetype/ui.tests.cypress/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
UI Testing module (Cypress) for your AEM application
===

Sample structure for [Cypress](https://www.cypress.io) UI test module which conforms to
AEM Cloud Manager quality gate UI test conventions.

## Cloud Manager UI test module conventions

AEM provides an integrated suite of Cloud Manager quality gates to ensure smooth updates to custom applications,
UI tests are executed as part of a specific quality gate for each Cloud Manager pipeline with a dedicated Custom UI Testing step.

The Cloud Manager UI test module convention defines the expected structure of the test module as well as the environment
variables which will be passed at runtime. This is explained in detail in the [Building UI Tests](https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/using-cloud-manager/test-results/functional-testing/ui-testing.html?lang=en#building-ui-tests)
section of the documentation.

## Structure

- `/test-module` The test project (add your tests there)

**Do not modify following files**
- `Dockerfile` commands to assemble the image
- `pom.xml` defines project dependencies and build configuration which will be used by Cloud Manager to build the test module image
- `assembly-ui-test-docker-context.xml` Packages test project for AEMaaCS

### Dockerfile

Sample dockerfile is based on the `cypress/included` [image](https://hub.docker.com/r/cypress/included), which provides all the dependencies and the binaries
to run cypress tests.

### xvfb setup

>When running several Cypress instances in parallel, the spawning of multiple X11 servers at once can cause problems for some of them. In this case, you can separately start a single X11 server and pass the server's address to each Cypress instance using DISPLAY variable.
The setup described in [the documentation](https://docs.cypress.io/guides/continuous-integration/introduction#In-Docker)
is implemented in `run.sh` as is used as entrypoint to the container.

## Run Tests

### Locally (standalone)

Refer to [test-module/README.md](test-module/README.md).

### Build and run test image

The image built from the Dockerfile can be used to execute tests locally against an AEM environment. The `ui-tests-docker-execution`
maven profile will start the docker-compose setup starting Cypress and the test module, executing the tests against
the AEM instance defined via environment variables. The test results will be stored in the `./target/reports` directory.

The following environment variables (AEM UI test convention) can be passed

| envvar | default |
| --- | --- |
| AEM_AUTHOR_URL | http://localhost:4502 |
| AEM_AUTHOR_USERNAME | `admin` |
| AEM_AUTHOR_PASSWORD | `admin` |
| AEM_PUBLISH_URL | http://localhost:4503 |
| AEM_PUBLISH_USERNAME | `admin` |
| AEM_PUBLISH_PASSWORD | `admin` |
| REPORTS_PATH | `cypress/results` |

1. Build the Docker UI test image with below command
```
mvn clean package -Pui-tests-docker-build
```
2. Run the test
```
mvn verify -Pui-tests-docker-execution -DAEM_AUTHOR_URL=https://author.my-deployment.com -DAEM_AUTHOR_USERNAME=<PASS> -DAEM_AUTHOR_PASSWORD=<PASS>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<!--
| Copyright 2023 Adobe Systems Incorporated
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
-->

<!--
| DO NOT MODIFY
-->
<id>ui-test-docker-context</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>${basedir}</directory>
<includes>
<include>Dockerfile</include>
</includes>
</fileSet>
<fileSet>
<directory>${basedir}/test-module</directory>
<excludes>
<exclude>node_modules/**</exclude>
<exclude>target/**</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
189 changes: 189 additions & 0 deletions src/main/archetype/ui.tests.cypress/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
| Copyright 2023 Adobe Systems Incorporated
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
-->

<!--
| DO NOT MODIFY
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.adobe.cq.cloud</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>com.adobe.cq.cloud.testing.ui.cypress.tests</artifactId>
<name>com.adobe.cq.cloud.testing.ui.cypress - UI Tests</name>
<description></description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<REPORTS_PATH>${project.basedir}/target/reports</REPORTS_PATH>

<!-- AEMaaCS UI testing convention properties -->
<AEM_AUTHOR_URL>http://localhost:4502</AEM_AUTHOR_URL>
<AEM_AUTHOR_USERNAME>admin</AEM_AUTHOR_USERNAME>
<AEM_AUTHOR_PASSWORD>admin</AEM_AUTHOR_PASSWORD>
<AEM_PUBLISH_URL />
<AEM_PUBLISH_USERNAME>admin</AEM_PUBLISH_USERNAME>
<AEM_PUBLISH_PASSWORD>admin</AEM_PUBLISH_PASSWORD>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly-ui-test-docker-context.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>ui-tests-docker-build</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>docker-build</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>docker</executable>
<workingDirectory>.</workingDirectory>
<arguments>
<argument>build</argument>
<argument>-t</argument>
<argument>${project.groupId}-${project.artifactId}/ui.tests:${project.version}</argument>
<argument>.</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>docker-tag</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>docker</executable>
<workingDirectory>.</workingDirectory>
<arguments>
<argument>tag</argument>
<argument>${project.groupId}-${project.artifactId}/ui.tests:${project.version}</argument>
<argument>${project.groupId}-${project.artifactId}/ui.tests:latest</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>ui-tests-docker-execution</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>docker-run</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>docker</executable>
<workingDirectory>.</workingDirectory>
<arguments>
<argument>run</argument>
<argument>-eAEM_AUTHOR_URL=${AEM_AUTHOR_URL}</argument>
<argument>-eAEM_AUTHOR_USERNAME=${AEM_AUTHOR_USERNAME}</argument>
<argument>-eAEM_AUTHOR_PASSWORD=${AEM_AUTHOR_PASSWORD}</argument>
<argument>-eAEM_PUBLISH_URL=${AEM_PUBLISH_URL}</argument>
<argument>-eAEM_PUBLISH_USERNAME=${AEM_PUBLISH_USERNAME}</argument>
<argument>-eAEM_PUBLISH_PASSWORD=${AEM_PUBLISH_PASSWORD}</argument>
<argument>-eREPORTS_PATH=/tmp/reports</argument>
<argument>-v${REPORTS_PATH}:/tmp/reports</argument>
<argument>${project.groupId}-${project.artifactId}/ui.tests:latest</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Loading

0 comments on commit dd01179

Please sign in to comment.