A the Dev
A the Dev

Reputation: 11

Playwright config file not using all of the values set

My Playwright config file doesn't appear to be used properly. When I run my test command, I make sure to point to my config file (named: playwright.config.ts, using --config) and the terminal verifies that this file is being used.

However, the only the retries setting appears to work. Timeouts setting changes are not applied and screenshots are not generated after tests whether its set to "on" or "only-on-failure". A folder is not generated without the outputDir set either.

TypeScript has not made any error on my config file so I can't tell whats wrong. The config file is located in the same folder as my tests, it is not at the root.

I moved the file outside to the root and had the same issue.


import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  testDir: 'tests', //is recognized
  timeout: 45000,
  retries: 1, //is recognized
  outputDir: './screenshots',
  use: {
    headless: false,
    viewport: { width: 1440, height: 800 },
    screenshot: 'only-on-failure',
  },
};

export default config;

Here are the docs for reference: https://playwright.dev/docs/test-configuration/

Upvotes: 1

Views: 5928

Answers (1)

Gornostalev
Gornostalev

Reputation: 11

me too faced with this problem, my mistake was in using test method:

import { firefox } from 'playwright';
import { test } from '@playwright/test';

    test('test not using configuration', async () => {
        var browser = await firefox.launch()
        var context = await browser.newContext()
        var page = await browser.newPage()
         
        await page.goto("http://ya.ru")
        page.waitForLoadState()
        var input = await page.waitForSelector('#text');
        (await input).click
        await page.keyboard.type('test text', {delay: 100})
        console.log(await page.video()?.path())
    })

that code not using configuration because there was initialize new browser with default parameters.

that example of code with using configuration:

test('test using configuration', async ({ page }) => {
    await page.goto("http://ya.ru")
    page.waitForLoadState()
    var input = await page.waitForSelector('#text');
    (await input).click
    await page.keyboard.type('test text', {delay: 100})
    console.log(await page.video()?.path())
});

that working because we add page argument in test method and he was initialize from config file.That example have on docs

Upvotes: 1

Related Questions