cy.request不允许我进入下一个UI测试用例 [英] cy.request doesn't allowing me to go to next UI test cases

查看:92
本文介绍了cy.request不允许我进入下一个UI测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试同时集成UI和API测试用例

Trying to integrate both UI & API test cases

创建了两个文件:


  1. API测试- ->做登录并写令牌&将其保存到夹具文件中

  1. API test --> DO Login and writing token & saving it to fixture file

规范测试->使用用户名和密码进行真实登录,一旦通过测试用例,然后在下一个测试中首先通过使用cy.request使用由step1保存的令牌。根据响应键在搜索栏中搜索数据

Spec test -->Do REAL Login by using username and password and once test case pass then in next test first get the response by using cy.request using token which saved by step1. Based on response keys search the data in search bar

API测试文件:

it("Login Request API",function(){

        cy.request({
            method:"POST",
            url: POST URL,
            headers:{
             "content-type" : "application/json"
            },
            body : {
             "email": USER NAME,
             "password": PASSWORD
            },
            log: true
        }).then((response) => {
             // Parse JSON the body.
             expect(response.status).to.equal(200)
             let resbody = JSON.parse(JSON.stringify(response.body));
            cy.writeFile("File Path to store response",resbody)
         })
    });

C柏版本:3.8.3

执行上述测试后,它将重定向到第一个测试。不再进行进一步的测试

Once above test is executed then it redirect to first test . Not going to further tests

推荐答案

对于赛普拉斯3.8.3版:您可能需要检查您尝试创建的新文件的路径。

For Cypress Version 3.8.3: You may need to check the path of the new file you are trying to create. it is by default within the 'fixture' folder.

cy.request({
    method:"POST",
    url: POST URL,
    headers: {
      "content-type" : "application/json"
    },
    body : {
      "email": USER NAME,
      "password": PASSWORD
    },
    log: true
}).then((response) => {
    // Parse JSON the body.
    expect(response.status).to.equal(200);
    cy.writeFile("<path>/api.json", response.body); // <path> is with respect to cypress/fixture folder
});

根据我的测试:

这篇关于cy.request不允许我进入下一个UI测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆