我目前正在尝试使用 expect 来做断言,const { expect } = require('@playwright/test');
但每次我得到错误:找不到模块'@playwright/test'。这是一个非常短的脚本,但其中有问题。
const { chromium } = require("playwright");
const { expect } = require('@playwright/test');
const { matchers } = require('playwright-expect');
console.log("##########", expect)
// add custom matchers
expect.extend(matchers);
(async () => {
const browser = await chromium.launch({
headless: false,
});
const page = await browser.newPage();
await page.goto("someurl");
await page.fill("input[name='userLoginId']", 'nnn');
await page.fill("input[name='password']", 'nnn');
await page.click("button[type=submit]");
})();
包.json
{
"name": "playwright",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node ./index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"playwright": "^1.15.1",
"playwright-expect": "^0.1.2"
}
}
没有这个测试工作正常:
const { expect } = require('@playwright/test');
const { matchers } = require('playwright-expect');
console.log("##########", expect)
// add custom matchers
expect.extend(matchers);
它做我要求它做的事情,但是现在我想做断言并且我补充说,现在它不起作用。