playwright-json-summary-reporter-fork
v1.1.0-17
Published
A Simple Playwright Reporter
Downloads
64
Maintainers
Readme
playwright-json-summary-reporter-fork
This package can be installed to generate a simple summary.json
file that can be used as apart of a Playwright Test
automation framework. My main use case for building this is to have quick access to a list of failed or succeeded tests for re-running failures (outside of playwright's retry functionality). I also use this as a way to quickly identify if all tests passed within a github action.
Install
npm install [email protected] --save-dev
Usage
Modify your playwright.config.ts
file to include the reporter:
reporter: [
['playwright-json-summary-reporter-fork'],
['html'], // other reporters
['dot']
],
Now when you run a test there should be a new file summary.json
that gets saved to the root of the directory. An example of the file is shown below.
{
"tests": [
{
"testPath": "tests/main_page/main_page.spec.ts:12:9",
"project": "iPhone 12",
"testTitle": "visual main page",
"status": "failed"
},
{
"testPath": "tests/media/meetups_page.spec.ts:19:9",
"project": "iPhone 12",
"testTitle": "visual meetups page",
"status": "passed"
}
]
}
Пример makefile-а для использования в CI с рераном только упавших тестов из summary.json
build-playwright-image:
docker buildx build --platform linux/amd64,linux/arm64 --tag harbor.kolesa-team.org/utils/playwright:latest --file ./tests/e2e/Dockerfile . && \
docker push harbor.kolesa-team.org/utils/playwright:latest
# Парсинг флагов командной строки
flags:
while [ $$# -gt 0 ]; do \
case "$$1" in \
--config=*) config=$${1#*=}; shift;; \
--run=*) run=$${1#*=}; shift;; \
-u) shift; update_snapshots=-u; shift;; \
--headed) headed=$$1; shift;; \
--shard*) shard=--shard=$${1#*=}; shift;; \
--grep=*) grep=$${1#*=}; shift;; \
--projects=*) projects=$${1#*=}; shift;; \
*) echo "Unknown option: $$1" >&2; exit 1;; \
esac; \
done
playwright_docker_run_base := docker run --rm \
-e FAILED_TESTS="$$(jq -r ".tests | map(select(.status == \"failed\")) | .[].testPath" ./summary.json | tr "\n" " ")" \
-e TEST_TITLES="$$(jq -r '.tests | map(select(.status == "failed")) | map(.testTitle) | unique | join("|")' ./summary.json)" \
-e UNIQUE_PROJECTS="$$(jq -r '.tests | map(select(.status == "failed")) | map(.project) | unique | join(",")' ./summary.json)" \
--volume $$(pwd):/code \
--user root \
--workdir /code \
--ipc=host \
ci_docker_run := $(playwright_docker_run_base) \
-e IS_CI=true \
harbor.kolesa-team.org/utils/playwright:latest \
# make playwright-ci -- run="npx playwright test" config=--config=./tests/e2e/playwright.config.ts grep='-g "visual main page|visual meetups page"' projects='--project="iPhone 12"'
playwright-ci: flags
$(ci_docker_run) bash -c '\
echo "FAILED_TESTS: $${FAILED_TESTS}"; \
echo "TEST_TITLES: $${TEST_TITLES}"; \
echo "UNIQUE_PROJECTS: $${UNIQUE_PROJECTS}"; \
if [ -n "$${FAILED_TESTS}" ]; then \
projects_args=(); \
IFS=","; \
projects_array=($${UNIQUE_PROJECTS}); \
for project in $${projects_array[@]}; do \
projects_args+=("--project=$${project}"); \
done; \
echo "$(run) $(config) ${update_snapshots} $${projects_args[@]} -g $${TEST_TITLES}"; \
$(run) $(config) ${update_snapshots} $${projects_args[@]} -g $${TEST_TITLES}; \
else \
echo "$(run) $(config) ${update_snapshots} ${shard} ${grep} ${projects}"; \
$(run) $(config) ${update_snapshots} ${shard} ${grep} ${projects}; \
fi'
# make playwright-docker-local -- run="npx playwright test" config=--config=./tests/e2e/playwright.config.ts grep='-g "visual main page|visual meetups page"' projects='--project="iPhone 12"' headed=--headed
playwright-docker-local: flags
$(local_docker_run) bash -c '\
echo "FAILED_TESTS: $${FAILED_TESTS}"; \
echo "TEST_TITLES: $${TEST_TITLES}"; \
echo "UNIQUE_PROJECTS: $${UNIQUE_PROJECTS}"; \
if [ -n "$${FAILED_TESTS}" ]; then \
projects_args=(); \
IFS=","; \
projects_array=($${UNIQUE_PROJECTS}); \
for project in $${projects_array[@]}; do \
projects_args+=("--project=$${project}"); \
done; \
echo "$(run) $(config) ${update_snapshots} $${projects_args[@]} -g $${TEST_TITLES}"; \
$(run) $(config) ${update_snapshots} $${projects_args[@]} -g $${TEST_TITLES}; \
else \
echo "$(run) $(config) ${update_snapshots} ${shard} ${grep} ${projects}"; \
$(run) $(config) ${update_snapshots} ${shard} ${grep} ${projects}; \
fi'
If you found this helpful feel free to check out https://playwrightsolutions.com!