Skip to content

Commit

Permalink
Cypress UI tests (#433)
Browse files Browse the repository at this point in the history
Added AEMCS UI tests using Cypress
  • Loading branch information
andresbott authored Dec 14, 2023
1 parent 7612925 commit 48f414f
Show file tree
Hide file tree
Showing 35 changed files with 4,569 additions and 4,959 deletions.
2 changes: 1 addition & 1 deletion it.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>com.adobe.cq</groupId>
<artifactId>aem-cloud-testing-clients</artifactId>
<version>1.0.5</version>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import com.adobe.cq.testing.client.CQClient;
import com.adobe.cq.testing.junit.rules.CQAuthorPublishClassRule;
import com.adobe.cq.testing.junit.rules.CQRule;
import com.adobe.cq.testing.junit.rules.Page;
import org.apache.sling.testing.clients.ClientException;
import org.apache.sling.testing.clients.SlingHttpResponse;
import org.junit.*;

import static org.junit.Assert.assertEquals;


/**
* Test that some paths exist out-of-the-box on the author service. This test
Expand Down Expand Up @@ -68,6 +69,12 @@ public static void beforeClass() throws ClientException {
public void testHomePageAuthor() throws ClientException {
adminAuthor.doGet("/", 200);
}
@Test
public void testHomePagePub() throws ClientException {
SlingHttpResponse response = adminPublish.doGet("/", 200);

assertEquals(response.getSlingStatusAsInt(), 200);
}

/**
* Verifies that the sites console exists on author
Expand Down
1 change: 1 addition & 0 deletions ui.tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secret
50 changes: 8 additions & 42 deletions ui.tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,64 +1,30 @@
# Copyright 2020 Adobe Systems Incorporated
# 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
#
FROM node:lts-slim
FROM cypress/included:13.5.1

ENV APP_PATH /usr/src/app
ENV SELENIUM_STARTUP_TIMEOUT 60

# Begin CloudManager Convention >>>
## Environment variables
ENV SELENIUM_BASE_URL http://localhost:4444
ENV SELENIUM_BROWSER chrome
ENV REPORTS_PATH reports
ENV AEM_AUTHOR_URL http://localhost:4502
ENV AEM_AUTHOR_USERNAME admin
ENV AEM_AUTHOR_PASSWORD admin
ENV AEM_PUBLISH_URL http://localhost:4503
ENV AEM_PUBLISH_USERNAME admin
ENV AEM_PUBLISH_PASSWORD admin
# Following convention variables are null by default
# ENV SHARED_FOLDER
# ENV UPLOAD_URL

## Install dependencies for wait_for_grid script
RUN apt -qqy update \
# Generic dependencies
&& apt -qqy --no-install-recommends install \
python \
build-essential \
# for wait_for_grid script
&& apt -qqy --no-install-recommends install \
curl \
jq
# <<< End CloudManager Convention
build-essential

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

# Copy + Install WDIO project
ENV TEST_RUN_COMMAND "npm run test-cloud"
COPY test-module/ ./
RUN npm ci

# Begin CloudManager Convention >>>
## Copy helper to wait on Selenium readiness
COPY wait-for-grid.sh .
RUN chmod 555 wait-for-grid.sh

CMD ./wait-for-grid.sh ${TEST_RUN_COMMAND}
# <<< End CloudManager Convention
148 changes: 61 additions & 87 deletions ui.tests/README.md
Original file line number Diff line number Diff line change
@@ -1,106 +1,80 @@

UI Testing module for your AEM application
UI Testing module for WKND.stie
===

This folder contains a set of sample cypress UI tests that following good practices for AEMCS based on the tests
provided in the [archetype](https://github.com/adobe/aem-project-archetype/tree/develop/src/main/archetype/ui.tests.cypress).

## Structure

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

**Do not modify following files**
* `pom.xml` Builds and executes the test Docker image
* `Dockerfile` Builds test Docker image compatible with AEMaaCS
* `wait-for-grid.sh` Bash script helper to check Selenium readiness in the Docker image
* `docker-compose-wdio-*.yaml` Docker compose files to demo the Docker image with Selenium Docker images
* `assembly-ui-test-docker-context.xml` Packages test project for AEMaaCS


## Requirements

* Maven
* Latest version of Chrome and/or Firefox browser installed locally in default location
* An AEM author instance running at http://localhost:4502
* Sample application deployed on your AEM author instance (see [../README.md](../README.md))
Note: this set of tests are intended to be used on AEMCS and have only been verified using a Cloud instance

## Structure

## Run Tests
- `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
- `/test-module` The test project (add your tests there)

```
mvn verify -Pui-tests-local-execution
```
### Dockerfile

#### Remarks
* After execution, reports and logs are available in `target/reports` folder
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.

### Parameters
### xvfb setup

| Parameter | Required | Default| Description |
| --- | --- | --- | --- |
| `AEM_AUTHOR_URL` | false | `http://localhost:4502` | URL of the author instance |
| `AEM_AUTHOR_USERNAME` | false | `admin` | Username used to access the author instance |
| `AEM_AUTHOR_PASSWORD` | false | `admin` | Password used to access the author instance |
| `AEM_PUBLISH_URL` | false | - | URL of the publish instance |
| `AEM_PUBLISH_USERNAME` | false | `admin` | Username used to access the publish instance |
| `AEM_PUBLISH_PASSWORD` | false | `admin` | Password used to access the publish instance |
| `SELENIUM_BROWSER` | false | `chrome` | Browser used in the tests (`chrome` **_or_** `firefox`) |
| `HEADLESS_BROWSER` | false | `false` | Set [headless mode](https://en.wikipedia.org/wiki/Headless_browser) of the browser |
>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 the DISPLAY environment variable.
#### Example
The setup described in [the documentation](https://docs.cypress.io/guides/continuous-integration/introduction#In-Docker)
is implemented in `run.sh`, used as the _entrypoint_ to the container.

Run tests on <span style="color:green">local</span> <span style="color:orange">headless</span> <span style="color:purple">firefox</span>, targeting a <span style="color:blue">custom AEM author instance</span>:
## Execute test module

<PRE>
mvn test \
<span style="color:green">-Plocal-execution</span> \
<span style="color:orange">-DHEADLESS_BROWSER=true</span> \
<span style="color:purple">-DSELENIUM_BROWSER=firefox</span> \
<span style="color:blue">-DAEM_AUTHOR_URL=http://my-aem-author-instance.com</span> \
<span style="color:blue">-DAEM_AUTHOR_USERNAME=testuser</span> \
<span style="color:blue">-DAEM_AUTHOR_PASSWORD=aVVe5om3</span>
</PRE>
### Locally (standalone)

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

## Docker execution
### Using the test image

This project also provides Maven profiles to build and execute the tests using Docker
In the Cloud Manager pipeline the test image will be build and executed, this behaviour can also be recreated.

### Requirements
#### Requirements

* Maven
* Docker and `docker-compose`
* An AEM author instance running at http://localhost:4502

### Build test image

```
mvn clean install -Pui-tests-docker-build
```

will build Docker image `com.adobe.aem.guides-aem-guides-wknd.ui.tests/ui.tests` locally

### Run Tests

**Remarks**
* Following commands will start a Docker service with both the cloud tests and a Selenium server (using official Docker images)
* Parameters described above also apply for Docker use case

#### Target a local AEM author instance

Example, your instance is available at http://localhost:4502):

```
mvn verify -Pui-tests-docker-execution -DAEM_AUTHOR_URL=http://host.docker.internal:4502
```

> `host.docker.internal` is a Docker convention, do not change it!
#### Target a remote AEM author instance

Example, you have an [AEM as a Cloud Service](https://docs.adobe.com/content/help/en/experience-manager-cloud-service/overview/introduction.html) deployment with author instance available at https://author.my-deployment.com:


```
mvn verify -Pui-tests-docker-execution -DAEM_AUTHOR_URL=https://author.my-deployment.com
```

> **&#x26A0; Default tests provided in this module require sample content (module `ui.content`) to be installed in your AEMaaCS deployment!**
* Docker
* Latest version of Chrome installed locally in default location
* Sample application deployed on your AEMCS environment (Author + Publish)

#### Build and run the 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 | https://author-p***-e***.adobeaemcloud.com |
| AEM_AUTHOR_USERNAME | `admin` |
| AEM_AUTHOR_PASSWORD | `admin` |
| AEM_PUBLISH_URL | https://publish-p***-e***.adobeaemcloud.com|
| 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 (set environment variables accordingly)
```
mvn verify -Pui-tests-docker-execution \
-DAEM_AUTHOR_URL=${AEM_AUTHOR_URL} \
-DAEM_AUTHOR_USERNAME=${AEM_AUTHOR_USERNAME} \
-DAEM_AUTHOR_PASSWORD=${AEM_AUTHOR_PASSWORD} \
-DAEM_PUBLISH_URL=${AEM_PUBLISH_URL} \
-DAEM_PUBLISH_USERNAME=${AEM_PUBLISH_USERNAME} \
-DAEM_PUBLISH_PASSWORD=${AEM_PUBLISH_PASSWORD}
```
10 changes: 4 additions & 6 deletions ui.tests/assembly-ui-test-docker-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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 2020 Adobe Systems Incorporated
| 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.
Expand Down Expand Up @@ -30,17 +30,15 @@
<directory>${basedir}</directory>
<includes>
<include>Dockerfile</include>
<include>wait-for-grid.sh</include>
<include>testing.properties</include> <!-- opt-in test module in Cloud Manager -->
</includes>
</fileSet>
<fileSet>
<directory>${basedir}/test-module</directory>
<excludes>
<exclude>node/**</exclude>
<exclude>node_modules/**</exclude>
<exclude>reports/**</exclude>
<exclude>reports/wdio.conf.local*</exclude>
<exclude>target/**</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
</assembly>
46 changes: 0 additions & 46 deletions ui.tests/docker-compose-wdio-chrome.yaml

This file was deleted.

Loading

0 comments on commit 48f414f

Please sign in to comment.