Как использовать какое-то время l oop в кипарисе? Элемент управления НЕ вводит l oop при запуске этого файла spe c? То, как я опрашиваю, задание правильное? - PullRequest
0 голосов
/ 04 мая 2020

То, как я опрашиваю задачи для asyn c POST, это правильно ??? Поскольку управление программой не вводит 'while' l oop в файл spe c. Пожалуйста помоги! Предыдущий запрос: Как вернуть значение из пользовательской команды 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
        })
    }
})

-------------------------

//In Commands.js file, I have written a function to return taskStatus, which I am using it in spec 
 file above

Commands.js -

Cypress.Commands.add("pollTask", (NEWURL, token) => {

    cy.request({
        method: 'GET',
        url: NEWURL ,
        failOnStatusCode: false,
        headers: {
            'x-auth-token': token
        }
    }).as('fetchTaskDetails')


    cy.get('@fetchTaskDetails').then(function (response) {
        const taskStatus = response.body.task.status
        cy.log('task status: ' + taskStatus)
        cy.wrap(taskStatus)
    })

})  
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...