First, install the Playwright library in your Node.js project. Use npm or Yarn and run npm i -D playwright
. This command downloads the Playwright NPM package and browser binaries for Chromium, Firefox, and WebKit.
import { chromium } from 'playwright';
Next, launch the Chromium browser instance in headless mode.
const browser = await chromium.launch({headless: true});
Create a new page instance.
const page = await browser.newPage();
Navigate to the ray.run
website.
await page.goto('https://ray.run');
Finally, log the output of the ray.run
website.
const response = await page.goto('https://ray.run');
console.log(await response.text());
Your final code should look like this:
import { chromium } from 'playwright';
(async () => {
const browser = await chromium.launch({headless: true});
const page = await browser.newPage();
await page.goto('https://ray.run');
const response = await page.goto('https://ray.run');
console.log(await response.text());
// Close the browser
await browser.close();
})();
For more information on Playwright, check out Mastering Playwright Test Automation: Your Comprehensive Cheat Sheet.
If you still have questions, please ask a question and I will try to answer it.
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].