赛普拉斯中多个具有相同名称的网络请求

时间:2020-04-08 09:03:11

标签: testing automation automated-tests cypress

我对赛普拉斯的网络请求有疑问。我想通过等待xhr请求状态为200来等待页面加载。基本上,我必须从下拉列表中选择一个值,然后我要等待直到加载带有约会的日历。但是我的测试有时会失败,有时会通过,因为我在柏树中以不同的形式(如下面的图像所示)收到了xhr请求: enter image description here

enter image description here

如果有人可以在运行测试之前清除浏览器网络请求,或者是否有办法多次击中该请求?谢谢

我的代码也在下面:


    waitForAppointmentsToLoad() {
    const year = Cypress.moment().format('YYYY');
    const month = Cypress.moment().format('M');
    const startDay = Cypress.moment().startOf('week').format('DD');
    const endDay = Cypress.moment().endOf('week').format('DD');
    let nextMonth;
    if (startDay > 24) {
        nextMonth = monthsMapperAsNumber[month];
    } else {
        nextMonth = monthsMapperAsNumber[month - 1];
    }
    cy.server();
    cy.route({
        method: 'GET',
        url: `services-beta/home-therapy/appointments?type=clinic&id=${currentClinic}&start=${year}-${nextMonth}-${startDay}&end=${year}-${nextMonth}-${endDay}`,
        response: []
    }).as('waitAppointmentsToLoad');

    cy.wait(['@waitAppointmentsToLoad']).then((xhr) => {
        expect(xhr.status).to.eq(200);
    });
}

0 个答案:

没有答案