Add ddev playwright addon

This commit is contained in:
Emili Castells Guasch 2023-07-28 15:34:34 +02:00
parent 459d608424
commit 14f8701c96
28 changed files with 386 additions and 83 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,14 @@
name: playwright
repository: julienloizelet/ddev-playwright
version: v2.0.1
install_date: "2023-07-28T14:52:54+02:00"
project_files:
- commands/playwright/playwright
- commands/playwright/playwright-install
- playwright-build/Dockerfile
- playwright-build/kasmvnc.yaml
- playwright-build/xstartup
- playwright-build/entrypoint.sh
- docker-compose.playwright.yaml
global_files: []
removal_actions: []

View file

@ -0,0 +1,14 @@
#!/bin/bash
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
cd /var/www/html || exit 1
cd "${PLAYWRIGHT_TEST_DIR}" || exit 1
export PLAYWRIGHT_BROWSERS_PATH=0
PRE="sudo -u pwuser PLAYWRIGHT_BROWSERS_PATH=0 "
$PRE yarn playwright "$@"

View file

@ -0,0 +1,17 @@
#!/bin/bash
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
cd /var/www/html || exit 1
cd "${PLAYWRIGHT_TEST_DIR}" || exit 1
export PLAYWRIGHT_BROWSERS_PATH=0
PRE="sudo -u pwuser PLAYWRIGHT_BROWSERS_PATH=0 "
$PRE yarn install
$PRE yarn playwright install --with-deps
# Conditionally copy an .env file if an example file exists
[ -f .env.example ] && [ ! -f .env ] && $PRE cp -n .env.example .env; exit 0

View file

@ -0,0 +1,38 @@
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
services:
playwright:
build:
context: playwright-build
container_name: ddev-${DDEV_SITENAME}-playwright
hostname: ${DDEV_SITENAME}-playwright
# These labels ensure this service is discoverable by ddev.
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
environment:
# Modify the PLAYWRIGHT_TEST_DIR folder path to suit your needs
- PLAYWRIGHT_TEST_DIR=tests/Playwright
- NETWORK_IFACE=eth0
- DISPLAY=:1
- VIRTUAL_HOST=$DDEV_HOSTNAME
- HTTP_EXPOSE=8443:8444,9322:9323
- HTTPS_EXPOSE=8444:8444,9323:9323
- DDEV_UID=${DDEV_UID}
- DDEV_GID=${DDEV_GID}
expose:
- "8444"
- "9323"
depends_on:
- web
volumes:
- .:/mnt/ddev_config
- ddev-global-cache:/mnt/ddev-global-cache
- ../:/var/www/html:rw
external_links:
- ddev-router:${DDEV_HOSTNAME}
working_dir: /var/www/html

View file

@ -0,0 +1,57 @@
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
# If on arm64 machine, edit to use mcr.microsoft.com/playwright:focal-arm64
FROM mcr.microsoft.com/playwright:focal
# Debian images by default disable apt caching, so turn it on until we finish
# the build.
RUN mv /etc/apt/apt.conf.d/docker-clean /etc/apt/docker-clean-disabled
USER root
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& apt-get install -y sudo
# Give the pwuser user full `sudo` privileges
RUN echo "pwuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/pwuser \
&& chmod 0440 /etc/sudoers.d/pwuser
# CAROOT for `mkcert` to use, has the CA config
ENV CAROOT=/mnt/ddev-global-cache/mkcert
# Install the correct architecture binary of `mkcert`
RUN export TARGETPLATFORM=linux/$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') && mkdir -p /usr/local/bin && curl --fail -JL -s -o /usr/local/bin/mkcert "https://dl.filippo.io/mkcert/latest?for=${TARGETPLATFORM}"
RUN chmod +x /usr/local/bin/mkcert
# Install a window manager.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& apt-get install -y icewm xauth
# Install kasmvnc for remote access.
RUN /bin/bash -c 'if [ $(arch) == "aarch64" ]; then KASM_ARCH=arm64; else KASM_ARCH=amd64; fi; wget https://github.com/kasmtech/KasmVNC/releases/download/v1.1.0/kasmvncserver_bullseye_1.1.0_${KASM_ARCH}.deb'
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get install -y ./kasmvncserver*.deb
# We're done with apt so disable caching again for the final image.
RUN mv /etc/apt/docker-clean-disabled /etc/apt/apt.conf.d/docker-clean
# prepare KasmVNC
RUN sudo -u pwuser mkdir /home/pwuser/.vnc
COPY kasmvnc.yaml xstartup /home/pwuser/.vnc/
RUN chown pwuser:pwuser /home/pwuser/.vnc/*
RUN sudo -u pwuser touch /home/pwuser/.vnc/.de-was-selected
RUN sudo -u pwuser /bin/bash -c 'echo -e "secret\nsecret\n" | kasmvncpasswd -wo -u pwuser' # We actually disable auth, but KASM complains without it
COPY entrypoint.sh /root/entrypoint.sh
ENTRYPOINT "/root/entrypoint.sh"

View file

@ -0,0 +1,18 @@
#!/bin/bash
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
# Change pwuser IDs to the host IDs supplied by DDEV
usermod -u ${DDEV_UID} pwuser
groupmod -g ${DDEV_GID} pwuser
usermod -a -G ssl-cert pwuser
# Install DDEV certificate
mkcert -install
# Run CMD from parameters as pwuser
sudo -u pwuser vncserver -fg -disableBasicAuth

View file

@ -0,0 +1,14 @@
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
logging:
log_writer_name: all
log_dest: syslog
level: 100
network:
ssl:
require_ssl: false

32
.ddev/playwright-build/xstartup Executable file
View file

@ -0,0 +1,32 @@
#!/bin/sh
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
export DISPLAY=:1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
OS=`uname -s`
if [ $OS = 'Linux' ]; then
case "$WINDOWMANAGER" in
*gnome*)
if [ -e /etc/SuSE-release ]; then
PATH=$PATH:/opt/gnome/bin
export PATH
fi
;;
esac
fi
if [ -x /etc/X11/xinit/xinitrc ]; then
exec /etc/X11/xinit/xinitrc
fi
if [ -f /etc/X11/xinit/xinitrc ]; then
exec sh /etc/X11/xinit/xinitrc
fi
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
icewm-session

19
.github/workflows/playwright.yml vendored Normal file
View file

@ -0,0 +1,19 @@
name: Run Playwright tests via DDEV
on:
push:
workflow_dispatch:
jobs:
ddev-playwright:
uses: inpsyde/reusable-workflows/.github/workflows/ddev-playwright.yml@feature/ddev-playwright
secrets:
COMPOSER_AUTH_JSON: ${{ secrets.PACKAGIST_AUTH_JSON }}
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
ENV_VARS: >-
[
{"name": "SOME_USERNAME", "value": "user1"},
{"name": "SOME_PASSWORD", "value": "pass123"}
]
with:
DDEV_ORCHESTRATE_CMD: ddev orchestrate
PLAYWRIGHT_INSTALL_CMD: ddev playwright-install
PLAYWRIGHT_RUN_CMD: ddev playwright test

View file

@ -69,8 +69,5 @@
"dependencies": {
"dotenv": "^16.0.3",
"npm-run-all": "^4.1.5"
},
"devDependencies": {
"@playwright/test": "^1.31.1"
}
}

View file

@ -1,12 +0,0 @@
require('dotenv').config({ path: '.env.e2e' });
const config = {
testDir: './tests/playwright',
timeout: 60000,
use: {
baseURL: process.env.BASEURL,
ignoreHTTPSErrors: true,
},
};
module.exports = config;

BIN
tests/.DS_Store vendored Normal file

Binary file not shown.

BIN
tests/playwright/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,3 @@
BASEURL="https://ddev-playwright-test.ddev.site"
PAGE_URL="/"

View file

@ -1,3 +1,5 @@
test-results/
playwright-report/
.cache/
node_modules
pw-browsers
test-results
.env
yarn.lock

View file

@ -1,40 +0,0 @@
# Playwright Testing
## Set Environment Variables
Duplicate [.env.e2e.example](/.env.e2e.example) and rename it to `.env.e2e`, set the values needed for the tests, like account credentials, card numbers.
## Install Playwright dependencies (browsers)
```
$ yarn ddev:pw-install
```
## Run Tests
```
$ yarn ddev:pw-tests
```
You can also choose which tests to run filtering by name
```
$ yarn ddev:pw-tests --grep "Test name or part of the name"
```
Or run without the headless mode (show the browser)
```
$ yarn pw-tests-headed
```
Or run with [the test debugger](https://playwright.dev/docs/debug)
```
$ yarn playwright test --debug
```
For the headed/debug mode (currently works only outside DDEV) you may need to re-install the deps if you are not on Linux.
```
$ yarn pw-install
```
---
See [Playwright docs](https://playwright.dev/docs/intro) for more info.

View file

@ -0,0 +1,7 @@
{
"license": "MIT",
"dependencies": {
"@playwright/test": "^1.34.2",
"dotenv": "^16.0.3"
}
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,77 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');
require('dotenv').config({ path: '.env' });
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
[process.env.CI ? 'github' : 'list'],
['html', {open: 'never'}],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.BASEURL,
ignoreHTTPSErrors: true,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
//
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },
/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ..devices['Desktop Chrome'], channel: 'chrome' },
// },
],
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});

View file

@ -0,0 +1,9 @@
const {test, expect} = require('@playwright/test');
const {
BASEURL,
} = process.env;
test('Visit home page', async ({page}) => {
await page.goto(BASEURL);
});

View file

@ -2,21 +2,6 @@
# yarn lockfile v1
"@playwright/test@^1.31.1":
version "1.31.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.31.1.tgz#39d6873dc46af135f12451d79707db7d1357455d"
integrity sha512-IsytVZ+0QLDh1Hj83XatGp/GsI1CDJWbyDaBGbainsh0p2zC7F4toUocqowmjS6sQff2NGT3D9WbDj/3K2CJiA==
dependencies:
"@types/node" "*"
playwright-core "1.31.1"
optionalDependencies:
fsevents "2.3.2"
"@types/node@*":
version "18.14.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.14.1.tgz#90dad8476f1e42797c49d6f8b69aaf9f876fc69f"
integrity sha512-QH+37Qds3E0eDlReeboBxfHbX9omAcBCXEzswCu6jySP642jiM3cYSIkU/REqwhCUqXdonHFuBfJDiAJxMNhaQ==
ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
@ -146,11 +131,6 @@ escape-string-regexp@^1.0.5:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==
fsevents@2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
@ -447,11 +427,6 @@ pify@^3.0.0:
resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176"
integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==
playwright-core@1.31.1:
version "1.31.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.31.1.tgz#4deeebbb8fb73b512593fe24bea206d8fd85ff7f"
integrity sha512-JTyX4kV3/LXsvpHkLzL2I36aCdml4zeE35x+G5aPc4bkLsiRiQshU5lWeVpHFAuC8xAcbI6FDcw/8z3q2xtJSQ==
read-pkg@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389"