Ant*_*ras 7 javascript node.js playwright playwright-test
我目前正在尝试使用 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]");
})();
Run Code Online (Sandbox Code Playgroud)
包.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"
}
}
Run Code Online (Sandbox Code Playgroud)
没有这个测试工作正常:
const { expect } = require('@playwright/test');
const { matchers } = require('playwright-expect');
console.log("##########", expect)
// add custom matchers
expect.extend(matchers);
Run Code Online (Sandbox Code Playgroud)
它做了我要求它做的事情,但是现在我想做断言并且我添加了这一点,现在它不起作用了。
@playwright/test库: npm i -D @playwright/test
Run Code Online (Sandbox Code Playgroud)
不要使用playwright-expect库。Playwright 已经包含了网络优先的断言。因此,没有理由使用额外的库来扩展expect。
删除未使用的代码:
const { matchers } = require('playwright-expect');
console.log("##########", expect)
// add custom matchers
expect.extend(matchers);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25467 次 |
| 最近记录: |