playwright-request-mocker
playwright-request-mocker copied to clipboard
Generated mocks.json file doesn't show data
The mocks.js file I generated according to the content of the readme file has no requests data. I have tried many methods to solve this problem. If anyone knows the solution, please help to reply. Thank you very much for your help!
The following is my specific operation:
-
After downloading this project locally, execute the command:
npm install playwright-request-mocker -Dnpm install @playwright/test -
After recording the js script with playwright, directly change the file name to the suffix of spec.js
-
Add content to the file, as shown below: //file: test02Mock.spec.js
const { test, expect } = require('@playwright/test'); const { useNetworkRecordMocks } = require('playwright-request-mocker'); test('test02Mock', async ({ page }) => { const requests = await useNetworkRecordMocks(page, { identifier: 'test02Mock', recordRoute: "my_login_test_url" }); await page.goto(my_login_test_url); -
The rest of this file is the page operation of the web UI, such as adding data after logging in. eg:
await page.click('[placeholder="account"]'); await page.fill('[placeholder="account"]', '2000M000'); await page.click('[placeholder="passwd"]'); await page.fill('[placeholder="passwd"]', '123456'); await page.click('button:has-text("login")') -
run command in terminal :
set PWDEBUG=consolenpx playwright test ./src/test02Mock.spec.js -
At this point, the playwright inspector window will open, manually execute it according to the operation of spec.js, and then click resume in the inspector window.
-
The .mocks.json file is displayed in the same directory for a period of time, and only one line is displayed when opening this file:
{"requests":[]} -
I manipulate the contents of the spec.js file in the browser, and the F12 developer mode displays multiple pieces of HAR data normally.
-
So, I don't know why the auto-generated mocks.js has no data. If anyone who knows can let me know, I would be very grateful!
@ysq123qwe i'm also experiencing the same issue. Which playwright/test version are you using?
Have you tried disabling the service worker?
await page.addInitScript(() => delete window.navigator.serviceWorker);
@ysq123qwe i'm also experiencing the same issue. Which playwright/test version are you using?
Have you tried disabling the service worker?
await page.addInitScript(() => delete window.navigator.serviceWorker);
I am using version 1.21. And i didn't disable the service worker.
Hi,I am using version 1.21. And i didn't disable the service worker.
------------------ 原始邮件 ------------------ 发件人: "kousenlsn/playwright-request-mocker" @.>; 发送时间: 2022年5月16日(星期一) 晚上10:03 @.>; @.@.>; 主题: Re: [kousenlsn/playwright-request-mocker] Generated mocks.json file doesn't show data (Issue #13)
@ysq123qwe i'm also experiencing the same issue. Which playwright/test version are you using?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>