【发布时间】:2020-12-08 04:48:47
【问题描述】:
我正在尝试在请求正文上声明,以确保正确的新测试卡作为订单的一部分通过。
it("User clicks confirm & pay button to complete order", () => {
cy.intercept("/api/checkout/payandcommit").as("placeOrder");
cy.placeOrderAndPay();
cy.wait("@placeOrder")
.its("response.statusCode")
.should("eq", 200)
.its("request.body")
.should("include", "cardNumber", 370000000000002);
});
验证状态码后一切正常。
这是抛出的错误:
Timed out retrying: cy.its() errored because the property: request does not exist on your subject.
cy.its() waited for the specified property request to exist, but it never did.
If you do not expect the property request to exist, then add an assertion such as:
cy.wrap({ foo: 'bar' }).its('quux').should('not.exist')
如果我注释掉状态码断言,则会抛出这个新错误:被测对象必须是数组、映射、对象、集合、字符串或弱集,但对象已给定。
我们将不胜感激任何帮助完成这项工作!
【问题讨论】:
-
从一个步骤到下一个步骤产生的主题正在改变 -
cy.wait("@placeOrder")产生一个“拦截对象”,但.its("response.statusCode")产生数字 200,这是.its("request.body")看到的,而不是拦截对象。 -
@HiramK.Hackenbacker 感谢您的快速回复!如果我注释掉 statusCode 断言,我会遇到“测试的对象必须是数组”错误。有关如何解决此问题并让 statusRequest 和 request.body 检查正常工作的任何提示?
-
好吧,可能是拦截没有
request.body属性。您可以通过cy.wait("@placeOrder").then(interception => console.log(interception))检查拦截。 -
谢谢,这真的很方便。这是注销拦截时返回的内容。请求:正文:accountRegistrationPreferences: {email: ""} paymentDetails: Array(1) 0: billingAddress: {address: {...}, contactInfo: {...}, personalInfo: {...}} cardNumber: "370000000000002" cardType: "AmericanExpress " cvv: "7373" defaultPayment: false expirationMonth: "03" expirationYear: "2030" type: "creditCard3DS"
标签: cypress