Sam Davies
Sam Davies

Reputation: 33

Playwright Test Runner Failing Tests

Hi I've been learning Playwright and been executing scripts using the command line and "node filename.js" to execute the tests manually. I have since been looking into using the test runner and executing tests using "npx folio" or "npx filename.spec.ts" having appropriately edited the scripts, they execute but seems to fail very early on in the script where they had previously worked fine.

Is there something else other than changing the declaration at the top of script, or do I also need to change syntax in the body of the script for proper execution in typescript.

Below is all I have changed between the two scripts.

javascript declaration

typescript

Upvotes: 2

Views: 7314

Answers (1)

sahmeepee
sahmeepee

Reputation: 532

Now that Playwright Test Runner has been released fully (docs here: https://playwright.dev/docs/test-intro) it's worth switching to that. The syntax is slightly different, with the more intuitive "test" rather than "it".

The documentation is now very good so probably doesn't need to be repeated here at length, but for your example it would start something like:

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

test('ofcsingleapptest', async({ page }) => {
      var date = Date.now();
      var d = date.toString();
      //more
      //test
      //steps
      await page.goto('https://some.url');
});

Just save this as filename.js in a /tests directory in your project and then run:

npx playwright test

to run all tests in /tests or run:

npx playwright test filename.js

and it will run any tests matching that name.

Setting which browsers to use and options like headlessness is probably best done now by creating a playwright.config.js in the root of your project. Examples of that are available here:

https://playwright.dev/docs/test-configuration

Upvotes: 2

Related Questions