-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update README.md fix: disable clock tests enable clock tests
- Loading branch information
Showing
8 changed files
with
80 additions
and
78 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# FluentCI CI demo for Playwright 🎭 | ||
|
||
[![ci](https://github.com/fluentci-demos/fluentci-demo-buck/actions/workflows/ci.yml/badge.svg)](https://github.com/fluentci-demos/fluentci-demo-buck/actions/workflows/ci.yml) | ||
[![ci](https://github.com/fluentci-demos/fluentci-demo-playwright/actions/workflows/ci.yml/badge.svg)](https://github.com/fluentci-demos/fluentci-demo-playwright/actions/workflows/ci.yml) | ||
|
||
This repo is used to demonstrate various testing scenarios with [Playwright](https://playwright.dev/) 🎭 with Node.js using FluentCI. |
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
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
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 |
---|---|---|
@@ -1,73 +1,70 @@ | ||
import { test, expect, type Page } from '@playwright/test'; | ||
import { test, expect, type Page } from "@playwright/test"; | ||
|
||
test.describe('Mocking an API call', () => { | ||
|
||
test('mocks a fruit and does not call api', async ({ page }) => { | ||
test.describe("Mocking an API call", () => { | ||
test("mocks a fruit and does not call api", async ({ page }) => { | ||
// Mock the api call before navigating | ||
await page.route('*/**/api/v1/fruits', async (route) => { | ||
const json = [{ name: 'Strawberry', id: 21 }]; | ||
await page.route("*/**/api/v1/fruits", async (route) => { | ||
const json = [{ name: "Strawberry", id: 21 }]; | ||
await route.fulfill({ json }); | ||
}); | ||
// Go to the page | ||
await page.goto('https://demo.playwright.dev/api-mocking'); | ||
await page.goto("https://demo.playwright.dev/api-mocking"); | ||
|
||
// Assert that the Strawberry fruit is visible | ||
await expect(page.getByText('Strawberry')).toBeVisible(); | ||
await expect(page.getByText("Strawberry")).toBeVisible(); | ||
}); | ||
|
||
}); | ||
|
||
test.describe('Intercepting the request and modifying it', () => { | ||
|
||
test('gets the json from api and adds a new fruit', async ({ page }) => { | ||
test.describe("Intercepting the request and modifying it", () => { | ||
test("gets the json from api and adds a new fruit", async ({ page }) => { | ||
// Get the response and add to it | ||
await page.route('*/**/api/v1/fruits', async (route) => { | ||
await page.route("*/**/api/v1/fruits", async (route) => { | ||
const response = await route.fetch(); | ||
const json = await response.json(); | ||
json.push({ name: 'Playwright', id: 100 }); | ||
json.push({ name: "Playwright", id: 100 }); | ||
// Fulfill using the original response, while patching the response body | ||
// with the given JSON object. | ||
await route.fulfill({ response, json }); | ||
}); | ||
|
||
// Go to the page | ||
await page.goto('https://demo.playwright.dev/api-mocking'); | ||
await page.goto("https://demo.playwright.dev/api-mocking"); | ||
|
||
// Assert that the new fruit is visible | ||
await expect(page.getByText('Playwright', { exact: true })).toBeVisible(); | ||
await expect(page.getByText("Playwright", { exact: true })).toBeVisible(); | ||
}); | ||
|
||
}); | ||
|
||
test.describe('Mocking with HAR files', () => { | ||
|
||
test('records or updates the HAR file', async ({ page }) => { | ||
test.describe("Mocking with HAR files", () => { | ||
test("records or updates the HAR file", async ({ page }) => { | ||
// Get the response from the HAR file | ||
await page.routeFromHAR('./hars/fruits.har', { | ||
url: '*/**/api/v1/fruits', | ||
await page.routeFromHAR("./hars/fruits.har", { | ||
url: "*/**/api/v1/fruits", | ||
update: true, | ||
}); | ||
|
||
// Go to the page | ||
await page.goto('https://demo.playwright.dev/api-mocking'); | ||
await page.goto("https://demo.playwright.dev/api-mocking"); | ||
|
||
// Assert that the Playwright fruit is visible | ||
await expect(page.getByText('Strawberry')).toBeVisible(); | ||
await expect(page.getByText("Strawberry")).toBeVisible(); | ||
}); | ||
|
||
test('gets the json from HAR and checks the new fruit has been added', async ({ page }) => { | ||
test("gets the json from HAR and checks the new fruit has been added", async ({ | ||
page, | ||
}) => { | ||
// Replay API requests from HAR. | ||
// Either use a matching response from the HAR, | ||
// or abort the request if nothing matches. | ||
await page.routeFromHAR('./hars/fruits.har', { | ||
url: '*/**/api/v1/fruits', | ||
await page.routeFromHAR("./hars/fruits.har", { | ||
url: "*/**/api/v1/fruits", | ||
update: false, | ||
}); | ||
|
||
// Go to the page | ||
await page.goto('https://demo.playwright.dev/api-mocking'); | ||
await page.goto("https://demo.playwright.dev/api-mocking"); | ||
|
||
// Assert that the Playwright fruit is visible | ||
await expect(page.getByText('Strawberry')).toBeVisible(); | ||
await expect(page.getByText("Strawberry")).toBeVisible(); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.