javascript - Miért kapom a 'Playwright Test did not expect $ {title} to be called here' üzenetet, amikor megpróbálok tesztet futtatni a testRunner.ts fájlból?
A tests mappában .spec.ts tesztfájljaim vannak, és a testRunner.ts fájl a szülőkönyvtárban található. A projektet a tsc segítségével építettem, és úgy konfiguráltam, hogy a generált js fájlokat a dist mappában tárolja. A build után végrehajtottam a testRunner.js-t, és ezt a hibát kapom: Error: A Playwright Test nem várta, hogy a test() itt legyen meghívva.
Ellenőriztem a következőket.
- A test() függvényt egy konfigurációs fájlban hívja meg - Nem
- Több drámaíró/teszt verzió telepítve - Nem
- a test() hívása egy fájlban, amelyet a konfigurációs fájl importál - Nem
Új vagyok a TypeScript és a Playwright használatában, de nem vagyok biztos benne, hogy még mit tehetek itt. Ez az én testRunner.ts fájlom
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 fájl
{
"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')
});
};
Válasz #1
ellenőrizd a package.json fájlodat, leginkább az ütköző függőségek okozzák ezt a problémát
add hozzá ezt a package.json fájlodhoz:
"devDependencies": {
"@playwright/test": "^1.49.1",
"@types/node": "^22.10.7" }
