Skip to content

Commit ddbc6b7

Browse files
Merge pull request #1 from discoverygarden/implementation
DDST-754, FDSF-221: Initial implementation
2 parents 1a3f4fa + 3f81b4c commit ddbc6b7

17 files changed

+679
-115
lines changed

README.md

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,43 @@
1-
[![tests](https://github.com/ddev/ddev-addon-template/actions/workflows/tests.yml/badge.svg)](https://github.com/ddev/ddev-addon-template/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2025.svg)
1+
[![tests](https://github.com/discoverygarden/ddev-dgi-playwright/actions/workflows/tests.yml/badge.svg)](https://github.com/discoverygarden/ddev-dgi-playwright/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2025.svg)
22

3-
# DDEV add-on template <!-- omit in toc -->
3+
# DGI-PLAYWRIGHT
44

5-
* [What is DDEV add-on template?](#what-is-ddev-add-on-template)
6-
* [Components of the repository](#components-of-the-repository)
7-
* [Getting started](#getting-started)
8-
* [How to debug in Github Actions](./README_DEBUG.md)
5+
Playwright integration for DGI projects, adapted from and using [Lullabot/ddev-playwright](https://github.com/Lullabot/ddev-playwright).
96

10-
## What is DDEV add-on template?
7+
## Enable
118

12-
This repository is a template for providing [DDEV](https://ddev.readthedocs.io) add-ons and services.
9+
Setup process should be straight forward. Download add-on, run install script, and tests will be immediately accessible to run:
1310

14-
In DDEV, add-ons can be installed from the command line using the `ddev add-on get` command, for example, `ddev add-on get ddev/ddev-redis` or `ddev add-on get ddev/ddev-solr`.
11+
```
12+
# Installs the add-on
13+
ddev add-on get discoverygarden/ddev-dgi-playwright
1514
16-
This repository is a quick way to get started. You can create a new repo from this one by clicking the template button in the top right corner of the page.
15+
# Installs playwright with dgi additions
16+
ddev install-dgi-playwright
17+
```
1718

18-
![template button](images/template-button.png)
19+
## Use playwright
1920

20-
## Components of the repository
21+
```
22+
# Runs playwright using playwrights `test` command.
23+
ddev playwright test
2124
22-
* The fundamental contents of the add-on service or other component. For example, in this template there is a [docker-compose.addon-template.yaml](docker-compose.addon-template.yaml) file.
23-
* An [install.yaml](install.yaml) file that describes how to install the service or other component.
24-
* A test suite in [test.bats](tests/test.bats) that makes sure the service continues to work as expected.
25-
* [Github actions setup](.github/workflows/tests.yml) so that the tests run automatically when you push to the repository.
25+
# Runs playwright with access to the UI accessible at <siteuri>:9324
26+
ddev playwright-ui
2627
27-
## Getting started
28+
## Runs playwright in codegen mode
29+
ddev playwright codegen
30+
```
2831

29-
1. Choose a good descriptive name for your add-on. It should probably start with "ddev-" and include the basic service or functionality. If it's particular to a specific CMS, perhaps `ddev-<CMS>-servicename`.
30-
2. Create the new template repository by using the template button.
31-
3. Globally replace "addon-template" with the name of your add-on.
32-
4. Add the files that need to be added to a DDEV project to the repository. For example, you might replace `docker-compose.addon-template.yaml` with the `docker-compose.*.yaml` for your recipe.
33-
5. Update the `install.yaml` to give the necessary instructions for installing the add-on:
32+
## Composer Package Type Details
3433

35-
* The fundamental line is the `project_files` directive, a list of files to be copied from this repo into the project `.ddev` directory.
36-
* You can optionally add files to the `global_files` directive as well, which will cause files to be placed in the global `.ddev` directory, `~/.ddev`.
37-
* Finally, `pre_install_commands` and `post_install_commands` are supported. These can use the host-side environment variables documented [in DDEV docs](https://ddev.readthedocs.io/en/stable/users/extend/custom-commands/#environment-variables-provided).
34+
We define and make use of two "types" of composer project:
35+
* `dgi-playwright-core`: Defining the core Playwright config, including `playwright.config.ts` and including `package.json`/`package-lock.json` indicating the Node.js packages needed; and,
36+
* `dgi-playwright-tests`: Defining a set of tests to run.
3837

39-
6. Update `tests/test.bats` to provide a reasonable test for your repository. Tests will run automatically on every push to the repository, and periodically each night. Please make sure to address test failures when they happen. Others will be depending on you. Bats is a testing framework that just uses Bash. To run a Bats test locally, you have to install [bats-core](https://bats-core.readthedocs.io/en/stable/installation.html) and its [libraries](https://github.com/ztombol/bats-docs) first. Then you download your add-on, and finally run `bats ./tests/test.bats` within the root of the uncompressed directory. To learn more about Bats see the [documentation](https://bats-core.readthedocs.io/en/stable/).
40-
7. When everything is working, including the tests, you can push the repository to GitHub.
41-
8. Create a [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) on GitHub.
42-
9. Test manually with `ddev add-on get <owner/repo>`.
43-
10. You can test PRs with `ddev add-on get https://github.com/<user>/<repo>/tarball/<branch>`.
44-
11. You can test add-ons locally without GitHub by downloading them, making changes and running `ddev add-on get /path/to/add-on-directory`.
45-
12. Update the `README.md` header, adding the machine name of the add-on, for example `# ddev-redis`, not `# DDEV Redis`.
46-
13. Update the `README.md` to describe the add-on, how to use it, and how to contribute. If there are any manual actions that have to be taken, please explain them. If it requires special configuration of the using project, please explain how to do those. Examples in [ddev/ddev-solr](https://github.com/ddev/ddev-solr), [ddev/ddev-memcached](https://github.com/ddev/ddev-memcached), and (advanced) [ddev-platformsh](https://github.com/ddev/ddev-platformsh).
47-
14. Add a good short description to your repo, and add the [topic](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics) "ddev-get". It will immediately be added to the list provided by `ddev add-on list --all`.
48-
15. When it has matured you will hopefully want to have it become an "official" maintained add-on. Open an issue in the [DDEV queue](https://github.com/ddev/ddev/issues) for that.
38+
We expect only one `dgi-playwright-core` package to be installed in a project (into `test/playwright`), and any number of `dgi-playwright-tests` packages (which should get installed into `test/playwright-tests/{$name}`, where `{$name}` is the name of the package without its namespace, as per [`composer/installers`](https://github.com/composer/installers)).
4939

50-
Add-ons were covered in [DDEV Add-ons: Creating, maintaining, testing](https://www.youtube.com/watch?v=TmXqQe48iqE) (part of the [DDEV Contributor Live Training](https://ddev.com/blog/contributor-training)).
40+
## Additional Resources
5141

52-
Note that more advanced techniques are discussed in [Advanced Add-On Techniques](https://ddev.com/blog/advanced-add-on-contributor-training/) and [DDEV docs](https://ddev.readthedocs.io/en/stable/users/extend/additional-services/).
53-
54-
**Contributed and maintained by `@CONTRIBUTOR`**
42+
* [Playwright basic usage docs](https://playwright.dev/docs/intro)
43+
* [Lullabot/ddev-playwright](https://github.com/Lullabot/ddev-playwright)

README_DEBUG.md

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
#ddev-generated
3+
4+
ENV_FILE=".ddev/.env.dgi-playwright"
5+
6+
if ! [ "$(ddev dotenv get $ENV_FILE --composer-installed 2> /dev/null)" == "true" ] ; then
7+
# Add base .gitignore
8+
mkdir -p $DDEV_APPROOT/test
9+
echo "playwright" >> $DDEV_APPROOT/test/.gitignore
10+
echo "playwright-tests" >> $DDEV_APPROOT/test/.gitignore
11+
12+
# Adding the new dgi-playwright-tests installer type and path
13+
ddev composer require --no-update "oomphinc/composer-installers-extender:^2.0"
14+
ddev composer config --merge --json -- extra.installer-types '["dgi-playwright-core", "dgi-playwright-tests"]'
15+
ddev composer config --merge --json -- extra.installer-paths.test/playwright '["type:dgi-playwright-core"]'
16+
ddev composer config --merge --json -- 'extra.installer-paths.test/playwright-tests/{$name}' '["type:dgi-playwright-tests"]'
17+
18+
# Installing the new basic playwright tests
19+
ddev composer require --dev --no-update \
20+
"discoverygarden/playwright-testing-core:^1" \
21+
"discoverygarden/playwright-testing-sample-tests:^1"
22+
23+
ddev composer update oomphinc/composer-installers-extender \
24+
discoverygarden/playwright-testing-core \
25+
discoverygarden/playwright-testing-sample-tests
26+
27+
ddev dotenv set $ENV_FILE --composer-installed true
28+
fi
29+
30+
if ! diff -q $DDEV_APPROOT/.ddev/web-build/disabled.Dockerfile.playwright $DDEV_APPROOT/.ddev/web-build/Dockerfile.playwright ; then
31+
# ddev errors out on subsequent builds if we symlink these files. Instead, we
32+
# copy them each time.
33+
echo "Rebuilding web service with playwright dependencies..."
34+
cp $DDEV_APPROOT/.ddev/web-build/disabled.Dockerfile.playwright $DDEV_APPROOT/.ddev/web-build/Dockerfile.playwright
35+
ddev restart
36+
fi

commands/host/playwright-ui

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#ddev-generated
3+
## Description: Shortcut command to run playwright in the ui
4+
## Usage: playwright-ui
5+
6+
set -e
7+
8+
ddev playwright test --ui-host 0.0.0.0 --ui-port 9323
9+
## Afterwards, navigate to `<hostURI>:9324` to run tests with the UI.
10+
## Setting the port here in reference to the container_port value from the config
11+
## https://github.com/discoverygarden/ddev-dgi-playwright/blob/main/config.playwright.yml#L28

commands/web/playwright

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#ddev-generated
3+
4+
# When initially starting the container, the NSS DB is not populated, so
5+
# let's pre-populate it so we can `mkcert -install` the cert into it.
6+
# Note that the DB would be created after attempting to run the tests once,
7+
# when the browser(s) start.
8+
NSSDB=$HOME/.pki/nssdb
9+
if ! [[ -d $NSSDB ]] ; then
10+
mkdir -p $NSSDB
11+
certutil -d $NSSDB -N --empty-password
12+
fi
13+
mkcert -install
14+
15+
export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"
16+
export NODE_PATH=$NODE_PATH:$DDEV_COMPOSER_ROOT/test/playwright/node_modules
17+
cd test/playwright || exit 1
18+
npm ci && exec npx playwright "$@"

config.playwright.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ddev-generated
2+
hooks:
3+
pre-start:
4+
# If Playwright is enabled, make sure we get any changes.
5+
- exec-host: |
6+
([[ -f .ddev/web-build/Dockerfile.playwright ]] && \
7+
cp .ddev/web-build/disabled.Dockerfile.playwright .ddev/web-build/Dockerfile.playwright) || true
8+
- exec-host: |
9+
if [[ -f .ddev/web-build/Dockerfile.playwright ]]
10+
then
11+
rm -rf .ddev/web-build/playwright
12+
cp -r test/playwright .ddev/web-build/
13+
fi
14+
post-start:
15+
# Clean up the playwright directory copied for builds.
16+
# We want to remove this otherwise future ddev get's will not copy in
17+
# changes to the web-build directory.
18+
- exec-host: rm -rf .ddev/web-build/playwright
19+
web_environment:
20+
- DISPLAY=:1
21+
- DGI_PLAYWRIGHT_TESTS_DIR=$DDEV_COMPOSER_ROOT/test/playwright-tests
22+
- DGI_PLAYWRIGHT_TEST_URL=$DDEV_PRIMARY_URL
23+
# We add the sleep so this doesn't error out when not using playwright.
24+
web_extra_daemons:
25+
- name: "kasmvnc"
26+
command: "kasmvncserver -fg || sleep infinity"
27+
directory: /var/www/html
28+
web_extra_exposed_ports:
29+
- name: playwright
30+
container_port: 9323
31+
http_port: 8323
32+
https_port: 9324
33+
- name: kasmvnc
34+
container_port: 8444
35+
http_port: 8443
36+
https_port: 8444

docker-compose.addon-template.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

images/gh-tmate.jpg

-53.9 KB
Binary file not shown.

images/template-button.png

-20 KB
Binary file not shown.

install.yaml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Details about the install.yaml file are at https://ddev.readthedocs.io/en/stable/users/extend/additional-services/#sections-and-features-of-ddev-get-add-on-installyaml
2-
3-
name: addon-template
1+
name: dgi-playwright
42

53
# pre_install_actions - list of actions to run before installing the addon.
64
# Examples would be removing an extraneous docker volume,
@@ -59,14 +57,17 @@ pre_install_actions:
5957
# If you use directories, they must be directories that are managed
6058
# by this add-on, or removal could remove things that are not owned by it
6159
project_files:
62-
- docker-compose.addon-template.yaml
63-
# - commands/web/add-on-command
64-
# - commands/host/add-on-command-host
65-
# - web-build/Dockerfile.addon-template
66-
# - some-directory/file1.txt
67-
# - some-directory/file2.txt
68-
# - extra_files_dir_created_by_this_template/
69-
# - somefile.sh
60+
- commands/host/playwright-ui
61+
- commands/host/install-dgi-playwright
62+
- commands/web/playwright
63+
- web-build/.gitignore
64+
- web-build/disabled.Dockerfile.playwright
65+
- web-build/Dockerfile.task
66+
- web-build/install-task.sh
67+
- web-build/install-kasmvnc.sh
68+
- web-build/kasmvnc.yaml
69+
- web-build/xstartup
70+
- config.playwright.yml
7071

7172
# List of files and directories that are copied into the global .ddev directory
7273
# DDEV environment variables can be interpolated into these filenames
@@ -85,7 +86,7 @@ ddev_version_constraint: '>= v1.24.2'
8586

8687
# List of add-on names that this add-on depends on
8788
dependencies:
88-
# - redis
89+
# - redis
8990

9091
# DDEV environment variables can be interpolated into these actions.
9192
# post_install_actions are executed in the context of the target project's .ddev directory.
@@ -98,15 +99,9 @@ post_install_actions:
9899
# Files listed in project_files section will be automatically removed here if they contain #ddev-generated line.
99100
# removal_actions are executed in the context of the target project's .ddev directory.
100101
removal_actions:
101-
# - rm ~/.ddev/commands/web/somecommand
102-
# - |
103-
# if [ -f ${DDEV_APPROOT}/.ddev/docker-compose.addon-template_extras.yaml ]; then
104-
# if grep -q '#ddev-generated' ${DDEV_APPROOT}/.ddev/docker-compose.addon-template_extras.yaml; then
105-
# rm -f ${DDEV_APPROOT}/.ddev/docker-compose.addon-template_extras.yaml
106-
# else
107-
# echo "Unwilling to remove '${DDEV_APPROOT}/.ddev/docker-compose.addon-template_extras.yaml' because it does not have #ddev-generated in it; you can manually delete it if it is safe to delete."
108-
# fi
109-
# fi
102+
- |
103+
#ddev-description:Deleting generated Dockerfile.
104+
if grep "#ddev-generated" web-build/Dockerfile.playwright 2>/dev/null; then rm web-build/Dockerfile.playwright; fi
110105
111106
# Advanced usage - YAML files can be read in and then used as go template actions
112107
# in pre_install_actions and post_install_actions

0 commit comments

Comments
 (0)