我正在尝试使用 BDD 运行测试。它将打开测试页面,但是当我要求它进入包含一些测试数据的页面对象时,我从赛普拉斯控制台收到以下消息。
有趣的是,在将页面对象添加为普通 mocha 测试之前,我已经运行了这个测试。这段代码完美地端到端运行。
那么这个错误是从哪里来的呢?
BDD 测试场景
场景:用户可以购买商品并将其交付到送货地址
Given I am on the Ecommerce page
When I add the mobile handsets to the shopping cart
And I verify the total price of shopping cart
Then I select the checkout button
When I will select my shipping location
And I agree to the terms and conditions checkbox
When I select the Purchase button
Then I will see an alert stating my order was successful, plus an ETA delivery
步骤定义文件
/// <reference types="Cypress" />
import { Given,When,Then,And } from "cypress-cucumber-preprocessor/steps";
import Homepage from "../../../support/pageObjects/Homepage";
import orderSummaryPage from "../../../support/pageObjects/orderSummaryPage";
import completeOrderPage from "../../../support/pageObjects/completeOrderPage";
const homepage = new Homepage()
const StartCheckout = new orderSummaryPage()
const CompleteOrder = new completeOrderPage()
Given ( 'I am on the Ecommerce page', () => {
cy.visit(Cypress.env('url')+"/angularpractice/")
})
When('I add the mobile handsets to the shopping cart',function () {
homepage.getShopTab().click()
this.data.mobileHandset.forEach(function(element) {// this custom commad will add items to your cart
cy.AddToCart(element)
});
StartCheckout.getBasketCheckoutButton().click()
} )//end of step
And('I verify the total price of shopping cart',() => {
//calculate shopping cart here
let sum=0
CompleteOrder.getProductCost().each(($e1, index, $list) =>{
const unitCost=$e1.text()
let res= unitCost.split(" ")
res= res[1].trim()
sum=Number(sum)+Number(res)
}).then(function()
{
cy.log(sum)
})
CompleteOrder.getBasketTotalCost().then(function(element)
{
const shopCartTotal=element.text()
var res= shopCartTotal.split(" ")
var total= res[1].trim()
expect(Number(total)).to.equal(sum)
})
} )//end of step
Then('I select the checkout button',() => {
StartCheckout.getStartCheckoutButton().click()
} )//end of step
When('I will select my shipping location',() => {
CompleteOrder.getShippingCountry().type('United Kingdom')
CompleteOrder.getShippingCountryConfirm().click()
} )//end of step
And('I agree to the terms and conditions checkbox',()=> {
CompleteOrder.getTermsConditionsCheckbox().click({force: true})
})//end of step
When('I select the Purchase button',()=> {
CompleteOrder.getPurchaseButton().click()
})
Then('I will see an alert stating my order was successful, plus an ETA delivery',()=> {
CompleteOrder.getPurchaseAlert().then(function(element){
const actualText= element.text()
expect(actualText.includes('Success')).to.be.true
})
})