Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
.DS_Store
generated-files
generated-files
playwright/node_modules
playwright/test-results/*
playwright/playwright-report/*
playwright/package-lock.json
playwright/results.json
16 changes: 16 additions & 0 deletions playwright/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
37 changes: 37 additions & 0 deletions playwright/playwright.config.js
Original file line number Diff line number Diff line change
@@ -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"],
},
},
],
});
28 changes: 28 additions & 0 deletions playwright/tests/home.spec.js
Original file line number Diff line number Diff line change
@@ -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"
);
});
});
19 changes: 19 additions & 0 deletions playwright/tests/result.spec.js
Original file line number Diff line number Diff line change
@@ -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
});
});