From 3a2df2d7c8a4db6a9eafd544306d6320fc5732bf Mon Sep 17 00:00:00 2001 From: ytimocin Date: Fri, 16 Feb 2024 10:50:46 -0800 Subject: [PATCH] Adding a secton that waits until the app is ready Signed-off-by: ytimocin --- .github/workflows/test.yaml | 8 +- playwright/package-lock.json | 176 +++++++++++++++++++---- playwright/package.json | 11 +- playwright/tests/demo/demo.app.spec.ts | 3 + playwright/tests/eshop/eshop.app.spec.ts | 3 + playwright/tests/util/helper.ts | 24 ++++ 6 files changed, 187 insertions(+), 38 deletions(-) create mode 100644 playwright/tests/util/helper.ts diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0bee5a8a..3139a3ec 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,9 +4,9 @@ on: workflow_dispatch: inputs: version: - description: 'Radius version number to use (e.g. 0.1.0, 0.1.0-rc1, edge). Defaults to edge.' + description: "Radius version number to use (e.g. 0.1.0, 0.1.0-rc1, edge). Defaults to edge." required: false - default: 'edge' + default: "edge" type: string push: branches: @@ -76,7 +76,7 @@ jobs: enableDapr: false - name: eshop-azure os: ubuntu-latest - runOnPullRequest: false + runOnPullRequest: true app: eshop env: azure path: ./samples/eshop/eshop.bicep @@ -85,7 +85,7 @@ jobs: enableDapr: false - name: eshop-aws os: ubuntu-latest - runOnPullRequest: false + runOnPullRequest: true app: eshop env: aws path: ./samples/eshop/eshop.bicep diff --git a/playwright/package-lock.json b/playwright/package-lock.json index 0cd663b4..b76d1ac7 100644 --- a/playwright/package-lock.json +++ b/playwright/package-lock.json @@ -9,46 +9,112 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "uuid": "^9.0.0" + "axios": "^1.6.7", + "uuid": "^9.0.1" }, "devDependencies": { - "@playwright/test": "^1.35.0", - "@types/node": "^20.6.0", - "@types/uuid": "^9.0.3", - "typescript": "^5.2.2" + "@playwright/test": "^1.41.2", + "@types/node": "^20.11.19", + "@types/uuid": "^9.0.8", + "typescript": "^5.3.3" } }, "node_modules/@playwright/test": { - "version": "1.35.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.35.0.tgz", - "integrity": "sha512-6qXdd5edCBynOwsz1YcNfgX8tNWeuS9fxy5o59D0rvHXxRtjXRebB4gE4vFVfEMXl/z8zTnAzfOs7aQDEs8G4Q==", + "version": "1.41.2", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.41.2.tgz", + "integrity": "sha512-qQB9h7KbibJzrDpkXkYvsmiDJK14FULCCZgEcoe2AvFAS64oCirWTwzTlAYEbKaRxWs5TFesE1Na6izMv3HfGg==", "dev": true, "dependencies": { - "@types/node": "*", - "playwright-core": "1.35.0" + "playwright": "1.41.2" }, "bin": { "playwright": "cli.js" }, "engines": { "node": ">=16" - }, - "optionalDependencies": { - "fsevents": "2.3.2" } }, "node_modules/@types/node": { - "version": "20.6.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.0.tgz", - "integrity": "sha512-najjVq5KN2vsH2U/xyh2opaSEz6cZMR2SetLIlxlj08nOcmPOemJmUK2o4kUzfLqfrWE0PIrNeE16XhYDd3nqg==", - "dev": true + "version": "20.11.19", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz", + "integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/@types/uuid": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.3.tgz", - "integrity": "sha512-taHQQH/3ZyI3zP8M/puluDEIEvtQHVYcC6y3N8ijFtAd28+Ey/G4sg1u2gB01S8MwybLOKAp9/yCMu/uR5l3Ug==", + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", + "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.6.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", + "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "dependencies": { + "follow-redirects": "^1.15.4", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", + "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", @@ -63,10 +129,47 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/playwright": { + "version": "1.41.2", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.41.2.tgz", + "integrity": "sha512-v0bOa6H2GJChDL8pAeLa/LZC4feoAMbSQm1/jF/ySsWWoaNItvrMP7GEkvEEFyCTUYKMxjQKaTSg5up7nR6/8A==", + "dev": true, + "dependencies": { + "playwright-core": "1.41.2" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, "node_modules/playwright-core": { - "version": "1.35.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.35.0.tgz", - "integrity": "sha512-muMXyPmIx/2DPrCHOD1H1ePT01o7OdKxKj2ebmCAYvqhUy+Y1bpal7B0rdoxros7YrXI294JT/DWw2LqyiqTPA==", + "version": "1.41.2", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.41.2.tgz", + "integrity": "sha512-VaTvwCA4Y8kxEe+kfm2+uUUw5Lubf38RxF7FpBxLPmGe5sdNkSg5e3ChEigaGrX7qdqT3pt2m/98LiyvU2x6CA==", "dev": true, "bin": { "playwright-core": "cli.js" @@ -75,10 +178,15 @@ "node": ">=16" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -88,10 +196,20 @@ "node": ">=14.17" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/uuid": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", - "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } diff --git a/playwright/package.json b/playwright/package.json index 1a52aee0..a6d72f61 100644 --- a/playwright/package.json +++ b/playwright/package.json @@ -8,12 +8,13 @@ "author": "", "license": "ISC", "devDependencies": { - "@playwright/test": "^1.35.0", - "@types/node": "^20.6.0", - "@types/uuid": "^9.0.3", - "typescript": "^5.2.2" + "@playwright/test": "^1.41.2", + "@types/node": "^20.11.19", + "@types/uuid": "^9.0.8", + "typescript": "^5.3.3" }, "dependencies": { - "uuid": "^9.0.0" + "axios": "^1.6.7", + "uuid": "^9.0.1" } } diff --git a/playwright/tests/demo/demo.app.spec.ts b/playwright/tests/demo/demo.app.spec.ts index 1d69fa67..84256f5e 100644 --- a/playwright/tests/demo/demo.app.spec.ts +++ b/playwright/tests/demo/demo.app.spec.ts @@ -1,5 +1,6 @@ import { test, expect } from "@playwright/test"; import { v4 as uuidv4 } from "uuid"; +import { waitForWebApp } from "../util/helper"; test("To-Do App Basic UI Checks", async ({ page }) => { // Listen for all console events and handle errors @@ -9,6 +10,8 @@ test("To-Do App Basic UI Checks", async ({ page }) => { } }); + await waitForWebApp("http://localhost:3000/"); + // Go to http://localhost:3000/ await page.goto("http://localhost:3000/"); diff --git a/playwright/tests/eshop/eshop.app.spec.ts b/playwright/tests/eshop/eshop.app.spec.ts index 0b67ab26..68d58691 100644 --- a/playwright/tests/eshop/eshop.app.spec.ts +++ b/playwright/tests/eshop/eshop.app.spec.ts @@ -1,4 +1,5 @@ import { test, expect } from "@playwright/test"; +import { waitForWebApp } from "../util/helper"; test("eShop on Containers App Basic UI and Functionality Checks", async ({ page }) => { // Listen for all console events and handle errors @@ -13,6 +14,8 @@ test("eShop on Containers App Basic UI and Functionality Checks", async ({ page // Remove quotes from the endpoint if they exist endpoint = (endpoint as string).replace(/['"]+/g, '') + + await waitForWebApp(endpoint); await page.goto(endpoint); diff --git a/playwright/tests/util/helper.ts b/playwright/tests/util/helper.ts new file mode 100644 index 00000000..45a5b500 --- /dev/null +++ b/playwright/tests/util/helper.ts @@ -0,0 +1,24 @@ +import axios from "axios"; + +export async function waitForWebApp(url: string | undefined, timeout = 30000) { + if (!url) { + throw new Error("URL is not defined"); + } + + const startTime = Date.now(); + while (true) { + try { + await axios.get(url); + console.log(`Web application is ready: ${url}`); + break; + } catch (error) { + console.log(`Web application is not ready: ${url}`); + if (Date.now() - startTime > timeout) { + throw new Error( + `Web application not ready after ${timeout} ms: ${url}` + ); + } + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + } +}