处理单个API调用的多个API调用

回首 测试交流1 112字数 832阅读模式
摘要在我的团队中,我们正试图为业务逻辑的一个非常常见的操作实现一个命令,但我在处理其实现时遇到了问题。 基本上: 我们必须检索一个数组。。。

在我的团队中,我们正试图为业务逻辑的一个非常常见的操作实现一个命令,但我在处理其实现时遇到了问题。
基本上:

  1. 我们必须找回一个 对象数组 (GET)。文章源自玩技e族-https://www.playezu.com/193164.html

  2. 对于每个对象,我们必须检索(获取)另一个 其父体内的物体.文章源自玩技e族-https://www.playezu.com/193164.html

  3. 对于每个子对象(child),我们必须 检查条件 如果它是我们想要的条件,我们检索子对象,否则我们传递null。文章源自玩技e族-https://www.playezu.com/193164.html

Q: 我该如何处理 依赖于单个API调用的多个API调用 没有跳出赛扬链?文章源自玩技e族-https://www.playezu.com/193164.html

这是我当前的实现(不起作用,但有点解释了想要的逻辑)文章源自玩技e族-https://www.playezu.com/193164.html

Cypress.Commands.add('myCommand', (sumCriteria: Function, anotherCriteria: Function) => {
// I only retrieve fathers with certain criteria
return cy.request('GET', fathersUrl).its('body').then(fatherObjects => {
return fatherObjects.filter(father => father.childs.length && father.childs.find(sumCriteria))
}).then(filteredFathers => {
filteredFathers.forEach(father => {
// For each father I retrieve a single child
const targetChildId = father.childs.find(sumCriteria).id;
// For each single child I retrieve its data and evaluate if it has the needed criteria
cy.request('GET', `${childsUrl}/${targetChildId}`)
.its('body')
.then(property => anotherCriteria(property))
})

})

提前感谢!文章源自玩技e族-https://www.playezu.com/193164.html

软件测试自学文章源自玩技e族-https://www.playezu.com/193164.html 文章源自玩技e族-https://www.playezu.com/193164.html

玩技站长微信
添加好友自动发送入群邀请
weinxin
rainbow-shownow
玩技官方公众号
官方微信公众号
weinxin
PLAYEZU
 
  • 版权提示:本站仅供存储任何法律责任由作者承担▷诈骗举报◁▷新闻不符◁▷我要投稿◁
    风险通知:非原创文章均为网络投稿真实性无法判断,侵权联系2523030730
    免责声明:内容来自用户上传发布或新闻客户端自媒体,切勿!切勿!切勿!添加联系方式以免受骗。
  • 原创转载:https://www.playezu.com/193164.html
    转载说明: 点我前往阅读>>>
    • danh
      danh 9

      简化代码并应用 承诺。全部()…
      Cypress.Commands.add(‘myCommand’, (sumCriteria: Function, anotherCriteria: Function) => {
      return cy.request(‘GET’, fathersUrl).its(‘body’).then(fatherObjects => {
      const filteredFathers = fatherObjects.filter(father => father.childs.find(sumCriteria));
      const promises = filteredFathers.map(father => {
      const targetChildId = father.childs.find(sumCriteria).id;
      return cy.request(‘GET’, `${childsUrl}/${targetChildId}`)
      .its(‘body’)
      .then(property => anotherCriteria(property))
      });
      return Promise.all(promises);
      });
      })

      注意:(1)无需返回过滤器,因为它是异步的。(2) 在过滤器内,无需检查子项。长度(&A)&find,因为find在空数组中找不到任何东西,(3)在数组中收集get承诺,并返回一个承诺,当所有承诺都解决时,该承诺就会解决。

    匿名

    发表评论

    匿名网友
    确定