Rayrun
← Back to Discord Forum

Test fails when running npx playwright test, but passes when running through VSCode using plugin

Weird issue happening. I created a test and it passes when running via VS Code using the playwright plugin, but fails when I try to run it via the command line using npx playwright test. how can I check to make sure I am using the same test runner for both ways of execution? Or does anyone have any ideas?

This thread is trying to answer question "Why does a test pass when run via VS Code using the playwright plugin, but fail when run via the command line using npx playwright test, and how can the same test runner be ensured for both methods of execution?"

37 replies

could you be more specific on the failure, trace or log would be great for debugging your issue

debbieobrien
debbieobrien

running npx playwright test will run your tests across all projects setup in your config file. by default this is all 3 browsers. running in VS Code by default will only run on chromium. other than that everything is the same

Error: page.waitForResponse: Page closed at ..\pages\blockEnergyPredictions.ts:58

56 |       //});
  57 |

58 | const response = await page.waitForResponse(response => { | ^ 59 | return ( 60 | response.url().startsWith('http://website.com/web/v1.0/agency_blocks/') && 61 | response.status() === 200

Retry #1 ─────────────────────────────────────────
Test timeout of 30000ms exceeded.
Error: locator.waitFor: Page closed

This is the code it was trying to execute: const response = await page.waitForResponse(response => { return ( response.url().startsWith('http://xxx.xx.xx.x/web/v1.0/agency_blocks/') && response.status() === 200 ); }, { timeout: 60000 });

here are the trace files.

mittree_47147

so am I correct here? when you run the test from the command line, it fails.. Run through vs code it passes? I am seeing this here recently. it started out as a couple test. now the majority of my test fail from command line

mittree_47147

Error: locator.fill: Test timeout of 30000ms exceeded.

mittree_47147

Error: locator.pressSequentially: Test timeout of 30000ms exceeded.

mittree_47147

alot of these types of errors for me

Would assert you have bad locators, if they are good, but fail then would assert your tests may be running slowing and exceeding a times out.

mittree_47147

do you have any ideas on why they only fail when ran from command line and not through vscode?

Do you have multiple projects in your config? Which project(s) do you have selected in your vscode extension? Are you literally just running npx playwright test or adding anything extra on that may be changing the test execution? Have you checked traces from the failed tests to identify anything more specific on what is going wrong?

Ya no replacing the need to debug and investigate your test, no substitute from rolling up you sleeves and figure out what is happening. not a surprise that running in VS Code you may effectively be adding time delays which the tests outside of VS Code won't benefit from, if you increase the default timeout value while running from npx? Until you can rule that out seems you have some debugging and investigating?

mittree_47147

this is what I get.

mittree_47147

1 Playwright\tests\QA\Quote-LinQ\Broker_Admin\Log in\Log_in_Broker.spec.ts:3:5 › test (30.0s)

  1. Playwright\tests\QA\Quote-LinQ\Broker_Admin\Log in\Log_in_Broker.spec.ts:3:5 › test ───────────
Test timeout of 30000ms exceeded.
Error: locator.pressSequentially: Test timeout of 30000ms exceeded.
Call log:
  - waiting for getByPlaceholder('Username')


  3 | test('test', async ({ page }) => {
  4 |   await page.goto('https://qa.quote-linq.com/auth/login');

5 | await page.getByPlaceholder('Username').pressSequentially('Broker_admin',{delay: 100}); | ^ 6 | await page.getByRole('button', { name: 'Login' }).click(); 7 | await page.getByPlaceholder('Password').pressSequentially('password123', {delay: 100}); 8 | await page.getByRole('button', { name: 'Login' }).click(); at C:\Users\Steve Bishop\Playwright\tests\QA\Quote-LinQ\Broker_Admin\Log in\Log_in_Broker.spec.ts:5:43

Slow test file: Playwright\tests\QA\Quote-LinQ\Broker_Admin\Log in\Log_in_Broker.spec.ts (30.0s) Consider splitting slow test files to speed up parallel execution 1 failed Playwright\tests\QA\Quote-LinQ\Broker_Admin\Log in\Log_in_Broker.spec.ts:3:5 › test ──────────

mittree_47147

in the config it is set up for 60 seconds timeout

mittree_47147

using - npx playwright test Log_in_Broker.spec.ts --trace on

mittree_47147

in the trace.zip file i have a test.trace, 0-trace.trace, 0-trace.stacks, 0-trace.network, and a resources folder. When I go to the resources folder i have a html file, two jpegs and a txt file.

mittree_47147

I'm just confused because it works in vscode and not in command line. sorry eveyone, I've only just begun my automation journey so I am inexperienced on a lot of this

After running your test from the command line you would run: npx playwright show-report which would open the playwright html report, and you can then view the trace for the test from there

Or you can drag the trace.zip file to https://trace.playwright.dev/

Something doesn't sound right though if it's not picking up the correct test timeout

mittree_47147

I have a hotfix env and a QA env. The hotfix env works

Then it sounds like you have something messed up and need to isolate?

We don't know what the difference between those are. It sounds like the test just takes longer than 30 seconds?

Ya feels like more time is being spent describing the issue then someone actually debugging it to identify the issue?

Not saying issues are easy to find, just spent two days trying to figure out why something was failing, and had no info why... My philosophy is a person will be as good of a dev as to the level of issues they may debug. Kind of like the "Peter Principle" but for coding/development.

mittree_47147
@sinfluxx: thank you for your input. I appreciate it. When I ran npx playwright (name of test) show-report I didn't have anything open up. This is what my config has in it reporter: [ ['list'], ['html', { open: 'always' }] ],

thank you for your input. I appreciate it. When I ran npx playwright (name of test) show-report I didn't have anything open up. This is what my config has in it reporter: [

['list'],

    ['html', { open: 'always' }]

],
mittree_47147

again, inexperience so I'm assuming that is related to reports

Based on that the html report should be opening automatically once you've run the test(s) via the command line anyway. As per the timeout it sounds like your config isn't being used for some reason.

Do you have more than one playwright config?

mittree_47147

I do not.

mittree_47147

I'm gonna keep at it

mittree_47147

it's just like one day they started to fail from command line

If it worked fine before then it sounds like someone's made a change at some point that has caused your playwright config to not be used.

If you run:

npx playwright test --project doesNotExist

Does the error list the projects that you actually have in your config?

mittree_47147

the project in my config is not listed there

You're running the command from the same directory as your playwright config?

mittree_47147

yeah it is listed as available

mittree_47147

I'm gonna keep at it. I will check back later. I appreciate you help Josh

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].