【发布时间】:2020-01-20 12:42:08
【问题描述】:
考虑到下面的 API 响应,我想断言某个值在 JSON 结构中的确切位置。就我而言,forms 中 pikachu 的 name:
"abilities": [
{
"ability": {
"name": "lightning-rod",
"url": "https://pokeapi.co/api/v2/ability/31/"
},
"is_hidden": true,
"slot": 3
},
{
"ability": {
"name": "static",
"url": "https://pokeapi.co/api/v2/ability/9/"
},
"is_hidden": false,
"slot": 1
}
],
"base_experience": 112,
"forms": [
{
"name": "pikachu",
"url": "https://pokeapi.co/api/v2/pokemon-form/25/"
}]
我想扩展下面的代码 sn-p 不扫描整个身体,因为响应中有很多 name,而是通过 forms 准确定位:
describe('API Testing with Cypress', () => {
var baseURL = "https://pokeapi.co/api/v2/pokemon"
beforeEach(() => {
cy.request(baseURL+"/25").as('pikachu');
});
it('Validate the pokemon\'s name', () => {
cy.get('@pikachu')
.its('body')
.should('include', { name: 'pikachu' })
.should('not.include', { name: 'johndoe' });
});
提前非常感谢!
【问题讨论】:
-
欢迎来到 Stack Overflow。我不明白您所说的“宁可通过表格准确定位”是什么意思?