diff --git a/.gitignore b/.gitignore index e55668a..333082a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ .DS_Store -generated-files \ No newline at end of file +generated-files +playwright/node_modules +playwright/test-results/* +playwright/playwright-report/* +playwright/package-lock.json +playwright/results.json \ No newline at end of file diff --git a/playwright/package.json b/playwright/package.json new file mode 100644 index 0000000..9ea7f1f --- /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/playwright.config.js b/playwright/playwright.config.js new file mode 100644 index 0000000..b6bb183 --- /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"], + }, + }, + ], +}); diff --git a/playwright/tests/home.spec.js b/playwright/tests/home.spec.js new file mode 100644 index 0000000..4c56a96 --- /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 0000000..3396ad9 --- /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 + }); +});