[英]Error: Cannot find module '@playwright/test'
I am currently trying to use expect to do assertions by using const { expect } = require('@playwright/test');
我目前正在尝试通过使用
const { expect } = require('@playwright/test');
来使用 expect 来进行断言。 but every time I get Error: Cannot find module '@playwright/test'.但每次我得到错误:找不到模块'@playwright/test'。 It is a very short script but something is wrong with that.
这是一个非常短的脚本,但其中有问题。
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]");
})();
package.json package.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"
}
}
The test works fine without this:没有这个测试工作正常:
const { expect } = require('@playwright/test');
const { matchers } = require('playwright-expect');
console.log("##########", expect)
// add custom matchers
expect.extend(matchers);
And it does what I ask it to do, but now that I want to do assertions and I add that, now it does not work.它做我要求它做的事情,但是现在我想做断言并且我补充说,现在它不起作用。
@playwright/test
library:@playwright/test
库: npm i -D @playwright/test
Do not use playwright-expect
library.不要使用
playwright-expect
库。 Playwright already includes web-first assertions . Playwright 已经包含了网络优先的断言。 Hence, there is no reason to use an additional library to extend expect.
因此,没有理由使用额外的库来扩展期望。
Remove unused code:删除未使用的代码:
const { matchers } = require('playwright-expect');
console.log("##########", expect)
// add custom matchers
expect.extend(matchers);
I've created an issue about the same question here https://github.com/microsoft/playwright/issues/14971 and I'll update the result when it's answered.我在这里https://github.com/microsoft/playwright/issues/14971创建了一个关于同一问题的问题,我会在回答后更新结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.