Skip to content

Commit

Permalink
playwright test improvement (#155)
Browse files Browse the repository at this point in the history
* upgrade playwright

* fix lint

* integrate test report

* add selector id

* implement page-object-model & add more test
  • Loading branch information
depapp committed Feb 24, 2023
1 parent 083c168 commit 934d185
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.idea
.idea
playwright-report
test-results
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ Untuk menambahkan data developer silakan ubah file `src/data/people.js`. Data so
```

dan untuk menambahkan data perusahaan yang masih melakukan hiring silakan ubah file `src/data/employer.js`.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"postinstall": "husky install"
},
"devDependencies": {
"@playwright/test": "^1.28.1",
"@playwright/test": "^1.30.0",
"@sveltejs/adapter-auto": "^1.0.0",
"@sveltejs/kit": "^1.8.3",
"eslint": "^8.28.0",
Expand Down
4 changes: 4 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const config = {
port: 4173,
},
testDir: "tests",
reporter: "html",
use: {
trace: "retain-on-failure",
},
};

export default config;
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<Nav />
<slot />
<hr />
Dipersembahkan oleh <a
href="https://deeptech.id"
target="_blank"
rel="noreferrer">DeepTech Foundation</a
>. Kode sumber tersedia di <a
Dipersembahkan oleh
<a href="https://deeptech.id" target="_blank" rel="noreferrer"
>DeepTech Foundation</a
>. Kode sumber tersedia di
<a
href="https://github.com/rizafahmi/carikerja"
target="_blank"
rel="noreferrer">GitHub</a
Expand Down
4 changes: 3 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
on:select={handleStackChange}
items={getAllTechStack}
isMulti={true}
id="inputTechStack"
/>
</div>
<div>
Expand All @@ -162,6 +163,7 @@
on:select={handleLocationChange}
on:clear={handleLocationChange}
items={getAllLocation}
id="inputLocation"
/>
</div>
</div>
Expand All @@ -172,7 +174,7 @@
<ul>
<li>⏲️ {p.status}</li>
<li>💻 {p.role}</li>
<li>📍 {p.location}</li>
<li id="listLocation">📍 {p.location}</li>
{#if p.tech_stack.length != 0}
<li>
⚙️
Expand Down
17 changes: 17 additions & 0 deletions tests/home.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {test, expect} from "@playwright/test";
import {HomePage} from "./pages/home.page.js";

test.describe("Cari Kerja Home Page E2E Test", () => {
test.beforeEach(async ({page}) => {
const homePage = new HomePage(page);
await homePage.open();
expect(await page.textContent("h4")).toBe(
"Kata siapa cari software engineer yang berpengalaman itu susah?",
);
});

test("user should be able to filter using location", async ({page}) => {
const homePage = new HomePage(page);
await homePage.filterByLocation("bandung");
});
});
29 changes: 29 additions & 0 deletions tests/pages/home.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {expect} from "@playwright/test";

export class HomePage {
/**
* @param { import('@playwright/test').Page} page
*/

constructor(page) {
this.page = page;
this.inputLocation = page.locator("#inputLocation");
this.listLocation = page.locator("#listLocation");
}

async open() {
await this.page.goto("/");
}

/**
* @param {string} location
*/
async filterByLocation(location) {
await this.inputLocation.click();
await this.inputLocation.fill(location);
await this.page.keyboard.press("Enter");
for (const li of await this.listLocation.all()) {
expect(li).toContainText(location, {ignoreCase: true});
}
}
}
8 changes: 0 additions & 8 deletions tests/test.js

This file was deleted.

0 comments on commit 934d185

Please sign in to comment.