剧作家`“APIRequest”类型上不存在属性“get”

问题描述 投票:0回答:1

所以以下代码在 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'

我做错了什么?

typescript request get playwright
1个回答
0
投票

尝试从

request
导入
'@playwright/test'
,而不是从
'playwright'

© www.soinside.com 2019 - 2024. All rights reserved.