Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Default test scripts included in the Playwright package are not running correctly in Gitbash #27996

Closed
auto-franklin opened this issue Nov 7, 2023 · 3 comments

Comments

@auto-franklin
Copy link

auto-franklin commented Nov 7, 2023

I found this but its closed and I cannot seem to find a clear answer for it.
#17500

According to the official site Version 1.39.0 is the latest one

System info

  • Playwright Version: [Version 1.39.0]
  • Operating System: [Windows 10 Pro ]
  • Browser: [No browser opens]
  • Other info: Windows version "22H2"

Source code

Config file


/**
 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
 */
// require('dotenv').config();

/**
 * See https://playwright.dev/docs/test-configuration.
 */
export default defineConfig({
  testDir: './tests',
  /* Run tests in files in parallel */
  fullyParallel: true,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: 'html',
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Base URL to use in actions like `await page.goto('/')`. */
    // baseURL: 'http://127.0.0.1:3000',

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'on-first-retry',
  },

  /* Configure projects for major browsers */
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },

    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'] },
    },

    {
      name: 'webkit',
      use: { ...devices['Desktop Safari'] },
    },

    /* Test against mobile viewports. */
    // {
    //   name: 'Mobile Chrome',
    //   use: { ...devices['Pixel 5'] },
    // },
    // {
    //   name: 'Mobile Safari',
    //   use: { ...devices['iPhone 12'] },
    // },

    /* Test against branded browsers. */
    // {
    //   name: 'Microsoft Edge',
    //   use: { ...devices['Desktop Edge'], channel: 'msedge' },
    // },
    // {
    //   name: 'Google Chrome',
    //   use: { ...devices['Desktop Chrome'], channel: 'chrome' },
    // },
  ],

  /* Run your local dev server before starting the tests */
  // webServer: {
  //   command: 'npm run start',
  //   url: 'http://127.0.0.1:3000',
  //   reuseExistingServer: !process.env.CI,
  // },
});

Test file (self-contained)


test('has title', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  // Expect a title "to contain" a substring.
  await expect(page).toHaveTitle(/Playwright/);
});

test('get started link', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  // Click the get started link.
  await page.getByRole('link', { name: 'Get started' }).click();

  // Expects page to have a heading with the name of Installation.
  await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});

Steps

  • Install git bash
  • Install npm
  • Install node
  • Install playwright
  • Install visual studio (I installed visual studio as well but I dont know my way around it enough to try and execute the command there yet )
  • open gitbash
  • look for playwright directory
  • execute command npx playwright test
    - Bug occurs

Expected

After a freshly installed version of npm, node and playwright, when executing npx playwright test in my git bash console I should be able to correctly execute the default 6 test scripts that come along the playwrights tool package.

Actual

image

When executing npx playwright test in my git bash console I get this error message and the tests are not executed at all.

Error: Playwright Test did not expect test() to be called here.
Most common reasons include:

  • You are calling test() in a configuration file.

  • You are calling test() in a file that is imported by the configuration file.

  • You have two different versions of @playwright/test. This usually happens
    when one of the dependencies in your package.json depends on @playwright/test.

    at example.spec.ts:3

    1 | import { test, expect } from '@playwright/test';
    2 |
    3 | test('has title', async ({ page }) => {
    | ^
    4 | await page.goto('https://playwright.dev/');
    5 |
    6 | // Expect a title "to contain" a substring.

    at TestTypeImpl._currentSuite (C:\Users\Frank\documents\proyectos\frankplaywright\node_modules\playwright\lib\common\testType.js:71:13)
    at TestTypeImpl._createTest (C:\Users\Frank\documents\proyectos\frankplaywright\node_modules\playwright\lib\common\testType.js:77:24)
    at C:\Users\Frank\documents\proyectos\frankplaywright\node_modules\playwright\lib\transform\transform.js:236:12
    at Object. (C:\Users\Frank\documents\proyectos\frankplaywright\tests\example.spec.ts:3:5)

Error: No tests found

To open last HTML report run:

npx playwright show-report

@auto-franklin auto-franklin changed the title [BUG] Noob starting with Playwright having difficult running the default test scripts included in the package [BUG] Default test scripts included in the Playwright package are not running correctly in Gitbash Nov 7, 2023
@dgozman
Copy link
Contributor

dgozman commented Nov 7, 2023

@auto-franklin Most likely, you have two different versions of Playwright. The one which provides the CLI executed by npx playwright test, and another one you import in tests. Perhaps, your gitbash environment does not resolve npx playwright to the right playwright? I am not really sure how to help here without replicating your entire setup, which seems too involved.

As a workaround, try the following:

node node_modules\@playwright\test\cli.js test

Let me know whether this helps.

@auto-franklin
Copy link
Author

auto-franklin commented Nov 8, 2023

@auto-franklin Most likely, you have two different versions of Playwright. The one which provides the CLI executed by npx playwright test, and another one you import in tests. Perhaps, your gitbash environment does not resolve npx playwright to the right playwright? I am not really sure how to help here without replicating your entire setup, which seems too involved.

As a workaround, try the following:

node node_modules\@playwright\test\cli.js test

Let me know whether this helps.

Hey, thanks for the reply! I used your command and I got this.

Frank@DESKTOP-VTSOOPH MINGW64 ~/documents/proyectos/fcplaywright
$ node node_modules\@playwright\test\cli.js test
node:internal/modules/cjs/loader:1051
  throw err;
  ^

Error: Cannot find module 'C:\Users\Frank\documents\proyectos\fcplaywright\node_modules@playwrighttestcli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.9.0

Another thing I should probably mention is that, when installing the node I realized I was choosing the nvm linux or osx option instead of the nvm-windows option, so I ended up downloading an installer for windows instead of installing it through gitbash (although I am aware that this is discouraged by the node creators due to possible conflicts with local-global permits)

image

I downloaded an installer for windows and used the Node.js command prompt to execute the command npx playwright test
image
tests run correctly

then executed npx playwright show-report
image
and got to see the reports :)

When trying to execute the same commands in Gitbash I get the same mistakes as before.

@dgozman
Copy link
Contributor

dgozman commented Nov 8, 2023

Hey, thanks for the reply! I used your command and I got this.

Well, judging by C:\Users\Frank\documents\proyectos\fcplaywright\node_modules@playwrighttestcli.js, you probably have to escape the slashes? I am not really sure what does GitBash expect, perhaps node node_modules\\@playwright\\test\\cli.js test?

and got to see the reports :)

Yay!

When trying to execute the same commands in Gitbash I get the same mistakes as before.

Unfortunately, I am not really sure we can help with this. It is a question about using node/npm inside GitBash, and Playwright team are not the experts on the matter. Given this, let me close this issue as non-actionable from Playwright side. However, if you figure out the solution, consider commenting here for all other GitBash users to benefit from.

@dgozman dgozman closed this as completed Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants