Responsive

Bring Playwright Tests Into The Cloud With Testkube

Feb 28, 2023
4 min
read
Playwright is one of today's most popular end-to-end testing frameworks. Learn how to harness its power in your cloud native apps using Testkube.
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Want to learn more about this topic? Check out our Office Hours sessions!

Get Started with Testkube Pro

The Testkube community is getting bigger and stronger each day, and your contributions help us accelerate development. Playwright has been on Testkube’s radar since July 2022. Thanks to @chooco13, it’s now a reality. 🎉 

We are grateful and happy to announce that we support Playwright in Testkube’s version 1.10!

What is Playwright Testing?

Playwright is one of today's most popular end-to-end testing frameworks. It has been around since January 2020 and is gaining popularity due to its versatility, ease of use and speed of execution. It supports end-to-end testing, multiple browsers, operating systems and languages, among many other features that make the work of modern developers and testers more efficient.

Testkube is a test orchestration tool, helping projects bring their test automation to the cloud. It is built on top of Kubernetes, enabling users to run tests close to their already existing development environment. For a list of all the supported testing tools please visit the official Testkube documentation.

With Testkube you can easily automate the Playwright tests you create, and test your applications running on Kubernetes the cloud native way. It will help you visualize the state of all your tests in one place. It will make it easy to deploy new ones and manage the already existing ones.

Getting Started With Playwright and Testkube

Running a Playwright test with Testkube is a straightforward process. While some knowledge of Kubernetes is advised for advanced features, it is not a requirement for importing and running basic tests. To install and get familiar with Testkube, please consult our Getting Started guide.

It is also important that your Playwright tests are available in a Git repository. Testkube runners support working with files, URIs to files, Git files and Git directories. Given the nature of Playwright tests, Testkube is expecting Git directories as an input to the Playwright executor.

Another important note is that the configuration file (called `playwright.config.*`) does not necessarily have to disable the reporter that would open a browser window. However, you might want to set it up in case you want to run it locally using the official Docker images:

```bash

reporter: [  

['html', { open: 'never' }]  

],

```

In case that it's not set, Testkube has it configured using environment variables in the Docker image:

```bash

ENV CI=1

ENV PWTEST_SKIP_TEST_OUTPUT=1

```

The released Playwright executor only supports Playwright version 1.30.0. This is a limitation imposed by the underlying Playwright image, and will be tackled in further Testkube releases. Please make sure to pin the Playwright dependency to 1.30.0, otherwise you might run into issues of form:
```bash

browserType.launch: Executable doesn't exist at /ms-playwright/chromium-1048/chrome-linux/chrome

```

Prepare your Playwright Tests for Docker Containers

Playwright has numerous functionalities. Running automation in containers imposes some limits on which features are accessible. If you are already running Playwright in your CI/CD pipelines, you probably have a good understanding of which features are available, and how you should configure your test runs.

The Testkube Playwright executor was built on top of the official Docker image from Microsoft: mcr.microsoft.com/playwright:v1.30.0-focal and is a wrapper that makes sure Testkube can set the inputs and read the outputs properly. In case you are not familiar with these limitations, it basically means you cannot write or generate code, spin up browser windows, inspect traces, do anything GUI-related, or interact with the run on the command line. You will need to have the tests already written and able to run them without any manual assistance.

Playwright has a great explanation of its Test Runner on their website. They not only explain how to create runner-compatible tests, but also how to configure and collect the necessary artifacts: screenshots, videos, traces.

Import Playwright Tests into Testkube

There are multiple ways to work with Testkube. In this post, only the most popular ones will be shown: the UI and the CLI.

Some users prefer to use the API or CRDs via ArgoCD or Flux. GitHub Actions are also supported.

Create and Visualize Playwright Test Results with Testkube’s UI

The Testkube UI is the most straightforward way to interact with Testkube. It is a web-based application that you can access using your browser. In case of a local installation, the easiest way to reach it is via the `testkube dashboard` command which opens Testkube in a new window in the browser.

Testkube dashboard - Kubernetes-native testing framework

To import a new test, click on `Add a new test` and enter the details of your test. A new modal will open up, and you will have to populate it with the details of the test location. Example:

Creating a Playwright test in Kubernetes using Testkube

In case you are using a repository with multiple tests, it might be worth looking into Test Sources. For the sake of simplicity, we are sticking with the Git directory as the source type.

Once everything looks good, click on `Create` and see the newly created Testkube Test in your environment. Running this Test will create a new Execution, where you can follow along the logs, see the created Testkube Artifacts, and get suggestions on how to interact with this Test on the CLI:

Displaying logs for your Playwright tests in Kubernetes using Testkube

The Testkube Playwright executor treats the reports created by Playwright as Artifacts. They are compressed into a zip archive and uploaded into the configured object storage - by default this is a MinIO deployment in the Kubernetes cluster. Downloading them from the UI is straightforward, as they appear under the `Artifacts` tab in the Execution's view.

Using the CLI to Create Tests

Testkube also offers a CLI tool that needs to be installed and updated separately from the Testkube API server. Please make sure you are always using the latest and greatest by checking `testkube version`:

Testkube CLI - A Kubernetes-native testing framework

To create a new Playwright test, use the `testkube create test` command. Here is an example using the same repository as in the UI instructions:

```bash

$ testkube create test --git-uri https://github.com/vLia/testkube-tests.git --git-path playwright --git-branch lilla/feat/playwright-executor --type playwright/test --name my-first-playwright-test

```

Creating a Playwright Kubernetes test from the Testkube CLI

To run this test, only the name needs to be passed:

```bash

testkube run test my-first-playwright-test

```

Executing a Playwright Kubernetes test from the Testkube CLI

As the output suggests, the Execution logs can be followed with the `testkube watch execution <executionName>` command, and they will also be shown on `testkube get execution <executionName>`.

To get the reports on the command line, there are commands related to artifacts. Listing them can be done using `testkube get artifact <executionName>`:

Accessing Playwright Kubernetes test from the Testkube CLI

For downloading an artifact, please use `testkube download artifact <executionName> <artifactName> <destinationFolder>`:

Accessing Playwright Kubernetes test from the Testkube CLI

For setting environment variables and arguments, and further features, please consult the Testkube documentation.

And that’s it! You’ve successfully run your first Playwright test with Testkube.

Give it a go!

Automating your Playwright tests the cloud-native way should be as easy as plugging your code into your already existing Kubernetes cluster. Why not improve your testing process?

Sign up to Testkube and try one of our examples or head over to our documentation - if you get stuck or have questions, we’re here to help! Find an answer to your questions in the Testkube Knowledge Base or reach out to us on Slack. We’re eager to hear how you use our integrations!

Responsive
Testkube blog

Bring Playwright Tests Into The Cloud With Testkube

4 min
read
Lilla Vass
Software Engineer
Testkube
Playwright is one of today's most popular end-to-end testing frameworks. Learn how to harness its power in your cloud native apps using Testkube.
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Get Started with Testkube Pro

The Testkube community is getting bigger and stronger each day, and your contributions help us accelerate development. Playwright has been on Testkube’s radar since July 2022. Thanks to @chooco13, it’s now a reality. 🎉 

We are grateful and happy to announce that we support Playwright in Testkube’s version 1.10!

What is Playwright Testing?

Playwright is one of today's most popular end-to-end testing frameworks. It has been around since January 2020 and is gaining popularity due to its versatility, ease of use and speed of execution. It supports end-to-end testing, multiple browsers, operating systems and languages, among many other features that make the work of modern developers and testers more efficient.

Testkube is a test orchestration tool, helping projects bring their test automation to the cloud. It is built on top of Kubernetes, enabling users to run tests close to their already existing development environment. For a list of all the supported testing tools please visit the official Testkube documentation.

With Testkube you can easily automate the Playwright tests you create, and test your applications running on Kubernetes the cloud native way. It will help you visualize the state of all your tests in one place. It will make it easy to deploy new ones and manage the already existing ones.

Getting Started With Playwright and Testkube

Running a Playwright test with Testkube is a straightforward process. While some knowledge of Kubernetes is advised for advanced features, it is not a requirement for importing and running basic tests. To install and get familiar with Testkube, please consult our Getting Started guide.

It is also important that your Playwright tests are available in a Git repository. Testkube runners support working with files, URIs to files, Git files and Git directories. Given the nature of Playwright tests, Testkube is expecting Git directories as an input to the Playwright executor.

Another important note is that the configuration file (called `playwright.config.*`) does not necessarily have to disable the reporter that would open a browser window. However, you might want to set it up in case you want to run it locally using the official Docker images:

```bash

reporter: [  

['html', { open: 'never' }]  

],

```

In case that it's not set, Testkube has it configured using environment variables in the Docker image:

```bash

ENV CI=1

ENV PWTEST_SKIP_TEST_OUTPUT=1

```

The released Playwright executor only supports Playwright version 1.30.0. This is a limitation imposed by the underlying Playwright image, and will be tackled in further Testkube releases. Please make sure to pin the Playwright dependency to 1.30.0, otherwise you might run into issues of form:
```bash

browserType.launch: Executable doesn't exist at /ms-playwright/chromium-1048/chrome-linux/chrome

```

Prepare your Playwright Tests for Docker Containers

Playwright has numerous functionalities. Running automation in containers imposes some limits on which features are accessible. If you are already running Playwright in your CI/CD pipelines, you probably have a good understanding of which features are available, and how you should configure your test runs.

The Testkube Playwright executor was built on top of the official Docker image from Microsoft: mcr.microsoft.com/playwright:v1.30.0-focal and is a wrapper that makes sure Testkube can set the inputs and read the outputs properly. In case you are not familiar with these limitations, it basically means you cannot write or generate code, spin up browser windows, inspect traces, do anything GUI-related, or interact with the run on the command line. You will need to have the tests already written and able to run them without any manual assistance.

Playwright has a great explanation of its Test Runner on their website. They not only explain how to create runner-compatible tests, but also how to configure and collect the necessary artifacts: screenshots, videos, traces.

Import Playwright Tests into Testkube

There are multiple ways to work with Testkube. In this post, only the most popular ones will be shown: the UI and the CLI.

Some users prefer to use the API or CRDs via ArgoCD or Flux. GitHub Actions are also supported.

Create and Visualize Playwright Test Results with Testkube’s UI

The Testkube UI is the most straightforward way to interact with Testkube. It is a web-based application that you can access using your browser. In case of a local installation, the easiest way to reach it is via the `testkube dashboard` command which opens Testkube in a new window in the browser.

Testkube dashboard - Kubernetes-native testing framework

To import a new test, click on `Add a new test` and enter the details of your test. A new modal will open up, and you will have to populate it with the details of the test location. Example:

Creating a Playwright test in Kubernetes using Testkube

In case you are using a repository with multiple tests, it might be worth looking into Test Sources. For the sake of simplicity, we are sticking with the Git directory as the source type.

Once everything looks good, click on `Create` and see the newly created Testkube Test in your environment. Running this Test will create a new Execution, where you can follow along the logs, see the created Testkube Artifacts, and get suggestions on how to interact with this Test on the CLI:

Displaying logs for your Playwright tests in Kubernetes using Testkube

The Testkube Playwright executor treats the reports created by Playwright as Artifacts. They are compressed into a zip archive and uploaded into the configured object storage - by default this is a MinIO deployment in the Kubernetes cluster. Downloading them from the UI is straightforward, as they appear under the `Artifacts` tab in the Execution's view.

Using the CLI to Create Tests

Testkube also offers a CLI tool that needs to be installed and updated separately from the Testkube API server. Please make sure you are always using the latest and greatest by checking `testkube version`:

Testkube CLI - A Kubernetes-native testing framework

To create a new Playwright test, use the `testkube create test` command. Here is an example using the same repository as in the UI instructions:

```bash

$ testkube create test --git-uri https://github.com/vLia/testkube-tests.git --git-path playwright --git-branch lilla/feat/playwright-executor --type playwright/test --name my-first-playwright-test

```

Creating a Playwright Kubernetes test from the Testkube CLI

To run this test, only the name needs to be passed:

```bash

testkube run test my-first-playwright-test

```

Executing a Playwright Kubernetes test from the Testkube CLI

As the output suggests, the Execution logs can be followed with the `testkube watch execution <executionName>` command, and they will also be shown on `testkube get execution <executionName>`.

To get the reports on the command line, there are commands related to artifacts. Listing them can be done using `testkube get artifact <executionName>`:

Accessing Playwright Kubernetes test from the Testkube CLI

For downloading an artifact, please use `testkube download artifact <executionName> <artifactName> <destinationFolder>`:

Accessing Playwright Kubernetes test from the Testkube CLI

For setting environment variables and arguments, and further features, please consult the Testkube documentation.

And that’s it! You’ve successfully run your first Playwright test with Testkube.

Give it a go!

Automating your Playwright tests the cloud-native way should be as easy as plugging your code into your already existing Kubernetes cluster. Why not improve your testing process?

Sign up to Testkube and try one of our examples or head over to our documentation - if you get stuck or have questions, we’re here to help! Find an answer to your questions in the Testkube Knowledge Base or reach out to us on Slack. We’re eager to hear how you use our integrations!

Tags
No items found.
Lilla Vass
Software Engineer
Testkube
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Related Content

No items found.