简体   繁体   English

我使用 Cypress/Cucumber 不断收到 Step definiton 错误

[英]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 建议使用此文件夹结构。

See doc here .请参阅此处的文档。

- cypress/
  - integration/
    - feature1.feature
    - feature1/
      - feature1.js
    - feature2.feature
    - feature2/
      - feature2.js

So:所以:

  1. Create your .feature file in cypress/integrationcypress/integration创建您的.feature文件
  2. Create a folder with the same name as your .feature file, also in cypress/integration创建一个与.feature文件.feature文件夹,也在cypress/integration
  3. Create a .js file in the newly created folder with your step definitions在新创建的文件夹中使用您的步骤定义创建一个.js文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:步骤实现缺少:[step_definition] with cypress &amp; Cucumber 使用示例场景大纲时 - Error: Step implementation missing for: [step_definition] with cypress & Cucumber when using Scenario outline with example 如果我使用 cypress-cucumber,是否必须为每个特征文件创建 Step definition 文件夹? - Do I have to create Step definition folder for each feature file if I am using cypress-cucumber? Cypress Cucumber Step 运行多步 - Cypress Cucumber Step running multiple steps 在 Cypress Cucumber 中导入依赖项时出错 - Error importing dependency in Cypress Cucumber 我正在做 LWC Superbadge 第 6 步。无法检索描述符的元数据是我不断收到的错误 - I'm doing the LWC Superbadge Step 6. Unable to retrieve metadata for descriptor is the error I keep getting 使用黄瓜JS时错误“ HookUndefined Step”是什么意思? - what does the error “HookUndefined Step” mean when using cucumber JS? cypress cucumber - 如何识别调用步骤定义的功能文件? - cypress cucumber - How to identify the which feature file calling step definition? Cypress Cucumber,如何一步从页面获取数据并在另一个场景步骤中使用它 - Cypress Cucumber, how Get to data from page in one step and use it another scenario step 赛普拉斯-执行“赛普拉斯打开”时出错 - Cypress - Getting error while executing 'cypress open' 每当我尝试运行 Cypress Suite 时都会出现以下错误 - Getting below error whenever I try to run Cypress Suite
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM