kousenlsn / playwright-request-mocker

Automatically generate and use network request mocks inside Playwright.
https://www.npmjs.com/package/playwright-request-mocker
MIT License
35 stars 7 forks source link

Error: "deviceScaleFactor" option is not supported with null "viewport" #14

Open HoikanChan opened 8 months ago

HoikanChan commented 8 months ago

Awesome project completely fit my situation.

But can't work following the example

  // else use it here if each test scenario expects different results.
   test('scenario1', async ({ page, context }) => {
    // It'll generate a new file if it does not exist (".spec.scenario1.mocks.json")
    // then it'll read it and mock all defined network requests.
    await useNetworkRecordMocks(page, {
      identifier: 'scenario1',
      recordRoute: `${process.env.BASE_URL}/${BACKUP_PAGES.backConfig}`
    });

    // ...my test...
  });

The error output:

Mocks file not found for scenario1, recording a new one!
  1) [chromium] › backup\config.spec.ts:39:8 › 备份服务器 › scenario1 ───────────────────────────────────

    Error: "deviceScaleFactor" option is not supported with null "viewport"
    =========================== logs ===========================
    <launching> C:\Program Files\Google\Chrome\Application\chrome.exe --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=C:\Users\C00607~1\AppData\Local\Temp/chrome-user-data-dir --remote-debugging-pipe about:blank
    <launched> pid=31440
    ============================================================

  1 failed
    [chromium] › backup\config.spec.ts:39:8 › 备份服务器 › scenario1

Any idea about what happened? Thanks :D

HoikanChan commented 8 months ago

my playwright config :

export default defineConfig({
  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. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* 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',
  /* 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: process.env.BASE_URL,
    headless: false,
    /* 忽略HTTPS认证问题 */
    ignoreHTTPSErrors: true,
    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'on-first-retry',
    launchOptions: {
      headless: false,
      executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
    },
  },

  /* Configure projects for major browsers */
  projects: [
    {
      name: 'setup',
      testMatch: '**/*.setup.ts',
    },
    {
      name: 'chromium',
      dependencies: ['setup'],
      use: {
        ...devices['Desktop Chrome'],
        // Use prepared auth state.
        storageState: authFile,
      },
    },
  ],
});