小编Roh*_*ain的帖子

如何在cypress中使用while循环?运行此规范文件时,控制是否不进入循环?我轮询任务的方式是否正确?

我轮询异步 POST 调用任务的方式是否正确???因为程序控制不会进入spec文件中的“while”循环。请帮忙!上一个查询:如何从 Cypress 自定义命令返回值

beforeEach(function () {
    cy.server()
    cy.route('POST', '/rest/hosts').as("hosts")
})


it('Create Host', function () {

    let ts =''
    let regex = /Ok|Error|Warning/mg 

    // Some cypress commands to create a host. POST call is made when I create a host. I want to poll 
    // task for this Asynchronous POST call.

    cy.wait("@hosts").then(function (xhr) {
        expect(xhr.status).to.eq(202)
        token = xhr.request.headers["X-Auth-Token"]
        NEWURL = Cypress.config().baseUrl + xhr.response.body.task
    })


    while((ts.match(regex)) === null) { 
        cy.pollTask(NEWURL, token).then(taskStatus => {
        ts= taskStatus
        })
    }
})

------------------------- …
Run Code Online (Sandbox Code Playgroud)

cypress

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

cypress ×1