所以以下代码在 test.spec.ts 中对我有用:
//@ts-check
import { test, request } from '@playwright/test'
test('api test - to see if Playwright API calls are working', async ({ request }) => {
const response = await request.get(`https://catfact.ninja/fact`);
const statusCode = response.status()
const responseBody = JSON.parse(await response.text())
)}
所以我想将这个调用提取到一个单独的模块中。我在单独的文件中尝试过:
import { request } from "playwright";
export async function getCatInfo() {
const response = await request.get(`https://catfact.ninja/fact`)
}
我在 VS Code 中遇到错误:
Property 'get' does not exist on type 'APIRequest'
我做错了什么?
尝试从
request
导入 '@playwright/test'
,而不是从 'playwright'