Skip to content

Commit

Permalink
fix: disable boxed-steps tests
Browse files Browse the repository at this point in the history
update README.md

fix: disable clock tests

enable clock tests
  • Loading branch information
tsirysndr committed Aug 22, 2024
1 parent aa4f75c commit 5f033c7
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 78 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ jobs:
fluentci run --wasm playwright test -j $(nproc)
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CI: true
2 changes: 1 addition & 1 deletion README.md
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.
80 changes: 41 additions & 39 deletions hars/fruits.har
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,68 @@
"version": "1.2",
"creator": {
"name": "Playwright",
"version": "1.35.1"
"version": "1.45.0"
},
"browser": {
"name": "chromium",
"version": "115.0.5790.24"
"name": "webkit",
"version": "17.4"
},
"entries": [
{
"startedDateTime": "2023-07-03T18:00:20.971Z",
"time": 0.903,
"startedDateTime": "2024-08-22T09:01:02.636Z",
"time": 1.186,
"request": {
"method": "GET",
"url": "https://demo.playwright.dev/api-mocking/api/v1/fruits",
"httpVersion": "HTTP/2.0",
"cookies": [],
"headers": [
{ "name": ":authority", "value": "demo.playwright.dev" },
{ "name": ":method", "value": "GET" },
{ "name": ":path", "value": "/api-mocking/api/v1/fruits" },
{ "name": ":scheme", "value": "https" },
{ "name": "accept", "value": "*/*" },
{ "name": "accept-encoding", "value": "gzip, deflate, br" },
{ "name": "accept-language", "value": "en-US" },
{ "name": "cache-control", "value": "max-age=0" },
{ "name": "referer", "value": "https://demo.playwright.dev/api-mocking/" },
{ "name": "sec-fetch-dest", "value": "empty" },
{ "name": "sec-fetch-mode", "value": "cors" },
{ "name": "sec-fetch-site", "value": "same-origin" },
{ "name": "user-agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.5790.24 Safari/537.36" }
{ "name": "Referer", "value": "https://demo.playwright.dev/api-mocking/" },
{ "name": "Accept", "value": "*/*" },
{ "name": "User-Agent", "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15" },
{ "name": "Cache-Control", "value": "max-age=0" },
{ "name": "Accept-Language", "value": "en-US" },
{ "name": "Accept-Encoding", "value": "gzip, deflate, br" },
{ "name": "Sec-Fetch-Dest", "value": "empty" },
{ "name": "Sec-Fetch-Mode", "value": "cors" },
{ "name": "Sec-Fetch-Site", "value": "same-origin" },
{ "name": "Host", "value": "demo.playwright.dev" }
],
"queryString": [],
"headersSize": -1,
"bodySize": -1
},
"response": {
"status": 200,
"statusText": "",
"statusText": "OK",
"httpVersion": "HTTP/2.0",
"cookies": [],
"headers": [
{ "name": "accept-ranges", "value": "bytes" },
{ "name": "access-control-allow-origin", "value": "*" },
{ "name": "age", "value": "0" },
{ "name": "cache-control", "value": "max-age=600" },
{ "name": "content-length", "value": "762" },
{ "name": "content-type", "value": "application/octet-stream" },
{ "name": "date", "value": "Mon, 03 Jul 2023 18:00:21 GMT" },
{ "name": "etag", "value": "\"6495697c-2fa\"" },
{ "name": "expires", "value": "Mon, 03 Jul 2023 18:10:21 GMT" },
{ "name": "last-modified", "value": "Fri, 23 Jun 2023 09:44:28 GMT" },
{ "name": "server", "value": "GitHub.com" },
{ "name": "vary", "value": "Accept-Encoding" },
{ "name": "via", "value": "1.1 varnish" },
{ "name": "x-cache", "value": "MISS" },
{ "name": "x-cache-hits", "value": "0" },
{ "name": "x-fastly-request-id", "value": "d56d393516eeca913cb814d35726d5c0a7a84e52" },
{ "name": "x-github-request-id", "value": "C544:114C7:2BA884C:2D0CD20:64A30CB3" },
{ "name": "Content-Type", "value": "application/octet-stream" },
{ "name": "Last-Modified", "value": "Fri" },
{ "name": "Last-Modified", "value": "28 Jun 2024 15:36:42 GMT" },
{ "name": "Access-Control-Allow-Origin", "value": "*" },
{ "name": "ETag", "value": "\"667ed88a-2fa\"" },
{ "name": "Expires", "value": "Thu" },
{ "name": "Expires", "value": "22 Aug 2024 09:03:56 GMT" },
{ "name": "Cache-Control", "value": "max-age=600" },
{ "name": "Accept-Ranges", "value": "bytes" },
{ "name": "Date", "value": "Thu" },
{ "name": "Date", "value": "22 Aug 2024 09:01:02 GMT" },
{ "name": "Via", "value": "1.1 varnish" },
{ "name": "Age", "value": "255" },
{ "name": "Vary", "value": "Accept-Encoding" },
{ "name": "Content-Length", "value": "762" },
{ "name": "Server", "value": "GitHub.com" },
{ "name": "x-proxy-cache", "value": "MISS" },
{ "name": "x-served-by", "value": "cache-mad2200145-MAD" },
{ "name": "x-timer", "value": "S1688407221.077434,VS0,VE135" }
{ "name": "x-github-request-id", "value": "44AB:36FCBA:34E054A:35EDDA3:66C6FCA4" },
{ "name": "x-served-by", "value": "cache-fra-eddf8230150-FRA" },
{ "name": "x-cache", "value": "HIT" },
{ "name": "x-cache-hits", "value": "1" },
{ "name": "x-timer", "value": "S1724317263.632686" },
{ "name": "x-timer", "value": "VS0" },
{ "name": "x-timer", "value": "VE4" },
{ "name": "x-fastly-request-id", "value": "2893cb9441212c5a4e789b244233b0c9c4baa164" }
],
"content": {
"size": -1,
Expand All @@ -74,7 +76,7 @@
"redirectURL": ""
},
"cache": {},
"timings": { "send": -1, "wait": -1, "receive": 0.903 }
"timings": { "send": -1, "wait": -1, "receive": 1.186 }
}
]
}
Expand Down
18 changes: 10 additions & 8 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, devices } from '@playwright/test';
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
Expand All @@ -10,7 +10,7 @@ import { defineConfig, devices } from '@playwright/test';
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
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. */
Expand All @@ -20,32 +20,34 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
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: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},

/*
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
*/

/* Test against mobile viewports. */
// {
Expand Down
57 changes: 27 additions & 30 deletions tests/api-mocking/api-mocking.spec.ts
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.

0 comments on commit 5f033c7

Please sign in to comment.