Cant require playwright

2k Views Asked by At

trying to run the following snippet

const { it, expect } = require('@playwright/test');
 
it('is a basic test with the page', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  const home = await page.waitForSelector('home-navigation');
  expect(await home.innerText()).toBe(' Playwright');
});

but get the following error :

TypeError: test_runner_1.fixtures.defineParameter is not a function

pointing to my require statement, I have run npm i -D @playwright/test @playwright/test-runner and have the modules present. Why would this fail? trying to run it with node 'filename.js'

2

There are 2 best solutions below

0
On

when you use playwright-test test runner: run commands like with npx:

file should be store in format *.ts, like:

foo.spec.ts

Run all tests across Chromium, Firefox and WebKit

npx folio

Run tests on a single browser

npx folio --param browserName=chromium

Run all tests in headful mode

npx folio --param headful

Run tests with slowMo (slows down Playwright operations by n milliseconds)

npx folio --param slowMo=100

Save screenshots on failure in test-results directory

npx folio --param screenshotOnFailure

See all options

npx folio --help

to run your code with more than 1 param:

npx foo.spec.ts --param browserName=chromium --param headful
0
On

Yes, for the Test scripts to run. It will look for the file name to be either *.spec.ts or *.test.ts