[Question] Using For.. await with PlayWright test (TypeScript)
See original GitHub issueHi 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:
- Created a year ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
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!
NB: If generating your test cases is expensive, you can break these steps up and run like: