0

这是我的黄瓜 when 语句的一个例子

基本交互.js


let aliasHref = 'aliasHref';
import {Given, When, Then} from 'cypress-cucumber-preprocessor/steps';

When(/I click link \'([^\']+)\'/, async (strSelector) => {
  cy.get(strSelector).should('have.attr', 'href').then(href => {
    cy.intercept(href).as(aliasHref);
  });
  cy.get(strSelector).click();
});

Then(/I redirect to url \'([^\']+)\'/, (strUrl) => {
  cy.wait(`@${aliasHref}`).its('request.url').should('eq', strUrl); // This passes
  cy.wait(`@${aliasHref}`).should('have.property', 'response.statusCode', 200); // This fails
  // cy.wait(`@${aliasHref}`).should('have.property', 'status', 200); // This fails

});

我不断收到错误

AssertionError: 预期 { Object (id, routeHandlerId, ...) } 具有属性“response.statusCode”

或者

AssertionError: 预期 { Object (id, routeHandlerId, ...) } 具有属性 'status'

4

1 回答 1

0

请尝试cy.wait(`@${aliasHref}`).its('response.statusCode').should('eq', 200)

于 2021-05-10T09:02:54.360 回答