question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Using For.. await with PlayWright test (TypeScript)

See original GitHub issue

Hi there,

I have begun building out a Test Suite for my blog cloudwithchris.com. It is built using the Hugo Static Site Generator, so I know what content should be available ahead of time. I plan to read through all of the markdown files (e.g. blog posts, podcast episodes), and check that certain data is in place (e.g. Titles, Banner Images, SEO Metadata, etc.)

I am trying to optimise the execution of the tests before I invest too much time into building further tests, but hitting an issue.

I am trying to use the For… await pattern in JavaScript to allow the tests to be executed asynchronously.

As soon as I put the await keyword before a test, e.g. await test('Check title is correct:.....'), it will then fail with the below 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

Is this because test returns a void, as per https://playwright.dev/docs/api/class-test#test-call ? Are there any patterns to achieve similar (e.g. looping through a series of objects, that have been generated from a directory list).

I have seen the CSV file scenario, but cannot quite map it to what I’m looking for. A work in progress example of what I’m working on is available at https://github.com/CloudWithChris/cloudwithchris.com/blob/preview/action-test/tests/example.spec.ts

Any insights appreciated - This is my first time using Playwright, so I have no doubt I’m missing something obvious 😃

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisreddingtoncommented, Mar 28, 2022

Makes complete sense @rwoll - Thank you! I think I made some false assumptions on the parallelism of the tests (even though I read that very doc, about tests within a file being ran in-order by default).

Code refactored based upon our above discussion, and also configured to use the fullyParallel config file. Appreciate your help here, thank you so much!

0reactions
rwollcommented, Mar 28, 2022

NB: If generating your test cases is expensive, you can break these steps up and run like:

$ npm run generate-test-cases # drops a JSON file on disk with the relevant bits, can be an arbitrary Node script, including async 
$ npx playwright test # reads in the JSON file to generate the test cases.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditionally wait for locators in Playwright - Stack Overflow
Using Promise.race , you can wait for one of many possible locators to be visible, then return details about which locator succeeded.
Read more >
Answers to All The Top Questions For Playwright Testing
Q: Does Playwright by default work asynchronously? That is, do we not have to use async/await explicitly? A: That depends on the language....
Read more >
An End To End Playwright Testing Tutorial - YouTube
This Playwright testing tutorial covers everything you need to get you up and running with the Microsoft Playwright framework with TypeScript.
Read more >
Async and Await in Playwright - ProgramsBuzz
While writing our first test, we used the async and await keywords in our test. Let's understand the main reason behind using it....
Read more >
How To Run End-to-End Tests Using Playwright and Docker
In this tutorial, you will set up an environment to use Playwright with Typescript for end-to-end testing, write and execute the tests, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found