playwright-request-mocker icon indicating copy to clipboard operation
playwright-request-mocker copied to clipboard

Generated mocks.json file doesn't show data

Open ysq123qwe opened this issue 3 years ago • 3 comments

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:

  1. After downloading this project locally, execute the command: npm install playwright-request-mocker -D npm install @playwright/test

  2. After recording the js script with playwright, directly change the file name to the suffix of spec.js

  3. 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);

  4. 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")')

  5. run command in terminal : set PWDEBUG=console npx playwright test ./src/test02Mock.spec.js

  6. 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.

  7. 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":[]}

  8. I manipulate the contents of the spec.js file in the browser, and the F12 developer mode displays multiple pieces of HAR data normally.

  9. 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 avatar May 06 '22 11:05 ysq123qwe

@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);

unlikelyzero avatar May 16 '22 14:05 unlikelyzero

@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.

ysq123qwe avatar May 16 '22 14:05 ysq123qwe

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: @.***>

ysq123qwe avatar Oct 11 '22 07:10 ysq123qwe