Run async API call in TestCafe .js config

Viewed 31

I am trying to setup TestCafe test filtering based on an API response. Ideally, I'd like to execute the API call before the runner actually spins up so that I can specify a metadata filter to exclude based on enabled environment variables.

I am wondering if it is possible to execute an async API call to filter test data, or if I would need to do this somewhere else. I haven't found any resources that really delve into the limitations of the .js configuration file for this use case.

Much thanks in advance

Cheers

1 Answers

You can execute API calls in a filter function in the .testcaferc.js file and filter your tests based on the response. For example:

//.testcaferc.js
module.exports = {
    filter: async (testName) => {
        const apiResponse = await callAPI();

 

        //...
    }
};
Related