Cypress Cucumber 测试启动失败

问题描述 投票:0回答:0

无论我做什么,测试都会崩溃。值得一提的是,这个测试实际上不会通过,但此时它甚至不会尝试运行。这是错误:

Step implementation missing for "I navigate to the website".

We tried searching for files containing step definitions using the following search pattern templates:

  - cypress\e2e\features/[filepath]/*/.{js,mjs,ts,tsx}

  - cypress\e2e\features/[filepath].{js,mjs,ts,tsx}

  - cypress/support/step_definitions/*/.{js,mjs,ts,tsx}

These templates resolved to the following search patterns:

  - cypress\e2e\features\login\*.{js,mjs,ts,tsx}

  - cypress\e2e\features\login.{js,mjs,ts,tsx}

  - cypress\support\step_definitions\*.{js,mjs,ts,tsx}

These patterns matched no files containing step definitions. This almost certainly means that you have misconfigured stepDefinitions.

You can implement it using the suggestion(s) below.

  Given("I navigate to the website", function () {

    return "pending";

  });

login.feature

cypress\e2e\features

Feature: Test login

    I want to login into the website

    Scenario: Login as existing user
        Given I navigate to the website
        When I enter user name and password
        When User click on sign in button
        Then Validate the title after login

测试 -

cypress\e2e\features
中的 website.js。重命名该文件或将其移动到不同的目录并不能解决问题。

import { When, Then, Given } from "@badeball/cypress-cucumber-preprocessor";

Given("I naviagate to the website", () => {
    cy.visit("https://www.saucedemo.com/")
});

When("I enter user name and password", () => {
    cy.get("#username").type("standard_user");
    cy.get("#password").type("secret_sauce");
});

When("User click on sign in button", () => {
    cy.get("#SubmitLogin").click();
});

Then("Validate the title after login", () => {
    cy.title().should("eq", "My account - My Store")
});

Cypress.config.js

const { defineConfig } = require("cypress");
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild");

async function setupNodeEvents(on, config) {
  // This is required for the preprocessor to be able to generate JSON reports after each run, and more,
  await preprocessor.addCucumberPreprocessorPlugin(on, config);

  on(
    "file:preprocessor",
    createBundler({
      plugins: [createEsbuildPlugin.default(config)],
    })
  );

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}

module.exports = defineConfig({
  e2e: {
    setupNodeEvents,
    specPattern: "cypress/e2e/features/*.feature"
  },
});

几乎可以肯定配置有问题。这非常令人困惑,但几乎所有如何将 Cucumber 连接到 Cypress 的教程都是不正确的,并且要求您访问不存在的文件。我设法找到了一个实际上是正确的,但如您所见,它并没有真正起作用。我没有想法,我不知道如何使用这个框架,尤其是在没有教程的情况下。

javascript cucumber cypress
© www.soinside.com 2019 - 2024. All rights reserved.