丝柏 + 黄瓜 - 相同的步骤定义

Dar*_*ony 2 cypress-cucumber-preprocessor

假设我有Feature1.feature 和Feature2.feature 文件。首先我有步骤:

Scenario: Test scenario1
Given   I Open the app
When    I Click on Tab1
Run Code Online (Sandbox Code Playgroud)

在第二个文件中我有:

Scenario: Test scenario2
Given   I Open the app
When    I Click on Tab2
Run Code Online (Sandbox Code Playgroud)

在step1.js文件的step_definitions文件夹下:

Given("I open the app", () => {
  cy.visit("/home");
});

When("I Click on Tab1", () => {
  cy.get('[title="Tab1"]'.click();
});
Run Code Online (Sandbox Code Playgroud)

在step_definitions文件夹下,我们有多个js文件(由每个测试用例分隔)。那么对于第二种情况,在step2.js中我是否需要再次定义“打开应用程序”步骤?:

Given("I open the app", () => {
  cy.visit("/home");
});
Run Code Online (Sandbox Code Playgroud)

或者它在steps_definition下的所有文件中进行全局查找?那么我只需要从以下开始:

When("I Click on Tab2", () => {
  cy.get('[title="Tab2"]'.click();
});
Run Code Online (Sandbox Code Playgroud)

但是,如果多个用户正在处理测试用例并且他们不小心在不同的文件中定义了相同的步骤,例如

在一个文件中

Given("I open the app", () => {
  cy.visit("/home");
});
Run Code Online (Sandbox Code Playgroud)

在其他文件中

Given("I open the app", () => {
  cy.visit("/news");
});
Run Code Online (Sandbox Code Playgroud)

正如我所读到的,每个场景都应该是独立的。但如果每个场景都有相同的步骤呢?我们只需在一个文件中定义它们一次。但如果其他人正在处理该文件,则可能会破坏我的场景。

Ord*_*ing 6

如果多个场景有两个步骤,您应该使用通用步骤:

可重用的步骤定义 我们还有一种方法来创建可重用的步骤定义。将它们放在 cypress/integration/common/ 中

示例:cypress/integration/common/i_see_string_in_the_title.js

import { Then } from "cypress-cucumber-preprocessor/steps";

Then(`I see {string} in the title`, (title) => {
  cy.title().should('include', title)
})
Run Code Online (Sandbox Code Playgroud)

摘自https://www.npmjs.com/package/cypress-cucumber-preprocessor