Gitlab CI/CD: JAVA/Playwright

Basic GitLab CI/CD & aqua workflow

This guide demonstrates integrating automated testing into your GitLab CI/CD pipeline, specifically using Maven project with JAVA/Playwright. However, the steps can be adapted for any test automation tool or framework to submit results to aqua.

Prerequisites

  • a GitLab project with CI/CD enabled

  • an aqua account to submit test results

  • an application or project configured with Maven project (e.g. using Visual Studi Code)

First, generate clean maven project or use existing one.

Make sure the following dependencies are added to the pom.xml file We will need Playwright, JUnit and JSON libraries.

Create a TestBase class to keep all general methods and implementations of the common logic and hooks: BeforeAll, BeforeEach, AfterAll, AfterEach, etc.

Create a TestCase class which extends the TestBase class and implements actual logic of a particular test. Here and further we assume that this class has an aqua Test Case instance so we will update its execution info in aqua web app. Test Case has one Step (Step 1) in aqua.

TestCase class implements simple actions: open www.wikipedia.org web site using playwright actions, do a few clicks there and check actual Web URL:

Using @AfterEach hook in TestBase class connect to aqua and get bearer token from REST GET request sent by playwright

The above token will be needed for POST request to create an aqua Test Case execution. We will use the following endpoint and JSON schema:

https://app.aqua-cloud.io/aquaWebNG/Help#tag/TestExecution/operation/TestExecution_Create

Example implementation in TestBase class for the above request looks as follows:

In the above request we are passing “logResult” variable. It represents the actual JUnit test result (“Pass”, “Failed”, “NotRun”, etc.) To obtain this status from JUnit run we implement Test Watcher Interface in the TestBase Class:

In this class we should implement Interface Methods as below:

We assume that Test Class name is based on actual aqua Test Case Id: e.g in the case above we updated aqua Test Case with Id=270.

This Id variable can be passed from Test Class by using TestInfo from org.junit.jupiter.api.TestInfo;

After successful JUnit test execution we should see corresponding single Test Case execution in aqua

To be able to run the above Maven Project using GitLab CI/CD we need to create corresponding workflow file .gitlab-ci.yml. Simple Example of .gitlab-ci.yml script is shown below:

Once a GitLab test runner is configured and connected to your GitLab projects we can Run GitLab Pipeline using the above workflow:

Full TestBase class listing:

Full Test Class listing:

Last updated

Was this helpful?