Rayrun

How do I run browsers in headless mode using Playwright?

Answer

Running Browsers in Headless Mode with Playwright

You might want to run your tests in a headless browser, meaning without any visible UI. Good news! Playwright does this by default. But if you want to see the UI while running tests, you can disable headless mode. Here's how:

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

const browser = await chromium.launch({ headless: false });

You can also slow down the execution to debug your code. Just add slowMo option when launching your browser:

const browser = await chromium.launch({ slowMo: 50 });

Remember, these options are browser-specific. If you want to enable or disable headless mode for a specific browser, specify it when launching:

const browser = await chromium.launch({ headless: true });

Playwright makes it easy to customize your testing environment. For more tips, check out Mastering Playwright Test Automation: Your Comprehensive Cheat Sheet.

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 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.