In Playwright, how do I fix the error locator.evaluateAll: Evaluation failed: ReferenceError: _test is not defined?
In Playwright, how do I fix the error locator.evaluateAll: Evaluation failed: ReferenceError: _test is not defined?
我刚刚开始使用 Playwright,所以我不知道是否遗漏了什么。我没有任何其他测试框架连接到它。我正在使用 @playwright/test v1.14.1
.
本次测试:
import { test, expect } from "@playwright/test";
test("focus sets tab indexes appropriately", async ({ page }) => {
await page.goto("http://localhost:3000/test");
const inputs = page.locator("input");
await expect(inputs).toHaveCount(5);
await inputs.evaluateAll(async (nodes) => {
console.log(nodes);
for (const node of nodes) {
console.log(node);
await expect(node.tabIndex).toBe(0);
}
});
});
产生以下错误:
locator.evaluateAll: Evaluation failed: ReferenceError: _test is not defined
at eval (eval at evaluate (:3:1339), <anonymous>:6:7)
at t.default.evaluate (<anonymous>:3:1362)
at t.default.<anonymous> (<anonymous>:1:44)
5 | const inputs = page.locator("input");
6 | await expect(inputs).toHaveCount(5);
> 7 | await inputs.evaluateAll(async (nodes) => {
| ^
8 | console.log(nodes);
9 | for (const node of nodes) {
10 | console.log(node);
如果我删除对 expect
的调用,测试通过但 console.log
仍然不会触发。
input.evaluateAll
在浏览器内执行,这是一个不同的执行上下文,其中 expect
不可用(Node.js 与例如 Chromium)。
看这里:https://playwright.dev/docs/core-concepts/#execution-contexts-playwright-and-browser
我刚刚开始使用 Playwright,所以我不知道是否遗漏了什么。我没有任何其他测试框架连接到它。我正在使用 @playwright/test v1.14.1
.
本次测试:
import { test, expect } from "@playwright/test";
test("focus sets tab indexes appropriately", async ({ page }) => {
await page.goto("http://localhost:3000/test");
const inputs = page.locator("input");
await expect(inputs).toHaveCount(5);
await inputs.evaluateAll(async (nodes) => {
console.log(nodes);
for (const node of nodes) {
console.log(node);
await expect(node.tabIndex).toBe(0);
}
});
});
产生以下错误:
locator.evaluateAll: Evaluation failed: ReferenceError: _test is not defined
at eval (eval at evaluate (:3:1339), <anonymous>:6:7)
at t.default.evaluate (<anonymous>:3:1362)
at t.default.<anonymous> (<anonymous>:1:44)
5 | const inputs = page.locator("input");
6 | await expect(inputs).toHaveCount(5);
> 7 | await inputs.evaluateAll(async (nodes) => {
| ^
8 | console.log(nodes);
9 | for (const node of nodes) {
10 | console.log(node);
如果我删除对 expect
的调用,测试通过但 console.log
仍然不会触发。
input.evaluateAll
在浏览器内执行,这是一个不同的执行上下文,其中 expect
不可用(Node.js 与例如 Chromium)。
看这里:https://playwright.dev/docs/core-concepts/#execution-contexts-playwright-and-browser