Rayrun

What is the 'slowMo' option in Playwright and how can it be used to simulate a slow network connection?

Answer

Simulating Slow Network with Playwright

You can simulate a slow network connection in Playwright using the slowMo option. This option slows down Playwright operations by the specified amount of milliseconds. It's a great way to see what's happening during test execution.

By default, slowMo is set to 0, meaning no delay between operations. But you can set it to a higher value to mimic a slower network. For instance, setting slowMo to 150 or 200 milliseconds can simulate a slow 3G connection.

Here's how you can use the slowMo option:

import { chromium } from 'playwright';

async function simulateSlow3G() {
  const browser = await chromium.launch();
  const context = await browser.newContext({
    slowMo: 150,
  });
  
  const page = await context.newPage();
  
  await browser.close();
}

simulateSlow3G();

In this example, we've created a new context with slowMo set to 150 milliseconds. This introduces a delay of that duration between each operation on the page.

Remember, simulating network conditions can vary based on server response times and actual network conditions. For more tips on efficient Playwright test scripts, check out this blog post.

References

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Discord Threads

Related Questions

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.