[英]I keep getting a Step definiton error using Cypress/Cucumber
I am getting a "Step implementation missing for: I open ecommerce page" when I try to run my Cypress/Cucumber test.feature file.当我尝试运行我的 Cypress/Cucumber test.feature文件时,我收到“缺少步骤实现:我打开电子商务页面” 。
I was referring to another post to help me but didn't manage to help clear up my own issue.我指的是另一篇文章来帮助我,但没有设法帮助解决我自己的问题。 The link for the post I used is below
我使用的帖子的链接在下面
Cypress.io and Cucumber.io testing integration, Step implementation missing for: Cypress.io 和 Cucumber.io 测试集成,缺少步骤实现:
So here is what everything I have for this.所以这就是我所拥有的一切。
As a start here is my current file structure that I have adjusted首先是我调整的当前文件结构
-cypress
-integration
-test
-test.feature
-test.js
Here is my test.feature file这是我的test.feature文件
Feature: End to end GFM validation
Scenario: Ecommerce products delivery
Given I open ecommerce page
When I add items to cart
And Validate the total prices
Then select the country submit and verify thank you
Here is the test.js file with the step definitions这是带有步骤定义的test.js文件
/// <reference types="Cypress" />
import { Given,When,Then,And } from 'cypress-cucumber-preprocessor/steps'
import HomePage from "../../support/classes/HomePage"
import ProductPage from "../../support/classes/ProductPage"
import CheckOutPg from "../../support/classes/CheckOutPg"
const homePage = new HomePage()
const productPage = new ProductPage()
const checkOut = new CheckOutPg()
Given("I open ecommerce page",()=>{
cy.visit(Cypress.env('url')+"/angularpractice/")
})
//When using hook to load data, use non-es6 syntax for a function.....might need to check if this was updated in later releases
When('I add items to cart',function(){
homePage.getShopTab().click()
testData.productName.forEach((product)=>{
cy.selectProduct(product)
})
productPage.getCheckoutBtn().click()
})
And('Validate the total prices',()=>{
let sum = 0
let total;
checkOut.getItemPrices().each(($el,index,$list)=>{
let price = $el.text().split(' ')[1].trim()
sum = Number(sum) + Number(price);
}).then(()=>{
cy.log(sum)
})
checkOut.getTotal().then((el)=> {
total = el.text().split(' ')[1].trim()
expect(Number(total)).to.eq(sum)
})
})
Then('select the country submit and verify thank you',()=>{
cy.get(':nth-child(6) > :nth-child(5) > .btn').click()
cy.get('#country').type('United States')
cy.wait(6000)
cy.get('.suggestions > ul > li > a').click()
cy.get('input[type="checkbox"]').check({force:true})
cy.get('.ng-untouched > .btn').click()
cy.get('.alert').then((el)=>{
const text = el.text()
expect(text.includes('Success')).to.be.true
})
})
I added the stepDefinitions in my package.json, and set the nonGlobalStepDifitions attribute to true as per cucumber docs when the the path for stepDefinition is set to "cypress/integration" .我说在我的package.json的stepDefinitions,并且当stepDefinition的路径设置为“柏/一体化” nonGlobalStepDifitions属性设置为true为每黄瓜文档。
"cypress-cucumber-preprocessor": {
"stepDefinitions": "cypress/integration",
"nonGlobalStepDefinitions": true,
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/cucumber-json",
"filePrefix": "",
"fileSuffix": ".cucumber"
}
}
I am not sure if I presented the context well on this, so I am open to any suggestion.我不确定我是否很好地介绍了上下文,所以我愿意接受任何建议。 Other than that is anyone able to assist me to see where this might have gone wrong?
除此之外,有没有人能够帮助我看看这可能出了什么问题?
Cypress-cucumber-preprocessor recommends this folder structure when you set "nonGlobalStepDefinitions": true
and "stepDefinitions": "cypress/integration"
in package.json
.当您在
package.json
设置"nonGlobalStepDefinitions": true
和"stepDefinitions": "cypress/integration"
,Cypress-cucumber-preprocessor 建议使用此文件夹结构。
- cypress/
- integration/
- feature1.feature
- feature1/
- feature1.js
- feature2.feature
- feature2/
- feature2.js
So:所以:
.feature
file in cypress/integration
cypress/integration
创建您的.feature
文件.feature
file, also in cypress/integration
.feature
文件.feature
文件夹,也在cypress/integration
.js
file in the newly created folder with your step definitions.js
文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.