Rayrun
← Back to Discord Forum

Possible to do slowMo for just a single test?

The test code below only passes when I do slowMo=1000 in headless. I know I am not supposed to use slowMo, but I am going by all the recommendations by playwright and it still only passes with slowMo. Is there a way to do just slowMo for a single test so I do not have to slow down the whole test suite?

Note: I am using mock data, not live data, so there is no lag in that respect.

it('should update max value in input box from slide adjustment and save', async({ page }) => {
        const responsePromise = page.waitForResponse(apiUrl);
        const targetPosition = { x: 100, y: 10 };
        const el = page.getByText('Match is probable');
        const el0 = page.locator('#mat-input-1');
  
        await page.getByRole('slider').nth(1).dragTo(el, {targetPosition});
        await expect(el0).toHaveAttribute('ng-reflect-model', '75');
  
        const response = await responsePromise;
        expect(response.url()).toContain('3924');
      });

This thread is trying to answer question "Is there a way to apply slowMo to a single test instead of the entire test suite?"

6 replies

If you are using the Playwright Test runner you can do this, along with overwriting the default timeout for your suite.

test("slow test", async ({ page }) => {
    test.slow();
    test.setTimeout(120_000);
    page.goto("url")
    ...
  });

thank you, I am using p test runner

it.slow(); isn't really helping. and I am not supposed to use waitForTimeout. Any ideas why?

it.only('should exit when save and exit button is pressed', async ({ page }) => {
        it.slow();
        await page.getByRole('button', { name: 'EDIT' }).click();                     
        await page.getByText('SAVE AND EXIT', { exact: true }).click();               
        expect(page.url()).toContain('http://127.0.0.1:8080/home');                   
      });

Can you link the docs for p test runner, first I’ve heard of this.

https://playwright.dev/docs/api/class-frame#frame-wait-for-timeout

Never wait for timeout in production. Tests that wait for time are inherently flaky. Use Locator actions and web assertions that wait automatically.

I am using locator actions and web assertions that wait. And it's what I been told on here before from @mxschmitt

I think playwright might have issues with the page transition animations in Angular ... if I was to guess some of these race condition issues? Or maybe just with Angular in general?

Answer

Sure, you can apply slowmo to just one test in Playwright! You can use the test.slow() method to mark a specific test as "slow". This gives it triple the default timeout. Here's how you do it:

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

test('slow test', async ({ page }) => {
  test.slow();
  // Your test code goes here
});

By using test.slow() in your test function, it gets more time to complete before timing out. But remember, you can't use test.slow() in a beforeAll or afterAll hook.

If you want to apply slowmo to all tests in a file or a test.describe() group, you can use the conditional version of test.slow(). Here's how:

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

test.slow(({ browserName }) => browserName === 'webkit');

test('slow in WebKit 1', async ({ page }) => {
  // Your code goes here
});

test('skip in WebKit 2', async ({ page }) => {
  // Your code goes here
});

In this case, all tests in this file or group will be "slow" if the condition browserName === 'webkit' is true. This lets you apply slowmo to specific tests based on certain conditions. So, with test.slow(), you can mark a specific test as "slow" or apply it conditionally to multiple tests.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.