Playwright Configuration File

This article will try to understand this configuration file in playwright.

  • So, first of all, when you create a new project, the automatic configuration file will come for you by default.
  • So you need not create everything from scratch. You can do that as well.
  • But initially, for you to get speed on this, we will use that default configuration file that is created.

So there are many things here to go over, and it won't make sense to discuss everything now because you need to understand many things to see what this configuration file provides?.

// @ts-check
const { devices } = require('@playwright/test');

/**
 * Read environment variables from the file.
 * https://github.com/motdotla/dotenv
 */
// require('dotenv').config();


/**
 * @see https://playwright.dev/docs/test-configuration
 * @type {import('@playwright/test').PlaywrightTestConfig}
 */
const config = {
  testDir: './tests',
  /* Maximum time one test can run for. */
  timeout: 30 * 1000,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: 5000
  },
  /* 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: {

    browserName: "chromium",

  }
};

module.exports = config;
  • For now, we will focus on what the browser is and the timeout, and there are some properties that we can go over later from time to time when we are revealing some topics. Then we will come back and see what all these properties do here.
  • So in this article, we will discuss what the config object holds in.
  • So in this config object, if you see where does this object, and this ends at the end. So that means what all you give inside comes under that config object.
  • So let's see, what are the different properties we have in this config object?
const config = {
  testDir: './tests',
  • First of all, we have a test directory property prescribed with the tests project directory where all the tests are present, and when we want to run things, it will be run from this testdir property.
  • You have to run this config file only, and this config file will eventually trigger all these.
 /* Maximum time one test can run for. */
  timeout: 30 * 1000,
  • Next maximum timeout that one test can wait for. So 30 seconds if you still do not hear anything from the test.
  • If the test is not responding for more than 30 seconds, it will report as a failure.
  • That's the timeout property up to how much time a test should wait before reporting failure.
 expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: 5000
  },
  • The expect is an assertion in playwright where the timeout prescribed here is the amount of time each test step waits for and fails after the given time.
reporter: 'html',
  • Reporter: How do you want to report your test against the results so you can report in history? And by default, it is HTML.
  • We can also use any other reporter formats according to our ease.
 use: {

    browserName: "chromium",

  }
  • We can mention the desired browser names we want to run within this using property. In this case, it is chromium.
  • If we prefer WebKit or firefox, it is also mentionable here.

Conclusion:

So these are some of the basic understanding we need about the playwright configuration file, and there is much to be known about the file, which is far complicated and will be converted into topics.

Mon, 06/06/2022 - 11:22

Authored by

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.
Tags