From 8c61e9e00b1f985c034abab9300b42ce38d80cca Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Fri, 30 Sep 2022 10:45:26 +0100 Subject: [PATCH] Update acceptance test readme & scripts (#13078) * Update readme to reflect the change to playwright * Update test scripts * update README * update pipelines to run new script * update package.json scripts * dont include demo test in package.json * Add creation of blueprint test * Implement create test script Co-authored-by: Zeegaan --- build/azure-pipelines.yml | 2 +- tests/Umbraco.Tests.AcceptanceTest/README.md | 23 +++++++++---------- .../createTest.js | 21 +++++++++++++++++ .../Umbraco.Tests.AcceptanceTest/package.json | 7 +++--- 4 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 tests/Umbraco.Tests.AcceptanceTest/createTest.js diff --git a/build/azure-pipelines.yml b/build/azure-pipelines.yml index 2b4a5b4428..f83492a35f 100644 --- a/build/azure-pipelines.yml +++ b/build/azure-pipelines.yml @@ -467,7 +467,7 @@ stages: inputs: targetType: inline workingDirectory: tests/Umbraco.Tests.AcceptanceTest - script: 'npm run ui --ignore-certificate-errors' + script: 'npm run test --ignore-certificate-errors' - bash: | if [ -f $(Build.SourcesDirectory)/tests/Umbraco.Tests.AcceptanceTest/results/ ]; then echo "##vso[task.setVariable variable=myfileexists]true" diff --git a/tests/Umbraco.Tests.AcceptanceTest/README.md b/tests/Umbraco.Tests.AcceptanceTest/README.md index 4339004f51..0823a31246 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/README.md +++ b/tests/Umbraco.Tests.AcceptanceTest/README.md @@ -1,12 +1,12 @@ # Umbraco Acceptance Tests ### Prerequisites -- NodeJS 12+ +- NodeJS 16+ - A running installed Umbraco on url: [https://localhost:44331](https://localhost:44331) (Default development port) - - Install using a `SqlServer`/`LocalDb` as the tests execute too fast for `SqlCE` to handle. + - Install using a `SqlServer`/`LocalDb` as the tests execute too fast for `Sqlite` to handle. ### Getting started -The tests are located in the project/folder as `Umbraco.Tests.AcceptanceTests`. Make sure you run `npm install` in that folder, or let your IDE do that. +The tests are located in the project/folder as `Umbraco.Tests.AcceptanceTests`. Make sure you run `npm ci` & `npx playwright install` in that folder, or let your IDE do that. The script will ask you to enter the username and password for a superadmin user of your Umbraco CMS. @@ -16,21 +16,20 @@ There are two npm scripts that can be used to execute the test: 1. `npm run test` - Executes the tests headless. 1. `npm run ui` - - Executes the tests in a browser handled by a cypress application. + - Executes the tests in a browser handled by a playwright application. - In case of errors it is recommended to use the UI to debug. + In case of errors it is recommended to use `await page.pause()` so you can step through your test. -### Enviroment Configuration +### Environment Configuration -The enviroment configuration is begin setup by the npm installation script. -This results in the creation of this file: `cypress.env.json`. +The environment configuration is begin setup by the npm installation script. +This results in the creation of this file: `.env`. This file is already added to `.gitignore` and can contain values that are different for each developer machine. The file has the following content: ``` -{ - "username": "", - "password": "" -} +UMBRACO_USER_LOGIN=email for superadmin +UMBRACO_USER_PASSWORD=password for superadmin +URL=https://localhost:44331 ``` You can change this if you like or run the config script to reset the values, type "npm run config" in your terminal. diff --git a/tests/Umbraco.Tests.AcceptanceTest/createTest.js b/tests/Umbraco.Tests.AcceptanceTest/createTest.js new file mode 100644 index 0000000000..b70903aee5 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/createTest.js @@ -0,0 +1,21 @@ +const fs = require('fs'); + +const args = process.argv.slice(2); + +function generate(fileName) { + fs.writeFileSync( + `./tests/${fileName}.spec.ts`, + `import {test} from '@umbraco/playwright-testhelpers'; + +test.describe('New test file description', () => { + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.login(); + }); + + test('New test', async ({page, umbracoApi, umbracoUi}) => { + }); +});` + ); +} + +generate(args[0] || "newTest"); \ No newline at end of file diff --git a/tests/Umbraco.Tests.AcceptanceTest/package.json b/tests/Umbraco.Tests.AcceptanceTest/package.json index 4c68965f51..b48fafb781 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/package.json +++ b/tests/Umbraco.Tests.AcceptanceTest/package.json @@ -4,9 +4,10 @@ "scripts": { "postinstall": "node postinstall.js", "config": "node config.js", - "ui": "npx playwright test tests/DefaultConfig", - "headed": "npx playwright test --headed tests/DefaultConfig", - "all": "npx playwright test" + "ui": "npx playwright test --headed DefaultConfig", + "test": "npx playwright test DefaultConfig", + "all": "npx playwright test", + "createTest": "node createTest.js" }, "devDependencies": { "@playwright/test": "^1.19.2",