I have .spec.ts test files in the tests folder and i have the testRunner.ts file in the parent directory. I hav built the project using tsc and configured to store the generated js files in a dist folder. After the build i have executed the testRunner.js and i get this error. Error: Playwright Test did not expect test() to be called here.
I have checked the following.
- You are calling test() in a configuration file - No
- Several playwright/test versions installed - No
- calling test() in a file that is imported by the configuration file - No
Im new to typescript and playwright but Im not sure what else i can do here. This is my testRunner.ts file
import { Command } from "commander";
const fs = require('fs'); // no default export in node.js
const executeTests = new Command();
executeTests
.requiredOption('-c, --client <clientName', 'Specify the client name. Eg. -c nbc OR --client nbc')
.parse(process.argv) // returns an array containing the command line args (client name)
const options = executeTests.opts();
const clientName = options.client.toLowerCase();
const clientTestDataFile = '../clientTestData/testdata_'+clientName+'.json';
if (!fs.existsSync(clientTestDataFile)) {
console.error('Error: Test data file not found in the test data folder for the client '+clientName+'.');
process.exit(1);
} else {
runTests();
// runTests();
}
const clientTestData = JSON.parse(fs.readFileSync(clientTestDataFile, 'utf-8'));
async function runTests() {
console.log('test1');
const { runTest1 } = await import('./tests/tes.spec');
console.log('test2');
await runTest1();
// runTest1();
//runTest2();
}
tsconfig.json file
{
"compilerOptions": {
"target": "ES5",
"module": "CommonJS",
"sourceMap": true,
"outDir": "dist",
}
}
tes.spec.ts
import { expect, test} from "@playwright/test"
//import casualportal_home from "../page/casualportal_home";
//import { create } from "domain";
//import casualportal_cart from "../page/casualportal_cart";
//const testdata= JSON.parse(JSON.stringify(require("../testdata.json")))
export function runTest1() {
test('Validate if the "Book" button works', async ({ page , baseURL }) => {
console.log('test() called')
});
};