From 05f22d65269688c5ce936020419ea47d032bb832 Mon Sep 17 00:00:00 2001 From: Debbie O'Brien Date: Tue, 2 Jul 2024 11:19:04 +0200 Subject: [PATCH 1/3] update versions --- ...f81554c5a5b00f3cb44f278e58b42af65a2ea6.txt | 257 ++++++++++++++++++ hars/fruit.har | 36 +-- package-lock.json | 40 ++- package.json | 2 +- 4 files changed, 306 insertions(+), 29 deletions(-) create mode 100644 hars/40f81554c5a5b00f3cb44f278e58b42af65a2ea6.txt diff --git a/hars/40f81554c5a5b00f3cb44f278e58b42af65a2ea6.txt b/hars/40f81554c5a5b00f3cb44f278e58b42af65a2ea6.txt new file mode 100644 index 0000000..3000dc0 --- /dev/null +++ b/hars/40f81554c5a5b00f3cb44f278e58b42af65a2ea6.txt @@ -0,0 +1,257 @@ +[ + { + "name": "Strawberry", + "id": 3, + "family": "Rosaceae", + "order": "Rosales", + "genus": "Fragaria", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/La_Trinidad_strawberries.jpg", + "nutritions": { + "calories": 29, + "fat": 0.4, + "sugar": 5.4, + "carbohydrates": 5.5, + "protein": 0.8 + } + }, + { + "name": "Banana", + "id": 1, + "family": "Musaceae", + "order": "Zingiberales", + "genus": "Musa", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Banana.arp.750pix.jpg", + "nutritions": { + "calories": 96, + "fat": 0.2, + "sugar": 17.2, + "carbohydrates": 22, + "protein": 1 + } + }, + { + "name": "Tomato", + "id": 5, + "family": "Solanaceae", + "order": "Solanales", + "genus": "Solanum", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Tomato_with_Tomato_Spotted_Wilt_Virus.jpg", + "nutritions": { + "calories": 74, + "fat": 0.2, + "sugar": 2.6, + "carbohydrates": 3.9, + "protein": 0.9 + } + }, + { + "name": "Pear", + "id": 4, + "family": "Rosaceae", + "order": "Rosales", + "genus": "Pyrus", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/600px-Pears.jpg", + "nutritions": { + "calories": 57, + "fat": 0.1, + "sugar": 10, + "carbohydrates": 15, + "protein": 0.4 + } + }, + { + "name": "Blackberry", + "id": 64, + "family": "Rosaceae", + "order": "Rosales", + "genus": "Rubus", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Blackberries_by_feiern1.jpg", + "nutritions": { + "calories": 40, + "fat": 0.4, + "sugar": 4.5, + "carbohydrates": 9, + "protein": 1.3 + } + }, + { + "name": "Kiwi", + "id": 66, + "family": "Actinidiaceae", + "order": "Struthioniformes", + "genus": "Apteryx", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/602px-Mature_kiwifruit.jpg", + "nutritions": { + "calories": 61, + "fat": 0.5, + "sugar": 9, + "carbohydrates": 15, + "protein": 1.1 + } + }, + { + "name": "Pineapple", + "id": 10, + "family": "Bromeliaceae", + "order": "Poales", + "genus": "Ananas", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Pineapples_Kenya.jpg", + "nutritions": { + "calories": 50, + "fat": 0.12, + "sugar": 9.85, + "carbohydrates": 13.12, + "protein": 0.54 + } + }, + { + "name": "Passionfruit", + "id": 70, + "family": "Passifloraceae", + "order": "Malpighiales", + "genus": "Passiflora", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Passiflora-edulis.jpg", + "nutritions": { + "calories": 97, + "fat": 0.7, + "sugar": 11.2, + "carbohydrates": 22.4, + "protein": 2.2 + } + }, + { + "name": "Orange", + "id": 2, + "family": "Rutaceae", + "order": "Sapindales", + "genus": "Citrus", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Sliced_orange_whitescreen.jpg", + "nutritions": { + "calories": 43, + "fat": 0.2, + "sugar": 8.2, + "carbohydrates": 8.3, + "protein": 1 + } + }, + { + "name": "Raspberry", + "id": 23, + "family": "Rosaceae", + "order": "Rosales", + "genus": "Rubus", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Framboise_Margy_3.jpg", + "nutritions": { + "calories": 53, + "fat": 0.7, + "sugar": 4.4, + "carbohydrates": 12, + "protein": 1.2 + } + }, + { + "name": "Watermelon", + "id": 25, + "family": "Cucurbitaceae", + "order": "Cucurbitales", + "genus": "Citrullus", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Watermelon_-_Fruit_Bazaar_-_near_Besat_sq_-_Nishapur_12.jpg", + "nutritions": { + "calories": 30, + "fat": 0.2, + "sugar": 6, + "carbohydrates": 8, + "protein": 0.6 + } + }, + { + "name": "Lemon", + "id": 26, + "family": "Rutaceae", + "order": "Sapindales", + "genus": "Citrus", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Lemon03.jpg", + "nutritions": { + "calories": 29, + "fat": 0.3, + "sugar": 2.5, + "carbohydrates": 9, + "protein": 1.1 + } + }, + { + "name": "Mango", + "id": 27, + "family": "Anacardiaceae", + "order": "Sapindales", + "genus": "Mangifera", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Mango.jpg", + "nutritions": { + "calories": 60, + "fat": 0.38, + "sugar": 13.7, + "carbohydrates": 15, + "protein": 0.82 + } + }, + { + "name": "Blueberry", + "id": 33, + "family": "Rosaceae", + "order": "Rosales", + "genus": "Fragaria", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Aberdeenshire_blueberries.jpg", + "nutritions": { + "calories": 29, + "fat": 0.4, + "sugar": 5.4, + "carbohydrates": 5.5, + "protein": 0 + } + }, + { + "name": "Apple", + "id": 6, + "family": "Rosaceae", + "order": "Rosales", + "genus": "Malus", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Apples_in_basket.jpg", + "nutritions": { + "calories": 52, + "fat": 0.4, + "sugar": 10.3, + "carbohydrates": 11.4, + "protein": 0.3 + } + }, + { + "name": "Melon", + "id": 41, + "family": "Cucurbitaceae", + "order": "Cucurbitaceae", + "genus": "Cucumis", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Philippines_Cucumis_melo.jpg", + "nutritions": { + "calories": 34, + "fat": 0, + "sugar": 8, + "carbohydrates": 8, + "protein": 0 + } + }, + { + "name": "Lime", + "id": 44, + "family": "Rutaceae", + "order": "Sapindales", + "genus": "Citrus", + "img": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/master/images/Key_lime.jpg", + "nutritions": { + "calories": 25, + "fat": 0.1, + "sugar": 1.7, + "carbohydrates": 8.4, + "protein": 0.3 + } + } +] diff --git a/hars/fruit.har b/hars/fruit.har index 649a2bf..555c543 100644 --- a/hars/fruit.har +++ b/hars/fruit.har @@ -3,16 +3,16 @@ "version": "1.2", "creator": { "name": "Playwright", - "version": "1.35.0" + "version": "1.46.0-alpha-2024-06-21" }, "browser": { "name": "chromium", - "version": "115.0.5790.24" + "version": "127.0.6533.5" }, "entries": [ { - "startedDateTime": "2023-06-16T10:35:43.794Z", - "time": 0.79, + "startedDateTime": "2024-07-02T09:02:33.046Z", + "time": 0.746, "request": { "method": "GET", "url": "https://raw.githubusercontent.com/debs-obrien/playwright-api-mocking/main/fruit.json", @@ -24,15 +24,19 @@ { "name": ":path", "value": "/debs-obrien/playwright-api-mocking/main/fruit.json" }, { "name": ":scheme", "value": "https" }, { "name": "accept", "value": "*/*" }, - { "name": "accept-encoding", "value": "gzip, deflate, br" }, + { "name": "accept-encoding", "value": "gzip, deflate, br, zstd" }, { "name": "accept-language", "value": "en-US" }, { "name": "cache-control", "value": "max-age=0" }, { "name": "origin", "value": "https://debs-obrien.github.io" }, + { "name": "priority", "value": "u=1, i" }, { "name": "referer", "value": "https://debs-obrien.github.io/" }, + { "name": "sec-ch-ua", "value": "\"Not)A;Brand\";v=\"99\", \"HeadlessChrome\";v=\"127\", \"Chromium\";v=\"127\"" }, + { "name": "sec-ch-ua-mobile", "value": "?0" }, + { "name": "sec-ch-ua-platform", "value": "\"Windows\"" }, { "name": "sec-fetch-dest", "value": "empty" }, { "name": "sec-fetch-mode", "value": "cors" }, { "name": "sec-fetch-site", "value": "cross-site" }, - { "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": "user-agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.5 Safari/537.36" } ], "queryString": [], "headersSize": -1, @@ -48,25 +52,25 @@ { "name": "access-control-allow-origin", "value": "*" }, { "name": "cache-control", "value": "max-age=300" }, { "name": "content-encoding", "value": "gzip" }, - { "name": "content-length", "value": "1091" }, + { "name": "content-length", "value": "1090" }, { "name": "content-security-policy", "value": "default-src 'none'; style-src 'unsafe-inline'; sandbox" }, { "name": "content-type", "value": "text/plain; charset=utf-8" }, { "name": "cross-origin-resource-policy", "value": "cross-origin" }, - { "name": "date", "value": "Fri, 16 Jun 2023 10:35:44 GMT" }, - { "name": "etag", "value": "W/\"d83122217d5366eba6451e64914440897d4e492590dcf4d6c626858144e5d054\"" }, - { "name": "expires", "value": "Fri, 16 Jun 2023 10:40:44 GMT" }, - { "name": "source-age", "value": "0" }, + { "name": "date", "value": "Tue, 02 Jul 2024 09:02:33 GMT" }, + { "name": "etag", "value": "W/\"d5d2456f2ad3733a866ca3b6f855d2fd2896776093c13577a4b74118698bb92c\"" }, + { "name": "expires", "value": "Tue, 02 Jul 2024 09:07:33 GMT" }, + { "name": "source-age", "value": "130" }, { "name": "strict-transport-security", "value": "max-age=31536000" }, { "name": "vary", "value": "Authorization,Accept-Encoding,Origin" }, { "name": "via", "value": "1.1 varnish" }, { "name": "x-cache", "value": "HIT" }, { "name": "x-cache-hits", "value": "1" }, { "name": "x-content-type-options", "value": "nosniff" }, - { "name": "x-fastly-request-id", "value": "af19e7d1a076de1b652b3bc6e5ee221ac7a195f4" }, + { "name": "x-fastly-request-id", "value": "47e2b25e9854fbe3e1d630424e76c2d33a56db29" }, { "name": "x-frame-options", "value": "deny" }, - { "name": "x-github-request-id", "value": "5AD2:E557:7660A4:7B5B76:648C36D2" }, - { "name": "x-served-by", "value": "cache-mad22078-MAD" }, - { "name": "x-timer", "value": "S1686911744.902050,VS0,VE179" }, + { "name": "x-github-request-id", "value": "79BA:0E41:43B46B:47ED27:6683C1A7" }, + { "name": "x-served-by", "value": "cache-mad2200094-MAD" }, + { "name": "x-timer", "value": "S1719910953.206159,VS0,VE1" }, { "name": "x-xss-protection", "value": "1; mode=block" } ], "content": { @@ -79,7 +83,7 @@ "redirectURL": "" }, "cache": {}, - "timings": { "send": -1, "wait": -1, "receive": 0.79 } + "timings": { "send": -1, "wait": -1, "receive": 0.746 } } ] } diff --git a/package-lock.json b/package-lock.json index aa23799..cae3153 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@playwright/test": "^1.35.0", + "@playwright/test": "^1.46.0-alpha-2024-06-21", "@types/react": "^18.0.37", "@types/react-dom": "^18.0.11", "@typescript-eslint/eslint-plugin": "^5.59.0", @@ -949,19 +949,33 @@ } }, "node_modules/@playwright/test": { - "version": "1.35.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.35.0.tgz", - "integrity": "sha512-6qXdd5edCBynOwsz1YcNfgX8tNWeuS9fxy5o59D0rvHXxRtjXRebB4gE4vFVfEMXl/z8zTnAzfOs7aQDEs8G4Q==", + "version": "1.46.0-alpha-2024-06-21", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.46.0-alpha-2024-06-21.tgz", + "integrity": "sha512-OIZFlodetQZQ8NLmm+deXcwZkIc/uqi+T6I3CFtaD0qZ4hKfSjkLzdX4LUOWkX+WWC3vZogFExcUb+HdnCdWYg==", "dev": true, "dependencies": { - "@types/node": "*", - "playwright-core": "1.35.0" + "playwright": "1.46.0-alpha-2024-06-21" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" + } + }, + "node_modules/@playwright/test/node_modules/playwright": { + "version": "1.46.0-alpha-2024-06-21", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.46.0-alpha-2024-06-21.tgz", + "integrity": "sha512-6S9Qbdsd4WkJgSRxK+YAqMgWeI3Y8wtEEifq4lSSo2Fp00v61G0OKJC/MBfFvkfdeSLPwEqju6Fk3gFiJoH3bQ==", + "dev": true, + "dependencies": { + "playwright-core": "1.46.0-alpha-2024-06-21" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" }, "optionalDependencies": { "fsevents": "2.3.2" @@ -977,7 +991,9 @@ "version": "20.2.5", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.2.5.tgz", "integrity": "sha512-JJulVEQXmiY9Px5axXHeYGLSjhkZEnD+MDPDGbCbIAbMslkKwmygtZFy1X6s/075Yo94sf8GuSlFfPzysQrWZQ==", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "node_modules/@types/prop-types": { "version": "15.7.5", @@ -3056,15 +3072,15 @@ "link": true }, "node_modules/playwright-core": { - "version": "1.35.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.35.0.tgz", - "integrity": "sha512-muMXyPmIx/2DPrCHOD1H1ePT01o7OdKxKj2ebmCAYvqhUy+Y1bpal7B0rdoxros7YrXI294JT/DWw2LqyiqTPA==", + "version": "1.46.0-alpha-2024-06-21", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.46.0-alpha-2024-06-21.tgz", + "integrity": "sha512-8IroNFoLw2ektgT4C5QyoAakoS0XbWSreiHz4Y0IyX6efG5jPeMQCg3O+XpvKsV1qm0jaWa64PRrk/rV32v8aw==", "dev": true, "bin": { "playwright-core": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/postcss": { diff --git a/package.json b/package.json index a907df6..ad29e4b 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@playwright/test": "^1.35.0", + "@playwright/test": "^1.46.0-alpha-2024-06-21", "@types/react": "^18.0.37", "@types/react-dom": "^18.0.11", "@typescript-eslint/eslint-plugin": "^5.59.0", From 57d226a26a1e9d9d3510d8ce714351e0e58e2a57 Mon Sep 17 00:00:00 2001 From: Debbie O'Brien Date: Tue, 9 Jul 2024 10:59:11 +0200 Subject: [PATCH 2/3] add test for monitoring requests --- tests/api-mocking.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/api-mocking.spec.ts b/tests/api-mocking.spec.ts index 3c89501..db1bf26 100644 --- a/tests/api-mocking.spec.ts +++ b/tests/api-mocking.spec.ts @@ -60,8 +60,27 @@ test('gets the json from api and adds a star rating to each fruit', async ({ // Assert that the stars are visible await expect(page.getByRole('img', { name: 'star' })).toBeVisible(); await expect(page.getByText('5', { exact: true })).toBeVisible(); + +}); + +test('monitor all requests and responses', async ({ page }) => { + + page.on('request', request => console.log('>>', request.method(), request.url())); + page.on('response', response => console.log('<<', response.status(), response.url())); + + await page.goto('./'); }); + + + + + + + + + + test('gets the har file from api and runs test against it', async ({ page, }) => { From 631f98481d24424efad31bb4b75facb6ef9bfa34 Mon Sep 17 00:00:00 2001 From: Debbie O'Brien Date: Tue, 9 Jul 2024 11:00:35 +0200 Subject: [PATCH 3/3] test --- tests/api-mocking.spec.ts | 43 --------------------------------------- 1 file changed, 43 deletions(-) diff --git a/tests/api-mocking.spec.ts b/tests/api-mocking.spec.ts index db1bf26..98787f1 100644 --- a/tests/api-mocking.spec.ts +++ b/tests/api-mocking.spec.ts @@ -70,46 +70,3 @@ test('monitor all requests and responses', async ({ page }) => { await page.goto('./'); }); - - - - - - - - - - - -test('gets the har file from api and runs test against it', async ({ - page, -}) => { - // Create the HAR file - await page.routeFromHAR('./hars/fruit.har', { - url: '**/*.json', - update: true, - }); - // Go to the page - await page.goto('./'); - - // assert that some text from the card is visible - await expect(page.getByText('Protein')).toBeVisible(); -}); - -test('gets the json from HAR and checks the stars have been added for each fruit', async ({ - page, -}) => { - // Get the response and add to it - await page.routeFromHAR('./hars/fruit.har', { - url: '**/*.json', - update: false, - }); - // Go to the page - await page.goto('./'); - - // wait for the image to load - await page.waitForResponse('**/*.jpg'); - - // Assert that the stars are visible - await expect(page.getByRole('img', { name: 'star' })).toBeVisible(); -});