I have a test which aims to check whether the contents downloaded from a page match the expected content. My code:
const expectedFiles = [...]
let actualFiles = [];
fs.createReadStream('/tmp/mydrivecontents.zip')
.pipe(unzipper.Parse())
.on('entry', function (entry) {
var fileName = entry.path;
actualFiles.push(fileName)
});
if (actualFiles == expectedFiles) {
await page.evaluate(_ => {}, `browserstack_executor: ${JSON.stringify({action: 'setSessionStatus',arguments: {name: 'can download drive contents', status: 'passed',reason: 'Can download drive contents'}})}`);
} else {
await page.evaluate(_ => {}, `browserstack_executor: ${JSON.stringify({action: 'setSessionStatus',arguments: {name: 'can download drive contents', status: 'failed',reason: 'Can't download drive contents'}})}`);
}
It used to work correctly. However running it now it always fails because it executes the if/else block before the fs.createReadStream() function. I tried to make sure the conditional block executes last by using callback functions, but this produces a Playwright error saying “reserved word: await” and reports that no tests were found, since I don’t think Playwright allows to have await
statements inside a function inside a test.
Any ideas how to go about this? Everything online related to sequential execution in Playwright is about the sequence of multiple tests, not of function execution within a test.