下面是我的cypress-cucumber项目结构。
如果我想使用 Home.feature 中的 Login.feature、Logout.feature 中的步骤,该怎么做?
基本上我想在主页中重复使用登录和注销,而不是在主页中再次重写它们
Login.feature
Feature: Successful Login into the application
Background:
Given Launch he application
Scenario: Login
Then I enter Username "xxxx"
Then I enter Password "xxxx"
Then I click on Login Button
Home.feature
Feature: Home Page Verification
Scenario: Home Page
Then I am on Home Page
Logout.feature
Feature: Logout from the application
Scenario: Log Out Page
Then I Log Out
LogoutSteps.js
/// <reference types="Cypress" />
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
import { Logout } from "../../Pages/LogoutPage"
const logout = new Logout()
Then("I log out", () => {
logout.clickLogout()
})
HomeSteps.js
// <reference types="Cypress" />
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
import { Login } from "../../Pages/LoginPage"
import { Home } from "../../Pages/HomePage"
import { Logout } from "../../Pages/LogoutPage"
const login = new Login()
const home = new Home()
const logout = new Logout()
Then("I am on Home Page", () => {
home.verifyHomePage()
home.searchfield()
})
您尚未提供配置详细信息,但这听起来像是常见步骤定义的情况。
例如
{
"stepDefinitions": [
"cypress/e2e/[filepath].js", // 1) steps by feature
"cypress/e2e/common-step-definitions/*.js" // 2) common to all
]
}
/home/john.doe/my-project
└── cypress
└── e2e
├── foo
│ ├── a.feature
│ └── a.js
├── bar
│ ├── b.feature
│ └── b.js
└── common-step-definitions
├── 1.js
└── 2.js
但是由于您有一个文件夹用于步骤,因此这取决于您如何配置。
如果您使用模式#2,您应该能够引用任何功能中的任何步骤:
{
"stepDefinitions": [
"cypress/e2e/step-definitions/*.js" // use any step in any feature
]
}