soccerway
soccerway

Reputation: 11991

Unable to run the playwright tests

I am trying to run playwright test from the below location, but it shows the message npm install -D @playwright/test and unable to run the test. I have already installed playwright as dev dependency. Could someone please advise what is the issue here ?

I have tried below runs:

1)

Test User@TestUser MINGW64 /c/Test
    $ npx playwright test --headed
    Please install @playwright/test package to use Playwright Test.
      npm install -D @playwright/test
  1. Test User@TestUser MINGW64 /c/Test $ npx playwright test Please install @playwright/test package to use Playwright Test. npm install -D @playwright/test

// test/test1.spec.js

const { test, expect } = require('@playwright/test');

test('basic test', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  const title = page.locator('.navbar__inner .navbar__title');
  await expect(title).toHaveText('Playwright');
});

//package.json

{
  "name": "play",
  "version": "1.0.0",
  "description": "Playwright test",
  "main": "index.js",
  "directories": {
    "test": "test"
  },
  "dependencies": {},
  "devDependencies": {
    "@playwright/test": "^1.16.1"
  },
  "scripts": {
    "test": "npx playwright test"
  },
  "author": "Test",
  "license": "ISC"
}

enter image description here

Upvotes: 5

Views: 20217

Answers (2)

Arun Yadav
Arun Yadav

Reputation: 31

I tried the above solutions but didn't work for me straight forward. I did the below workaround that worked for me

Steps

  • npm uninstall playwright playwright-chromium
  • Delete manually @playwright/test line from dev dependency section of package.json file
  • npm update
  • npm install -D @playwright/test

Upvotes: 0

Dima Dorogonov
Dima Dorogonov

Reputation: 2553

I saw guys are recommending a couple of suggestions here

  1. Delete the playwright module.

    npm rm playwright

    npm install @playwright/test -D

  2. Use yarn npx playwright test -> yarn playwright test

  3. And I solved the issue in my Gitlab pipeline with adding this to my .gitlab-ci.yml.

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - node_modules/

Upvotes: 2

Related Questions