2

I'm just getting started with Playwright so I don't know if there is something I'm missing. I do not have any other testing framework wired up to it. I'm using @playwright/test v1.14.1.

This test:

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);
        }
    });
});

is producing the following error:

   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);

If I remove the call to expect, the test passes but the console.log still will not fire off.

Chance
  • 11,043
  • 8
  • 61
  • 84
  • `input.evaluateAll` gets executed inside the browser which is a different execution context in which expect is not available (Node.js vs. e.g. Chromium). See here: https://playwright.dev/docs/core-concepts/#execution-contexts-playwright-and-browser – Max Schmitt Sep 20 '21 at 09:56
  • 1
    @MaxSchmitt gotcha. that makes sense. if you answer with that, I'll close up this question. thank you for your help. – Chance Sep 20 '21 at 14:30

1 Answers1

3

input.evaluateAll gets executed inside the browser which is a different execution context in which expect is not available (Node.js vs. e.g. Chromium).

See here: https://playwright.dev/docs/evaluating

Max Schmitt
  • 2,529
  • 1
  • 12
  • 26