当我使用 cucumber 和 playwright 时,我无法使用 GET、POST、PUT 任何 http 请求。在步骤定义中,我尝试使用 request.get 但它说不是函数。当我创建一个新的上下文时,我可以完成如何使用 cucumber 中的 playwright 配置进行 API 测试的所有操作
Given("I hit the endpoint {string}", async (request) => {
const response = await request.get("/metrics", {
headers: {
Authorization: auth_token,
},
});
console.log(response);
});
when I create a new context I am able to send request
const context = await request.newContext({
baseURL: 'https://habitat-energy-development.eu.auth0.com/'
});
const response = await context.post('/oauth/token',{
headers: {
"Accept": 'application/vnd.github.v3+json',
},
data: {
"grant_type": "password,
"username":'',
"password":'',
"client_id": '',
"client_secret": '',
"audience":
}
});
expect(response.ok()).toBeTruthy();`
我也在整个互联网、官方文档、视频、教程、指南、udemy 课程中进行了高低搜索,也遇到了同样的问题,我被困在这里:
错误:函数使用多个异步接口:回调和承诺 使用回调接口:不返回承诺 使用 Promise 接口:删除函数的最后一个参数
const { Given, When, Then, defineStep } = require('@cucumber/cucumber')
const { chromium, firefox } = require('playwright')
Given('I visit a login page', async ({ request }) => {
const baseURL = 'https://pokeapi.co/api/v2/pokemon'
const response = await request.get(`${baseURL}/1`)
expect(response.status()).toBe(200)
})
Playwright BDD Api 测试肯定是未来的要求吗?难道还没有一个人解决这个问题并实现这个问题吗?