-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d3dbad6
Showing
15 changed files
with
453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Installation | ||
|
||
1. `npm install` | ||
2. `npx playwright install --with-deps chromium` | ||
|
||
## Web | ||
https://automat.ostrava.digital/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "playwright-test-automation-playground", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "npx playwright test --reporter=list", | ||
"test:codegen": "npx playwright codegen https://automat.ostrava.digital", | ||
"test:headed": "npx playwright test --ui", | ||
"format": "prettier --write ." | ||
}, | ||
"keywords": [], | ||
"author": "Vojtěch Červený", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@playwright/test": "^1.44.0", | ||
"@types/node": "^20.12.10", | ||
"prettier": "^3.2.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Page } from "@playwright/test"; | ||
import { ButtonPage } from "./buttons"; | ||
import { CatsPage } from "./cats"; | ||
|
||
export class AllPages { | ||
readonly buttonPage: ButtonPage; | ||
readonly catsPage: CatsPage; | ||
readonly page: Page; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.buttonPage = new ButtonPage(page); | ||
this.catsPage = new CatsPage(page); | ||
} | ||
|
||
async visit(url: string) { | ||
await this.page.goto(url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Locator, Page, expect } from "@playwright/test"; | ||
|
||
export class ButtonPage { | ||
readonly page: Page; | ||
readonly navigationBar: string; | ||
readonly header: Locator; | ||
|
||
readonly buttonById: Locator; | ||
readonly buttonByName: Locator; | ||
readonly buttonByClass: Locator; | ||
readonly buttonByText: Locator; | ||
readonly buttonByXPath: Locator; | ||
readonly buttonByPartialText: Locator; | ||
readonly buttonByDataQA: Locator; | ||
|
||
readonly buttonOutsideDiv: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.navigationBar = "nav"; | ||
this.header = page.getByRole("heading", { name: "Tlačítka" }); | ||
|
||
// OH! Fill this! Check the HTML and fill the selectors. Use whatever selector you want. | ||
this.buttonById = page.locator("#button1"); | ||
this.buttonByName; | ||
this.buttonByClass; | ||
this.buttonByText; | ||
this.buttonByXPath; | ||
this.buttonByPartialText; | ||
this.buttonByDataQA; | ||
|
||
this.buttonOutsideDiv; | ||
} | ||
|
||
async visit() { | ||
await this.page.goto("/selectorsButtons.html"); | ||
} | ||
|
||
async expectToAllButtonsAreClicked() { | ||
// this.header.waitFor({ state: "visible" }); | ||
const buttons = this.page.getByRole("button"); | ||
|
||
for (const button of await buttons.all()) { | ||
await expect.soft(button).toHaveClass("btn-success", { timeout: 100 }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Locator, Page, expect } from "@playwright/test"; | ||
|
||
export class CatsPage { | ||
readonly page: Page; | ||
readonly navigationBar: string; | ||
readonly header: Locator; | ||
|
||
readonly addCatButton: Locator; | ||
readonly removeCaButton: Locator; | ||
readonly apocalypseButton: Locator; | ||
|
||
readonly catCards: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.navigationBar = "nav"; | ||
this.header = page.getByRole("heading", { name: "Tlačítka" }); | ||
|
||
// OH! Fill this! Check the HTML and fill the selectors. Use whatever selector you want. | ||
this.addCatButton; | ||
this.removeCaButton; | ||
this.apocalypseButton; | ||
this.catCards; | ||
} | ||
|
||
async visit() { | ||
await this.page.goto("/adding.html"); | ||
} | ||
|
||
// or you can use expext(pages.catPage.catCards).toHaveCount(3) | ||
// or different number | ||
getCountOfCatCards = async () => { | ||
return await this.catCards.count(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default 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 */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
// TURN OFF PARALLEL TESTS | ||
workers: process.env.CI ? 1 : 1, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "html", | ||
/* 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: "https://automat.ostrava.digital/", | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
testIdAttribute: "data-qa", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
import { AllPages } from "../pages/allpages"; | ||
|
||
test.describe("Buttons", () => { | ||
let pages: AllPages; | ||
test.beforeEach(async ({ page }) => { | ||
pages = new AllPages(page); | ||
await pages.buttonPage.visit(); | ||
}); | ||
|
||
// this works | ||
test("button ID should be clicked", async () => { | ||
await pages.buttonPage.buttonById.click({ timeout: 1000 }); | ||
await expect(pages.buttonPage.buttonById).toHaveClass(/btn-success/); | ||
}); | ||
|
||
// ------------------------------ 👀 | ||
// these tests needs to be fixed - add locator to buttons | ||
test.skip("button name should be clicked", async () => { | ||
await pages.buttonPage.buttonByName.click({ timeout: 1000 }); | ||
await expect(pages.buttonPage.buttonByName).toHaveClass(/btn-success/); | ||
}); | ||
|
||
test.skip("button class should be clicked", async () => { | ||
await pages.buttonPage.buttonByClass.click({ timeout: 1000 }); | ||
await expect(pages.buttonPage.buttonByClass).toHaveClass(/btn-success/); | ||
}); | ||
|
||
test.skip("button text should be clicked", async () => { | ||
await pages.buttonPage.buttonByText.click({ timeout: 1000 }); | ||
await expect(pages.buttonPage.buttonByText).toHaveClass(/btn-success/); | ||
}); | ||
|
||
test.skip("button XPath should be clicked", async () => { | ||
await pages.buttonPage.buttonByXPath.click({ timeout: 1000 }); | ||
await expect(pages.buttonPage.buttonByXPath).toHaveClass(/btn-success/); | ||
}); | ||
|
||
test.skip("button partial text should be clicked", async () => { | ||
await pages.buttonPage.buttonByPartialText.click({ timeout: 1000 }); | ||
await expect(pages.buttonPage.buttonByPartialText).toHaveClass( | ||
/btn-success/, | ||
); | ||
}); | ||
|
||
test.skip("button data-qa should be clicked", async () => { | ||
await pages.buttonPage.buttonByDataQA.click({ timeout: 1000 }); | ||
await expect(pages.buttonPage.buttonByDataQA).toHaveClass(/btn-success/); | ||
}); | ||
|
||
test.skip("button outside div should be clicked", async () => { | ||
await pages.buttonPage.buttonOutsideDiv.click({ timeout: 1000 }); | ||
await expect(pages.buttonPage.buttonOutsideDiv).toHaveClass(/btn-success/); | ||
}); | ||
}); |
Oops, something went wrong.