首页 > 解决方案 > 未找到测试/赛普拉斯无法检测此文件中的测试

问题描述

我目前正在学习赛普拉斯,并尝试参考我能找到的尽可能多的资源。我的我目前也在使用黄瓜插件,当我尝试运行赛普拉斯时,我不断收到“未找到测试”和“赛普拉斯无法检测到此文件中的测试”,除了空白屏幕之外,它并不明确正确的。我在这里引用了另一个关于此的问题,但它会丢失一个规范文件,这不是这里的问题。我已经根据文档导入了正确的步骤定义,但它也没有指向那个。

现在这是我的文件结构。

cypress -
    -integrations
        -BDD
           -ecommerce
              -ecommerce.spec.js
           - ecommerce.feature

在我的 cypress.json 文件中


    "testFiles":  "**/*.js",
    "baseUrl": "https://localhost:17843/GfmAdminConsole/",
    "env":{
        "url":"https://rahulshettyacademy.com"
    },
    "reporter": "mochawesome"
    
}

这是我要运行的代码

import {Given,When,Then,And} from 'cypress-cucumber-preprocessor/steps'
import HomePage from "./HomePage"
import ProductPage from "./ProductPage"
import CheckOutPg from "./CheckOutPg"







/// <reference types="Cypress" />
Given('I open ECommerce Page',()=>{
    cy.visit("https://rahulshettyacademy.com/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(){
    const homePage = new HomePage()
    const productPage = new ProductPage()
    homePage.getShopTab().click()
    
    
    testData.productName.forEach((product)=>{
        cy.selectProduct(product)
    })


    
    productPage.getCheckoutBtn().click()


})

And('Validate the total price of the items selected',()=>{
    let sum = 0
    let total;
    const checkOut = new CheckOutPg()
    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
    })
})

编辑:ecommerce.feature 文件

Feature: End to end Ecommerce validation


application Regression test
@focus
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 Thankyou

任何指导将不胜感激,并提前感谢您。

标签: cucumbercypresscucumberjs

解决方案


cypress.json根据https://github.com/TheBrainFamily/cypress-cucumber-preprocessor#cypress-configuration检查你的应该有

"testFiles": "**/*.feature"

推荐阅读