Однако в VS Code кнопка Playwright Test Runner не отображается.
В терминале Playwright говорит: «Тесты не найдены», даже когда я передаю имя файла спецификации напрямую.
Команда и ошибка:
Код: Выделить всё
PS C:\MyWorkspace\Playwright> npx playwright test dataDrivenXLSX.spec.ts
Error: No tests found.
Make sure that arguments are regular expressions matching test files.
You may need to escape symbols like "$" or "*" and quote the arguments.
- Кнопку запуска VS Code для отображения моих тестов.
- для обнаружения и запуска моих тестов *.spec.ts.
Код: Выделить всё
npx playwright test - для запуска этого файла.
Код: Выделить всё
npx playwright test dataDrivenXLSX.spec.ts
Код: Выделить всё
C:\MyWorkspace\Playwright
├─ sandbox\
│ └─ dataDrivenXLSX.spec.ts
├─ testdata\
│ └─ Login.xlsx
├─ playwright.config.ts
├─ tsconfig.json
└─ package.json
- :
Код: Выделить всё
playwright.config.tsКод: Выделить всё
import { defineConfig, devices } from '@playwright/test'; export default defineConfig({ testDir: '.', fullyParallel: false, forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers: process.env.CI ? 1 : undefined, reporter: [ ['html'], ['allure-playwright'] ], use: { trace: 'on-first-retry', headless: false, screenshot: 'on-first-failure', video: 'on', baseURL: 'https://www.saucedemo.com/', }, metadata: { appUsername: 'pwtest@nal.com', appPassword: 'test123' }, projects: [ { name: 'Google Chrome', use: { channel: 'chrome', viewport: null, launchOptions: { args: ['--start-maximized'], ignoreDefaultArgs: ['--window-size=1280, 720'] } }, }, ], }); - :
Код: Выделить всё
tsconfig.jsonКод: Выделить всё
{ "compilerOptions": { // File Layout // "rootDir": "./src", // "outDir": "./dist", // Environment Settings "module": "nodenext", "target": "esnext", "moduleResolution": "nodenext", // Playwright + Node types // Purpose: Make TypeScript understand Playwright + Node global functions. "types": ["@playwright/test", "node"], // Other Outputs "sourceMap": true, "declaration": true, "declarationMap": true, // Stricter Typechecking Options "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": false, // Recommended Options "strict": true, "jsx": "react-jsx", "verbatimModuleSyntax": false, "isolatedModules": true, "noUncheckedSideEffectImports": true, "moduleDetection": "force", "skipLibCheck": true, "strictNullChecks": false }, // Purpose: Tell TypeScript which files to type-check and compile. "include": ["tests/**/*.ts", "playwright.config.ts"] } - :
Код: Выделить всё
package.jsonКод: Выделить всё
{ "name": "playwrightproject", "version": "1.0.0", "main": "index.js", "type": "module", "scripts": { "test": "npx playwright test", "allure:generate": "npx allure generate allure-results --clean -o allure-report", "allure:open": "npx allure open allure-report" }, "keywords": [], "author": "", "license": "ISC", "description": "", "devDependencies": { "@playwright/test": "^1.56.1", "@types/node": "^24.10.1", "allure-commandline": "^2.34.1", "allure-playwright": "^3.4.2", "typescript": "^5.9.3" }, "dependencies": { "csv-parse": "^6.1.0", "xlsx": "^0.18.5" } } - Файл спецификации ():
Код: Выделить всё
sandbox/dataDrivenXLSX.spec.tsКод: Выделить всё
import { test, expect } from '@playwright/test'; import path from "path"; import { fileURLToPath } from "url"; import XLSX from "xlsx"; interface LoginTestData { username: string, password: string, expectedResult: string } const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); function getLoginCreds(xlsxFileName: string): LoginTestData[] { const absolutePath = path.join(__dirname, "../testdata", xlsxFileName); const workbook = XLSX.readFile(absolutePath); const sheet = workbook.Sheets["Register"]; const users = XLSX.utils.sheet_to_json(sheet); return users; } const records = getLoginCreds("Login.xlsx"); for (const record of records) { test(`Login Test for ${record.username}`, async ({ page }) => { await page.goto('https://www.saucedemo.com'); await page.locator("#user-name").fill(record.username); await page.locator("#password").fill(record.password); await page.click("#login-button"); await page.waitForTimeout(1500); if (record.expectedResult === 'success') { await expect(page).toHaveURL(/inventory/); } else { const selector = page.locator("[data-test='error']"); await expect(selector).toBeVisible(); } }); }
- Гарантированное имя файла заканчивается на .spec.ts.
- Пробывал и testDir: '.', и testDir: './tests'.
Вопросы:
- Почему Playwright не обнаруживает никаких тестов (как средства запуска VS Code, так и CLI), хотя мой файл *.spec.ts существует?
- Какие-либо настройки VS Code необходимы для того, чтобы обозреватель тестов Playwright отображал средство выполнения?
Подробнее здесь: https://stackoverflow.com/questions/798 ... ests-found