Rayrun
← Back to Discord Forum

Execution speed per test?

Hi,

in my test automation framework using playwright_sync api, currently the slow_mo parameter is read from a config.yaml and all tests except one are running fine with a value of 0. There is only one scrolling test that fails with the following error message:

E playwright._impl._api_types.Error: Element is not attached to the DOM E =========================== logs =========================== E waiting for element to be and stable E element is and stable E ============================================================

If I set the slow_mo e.g. to 50ms, it already passes. However, I would leave it at 0 and would like to slow down the execution at this test only.

  • I tried to start the test with a custom browser/context where I specified a higher slow_mo value, but that didn't work.
  • I also tried self.page.wait_for_load_state("domcontentloaded"), but it only works for frames ?

This is the body of the test (in a Page object based TAF), it tests the movement of the scrollbar:

def test_exercise_scroll_on_left_column_items(self): self.shipment_test_data.shipment_test_data_creation(json_name="10-accessories") self.rma_page.get_awaiting_items_button(9).scroll_into_view_if_needed() expect(self.rma_page.get_awaiting_items_button(9)).to_be_visible() self.rma_page.get_awaiting_items_button(0).scroll_into_view_if_needed() expect(self.rma_page.get_awaiting_items_button(0)).to_be_visible()

Any idea how to run it slower?

This thread is trying to answer question "How can the execution of a specific test be slowed down in a test automation framework using playwright_sync API while keeping the slow_mo parameter at 0 for all other tests?"

0 replies

Answer

Sure, you can slow down a specific test in Playwright without affecting the rest. Here's how you can do it using test.step and test.setTimeout.

First, use test.step to break down your test into multiple steps. This allows you to control the execution speed of each step individually. For instance, you can introduce delays using page.waitForTimeout within a test.step block.

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

test('slow down specific test', async ({ page }) => {
  await page.goto('https://ray.run');

  await test.step('Perform action slowly', async () => {
    await page.click('#button1');
    await page.waitForTimeout(1000);
    await page.fill('#input1', 'Hello');
  });
});

Next, use test.setTimeout to increase the timeout for the entire test. This ensures that the slow-downed step has enough time to complete without causing a timeout error.

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

const SLOW_DOWN_THRESHOLD = 5000;

test.setTimeout(SLOW_DOWN_THRESHOLD + 10000);

test('slow down specific test', async ({ page }) => {
  await page.goto('https://ray.run');

  await test.step('Perform action slowly', async () => {
    await page.click('#button1');
    await page.waitForTimeout(1000);
    await page.fill('#input1', 'Hello');
  });
});

By combining test.step and test.setTimeout, you can effectively slow down a specific test while keeping the slow_mo parameter at 0 for all other tests. Adjust the SLOW_DOWN_THRESHOLD value as per your needs.

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 [email protected].