如何在playwright js中使用expect?

问题描述 投票:0回答:1

我用 chai 用 puppeteer 编写了以下代码。怎么用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();
})()
testing puppeteer chai playwright
1个回答
0
投票

您应该能够使用正则表达式来检查文本,这样就可以满足您的期望:

expect(text).not.toHaveText(/top-bar/);

或者,如果您只想检查确切的文本,那么您可以跳过正则表达式,直接将其放在那里。

expect(text).not.toHaveText('top-bar');

© www.soinside.com 2019 - 2024. All rights reserved.