question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] how do I properly configure with it,jestPlaywrightConfig()..

See original GitHub issue

I’m trying to pass jetPlaywrightConfig in a test, however I don’t seem to get it to work.

This is my test:

import { JestPlaywrightConfig } from 'jest-playwright-preset';

describe('TEST 001', () => {
     const config: JestPlaywrightConfig = { 
                devices: ['iPhone 11'], 
                contextOptions: { locale: 'nl-NL' }, 
                exitOnPageError: true,  // required
                browsers: ['chromium'], // required
                collectCoverage: false, // required
      }

      // without the required I get a property missing error
    
     it.jestPlaywrightConfig(config, 'WITH CONFIG', async () => {
             await page.goto('http://google.com');
             await page.waitForTimeout(10000);
     }
}

Expected: the test launches in a browser sized to iPhone 11 with nl-NL locale. Actual: when I run the test I see a browser open, then a second. Both have the default size. The test is executed inside the first browser.

This is my jest.config.js:

module.exports = {
    verbose: true,
    preset: 'jest-playwright-preset',
    transform: {
        '^.+\\.ts$': 'ts-jest',
    },
    testTimeout: 60000,
    testRunner: 'jasmine2',
    globalSetup: './globalSetup.js',
    setupFilesAfterEnv: [
        "jest-allure/dist/setup"
    ],
    testEnvironmentOptions: {
        'jest-playwright': {
            launchOptions: {
                headless: false
            }
        }
    },
}

When I put the device and locale option inside the jest.config then I see the test run properly in a iPhone 11 sized browser.

Am I missing something in the way I use it.jestPlaywrightConfig()? Thank you.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mmarkelovcommented, Feb 2, 2021

@ychaudhari it should be ok in your case. The only thing that you should use provided page instance, otherwise it will tests global instance:

const headfulConfig = {
  launchOptions: {
    headless: false,
  },
};
describe('Test', () => {
  let landingPage: LandingPage;
  beforeEach(async () => {
    // steps to navigate
  });
  // use page from arguments
  it.jestPlaywrightConfig(headfulConfig, 'that uses headful config', async ({ page }) => {
    // test steps and assertion
  });
});

Also you can try to use jestPlaywrightDebug method. It will run your test with this params:

launchOptions: {
    headless: false,
    devtools: true,
},

it.jestPlaywrightDebug('that uses debug config', async ({ page }) => {
    // test steps and assertion
});
0reactions
ychaudharicommented, Feb 2, 2021

@mmarkelov Is it possible to use a different launchOption with this method? I’m using playwright 1.8.0. I want to run a particular test in headful mode but rest of the suite in headless mode, I tried following

const headfulConfig = {
  launchOptions: {
    headless: false,
  },
};
describe('Test', () => {
  let landingPage: LandingPage;
  beforeEach(async () => {
    // steps to navigate
  });
  it.jestPlaywrightConfig(headfulConfig, 'that uses headful config', async () => {
    // test steps and assertion
  });
});

However, test still picks up headless config from jest.config.ts file and runs the test in headless mode

import type { Config } from '@jest/types';
export default async (): Promise<Config.InitialOptions> => {
  return {
    verbose: true,
    testEnvironmentOptions: {
      'jest-playwright': {
        browsers: ['chromium'],
        launchOptions: {
          headless: true,
        },
      },
    },
  };
};

Is it possible to have a different launchOption with this method? or is the browser already lauched by the time it reaches to the test (i.e. ‘it’) also, is there a way to apply separate config to describe/beforeEach blocks?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest & Playwright Preset Configuration | Playwright - Part 18
Very important concept! Please watchfully.In this video. we are going to config the jest & playwright preset.It will help us to integrate ...
Read more >
Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >
First steps with end-to-end testing using jest + playwright ...
We will create a base repository with Playwright and JestJS and write a basic test which will: Load the blog page,; Check if...
Read more >
Answers to All The Top Questions For Playwright Testing
All the top answers to your favorite questions on the hottest new testing framework from Microsoft, Playwright.
Read more >
Using Jest with Playwright
The way how you should integrate Playwright into your project depends on your needs. Currently there two common ways of doing that. Either...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found