0

I have following code written in puppeteer with chai. How could it be written in playwright js?

const expect = require("chai").expect;

const puppeteer = require("puppeteer");
(async () => {
  const browser = await puppeteer.launch({
    headless: false,
    slowMo: 500, // slow down by 500ms
  });
  const page = await browser.newPage();
  const navigationPromise = page.waitForNavigation()
  // Go to the web page
  await page.goto("https://www.test.com");
  await navigationPromise;


  //Look for navigation point
  await page.screenshot({ path: "navigation.jpg" });
  const text = await page.$eval('.top--right', ele => ele.textContent);
  expect(text).to.not.include('top-bar');
  console.log("Navigation is deployed");
  await browser.close();
})()
user1953051
  • 321
  • 2
  • 7
  • 21
  • `const navigationPromise = page.waitForNavigation()` should be removed. `goto` already does this. – ggorlen Aug 10 '23 at 15:13

1 Answers1

0

You should be able to use regex to check for the text so something like this for your expect: expect(text).not.toContainText(/top-bar/);

Or if you only want to check for the exact text then you can skip the regex and just directly put it there. expect(text).not.toContainText('top-bar');

Basti
  • 449
  • 2
  • 13