From a90c42e5be766dd18c6510786e136dfc8c39adc4 Mon Sep 17 00:00:00 2001 From: Chaitra B V Date: Tue, 24 Sep 2024 09:46:27 +0530 Subject: [PATCH 1/2] ZBIO-5788:playwright test using assistance --- .gitignore | 5 ++++- playwright/package.json | 16 ++++++++++++++++ playwright/tests/home.spec.js | 28 ++++++++++++++++++++++++++++ playwright/tests/result.spec.js | 19 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 playwright/package.json create mode 100644 playwright/tests/home.spec.js create mode 100644 playwright/tests/result.spec.js diff --git a/.gitignore b/.gitignore index e55668a0..fc989784 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .DS_Store -generated-files \ No newline at end of file +generated-files +playwright/node_modules +playwright/test-results/* +playwright/package-lock.json \ No newline at end of file diff --git a/playwright/package.json b/playwright/package.json new file mode 100644 index 00000000..9ea7f1f3 --- /dev/null +++ b/playwright/package.json @@ -0,0 +1,16 @@ +{ + "name": "playwright", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@playwright/test": "^1.47.1", + "dotenv": "^16.4.5" + } +} \ No newline at end of file diff --git a/playwright/tests/home.spec.js b/playwright/tests/home.spec.js new file mode 100644 index 00000000..4c56a963 --- /dev/null +++ b/playwright/tests/home.spec.js @@ -0,0 +1,28 @@ +const { test, expect } = require("@playwright/test"); + +test.describe("Home Page", () => { + test.beforeEach(async ({ page }) => { + await page.goto("http://localhost:30041/"); + }); + + test("should load home page", async ({ page }) => { + //await expect(page).toHaveURL(""); + await expect(page.locator(".heading")).toHaveText( + "How do you create a K8S cluster on your local system ?" + ); + }); + + test("should display candidates", async ({ page }) => { + const candidates = await page.locator(".cardContainer .card"); + await expect(candidates).toHaveCount(4); // Assuming there are 5 candidates + }); + + test("should vote for a candidate", async ({ page }) => { + const firstCandidate = page.locator(".cardContainer .card").first(); + await firstCandidate.click(); + // await page.locator("button").click(); // Assuming there is a button to submit the vote + await expect(page.locator(".notification")).toHaveText( + "Vote registered for Roost" + ); + }); +}); diff --git a/playwright/tests/result.spec.js b/playwright/tests/result.spec.js new file mode 100644 index 00000000..3396ad9e --- /dev/null +++ b/playwright/tests/result.spec.js @@ -0,0 +1,19 @@ +const { test, expect } = require("@playwright/test"); + +test.describe("Result Page", () => { + test.beforeEach(async ({ page }) => { + await page.goto("http://localhost:30041/voter/result"); + }); + + test("should load result page", async ({ page }) => { + await expect(page).toHaveURL("http://localhost:30041/voter/result"); + await expect(page.locator(".heading")).toHaveText( + "Developers preference for building K8S cluster" + ); + }); + + test("should display results", async ({ page }) => { + const results = await page.locator(".cardContainer .card"); + await expect(results.first().locator(".voteCount")).toHaveText(/^\d+%$/); // Assuming vote count is displayed as percentage + }); +}); From d293eba4211123790d561aa4f254d3fddb97bc71 Mon Sep 17 00:00:00 2001 From: Chaitra B V Date: Tue, 24 Sep 2024 09:59:22 +0530 Subject: [PATCH 2/2] ZBIO-5788:playwright test using assistance --- .gitignore | 4 +++- playwright/playwright.config.js | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 playwright/playwright.config.js diff --git a/.gitignore b/.gitignore index fc989784..333082a0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ generated-files playwright/node_modules playwright/test-results/* -playwright/package-lock.json \ No newline at end of file +playwright/playwright-report/* +playwright/package-lock.json +playwright/results.json \ No newline at end of file diff --git a/playwright/playwright.config.js b/playwright/playwright.config.js new file mode 100644 index 00000000..b6bb183f --- /dev/null +++ b/playwright/playwright.config.js @@ -0,0 +1,37 @@ +const { defineConfig, devices } = require("@playwright/test"); +/** + * @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 */ + /* Opt out of parallel tests on CI. */ + workers: 1, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: [["html"], ["json", { outputFile: "results.json" }]], + /* 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: 'http://127.0.0.1:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: "on-first-retry", + video: "on", + // ignoreHTTPSErrors: true, + outputDir: "test-results", + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: "chromium", + use: { + ...devices["Desktop Chrome"], + }, + }, + ], +});