首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将柏树测试从旧版本迁移到最新版本引发错误

将柏树测试从旧版本迁移到最新版本引发错误
EN

Stack Overflow用户
提问于 2022-10-13 00:19:47
回答 1查看 239关注 0票数 4

我正在尝试将我的测试从Cypress 8.7.0版本迁移到Cypress 10.10.0版本。安装了最新版本,并执行了以下设置,但出现以下错误。使用以下版本:Cypress 10.10.0"@badeball/cypress-cucumber-preprocessor": "^11.4.0"node v18.4.0@bahmutov/cypress-esbuild-preprocessor": "^2.1.5"

Expected to find a global registry (this usually means you are trying to define steps or hooks in support/e2e.js, which is not supported) (this might be a bug, please report at https://github.com/badeball/cypress-cucumber-preprocessor)

代码语言:javascript
复制
Because this error occurred during a before each hook we are skipping all of the remaining tests.

我在e2e.js文件和support/index.js文件中添加了错误处理,但仍然无法解决这个问题。我有.env文件,它在根位置有环境变量。有人能就这个问题提出建议吗?

//详细错误日志:

代码语言:javascript
复制
Because this error occurred during a `before each` hook we are skipping all of the remaining tests.
    at fail (tests?p=tests/cypress/e2e/login/loginBase.feature:964:15)
    at assert (tests?p=tests/cypress/e2e/login/loginBase.feature:971:9)
    at assertAndReturn (tests?p=tests/cypress/e2e/login/loginBase.feature:975:9)
    at getRegistry (tests?

Cypress version : v10.10.0

//test/cypress/e2e/login/login.产

代码语言:javascript
复制
@regression
   @login
  Feature: Login to base url
  
    Scenario: Login to base url
    Given I go to base url

//step定义:

代码语言:javascript
复制
tests/cypress/stepDefinitions/login.cy.js  



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

When('I go to base url', () => {
  cy.visit(Cypress.config().baseUrl);
})

// test/cypress/support/index.js文件

代码语言:javascript
复制
    // Import commands.js using ES2015 syntax:
    import './commands'
    Cypress.on('uncaught:exception', (err, runnable) => {
      // returning false here prevents Cypress from
      // failing the test
      return false
    });

//测试/柏树/支持/e2e.js

代码语言:javascript
复制
    // Import commands.js using ES2015 syntax:
    import './commands'
 
    Cypress.on('uncaught:exception', (err, runnable) => {
        // returning false here prevents Cypress from
        // failing the test
        return false
    })

// ..cypress黄瓜-预处理器root //将此文件添加到项目根位置

代码语言:javascript
复制
    {
      "stepDefinitions": [
        "[filepath].{js,ts}",
        "tests/cypress/stepDefinitions/**/*.{js,ts}"
      ]
    }

// cypress.config.js

代码语言:javascript
复制
    const { defineConfig } = require('cypress')
    const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
    const addCucumberPreprocessorPlugin = require("@badeball/cypress-cucumber-preprocessor")
    const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild").createEsbuildPlugin;
    const dotenvPlugin = require('cypress-dotenv');
    
    async function setupNodeEvents(on, config) {
        await addCucumberPreprocessorPlugin.addCucumberPreprocessorPlugin(on, config);
        on(
            "file:preprocessor",
            createBundler({
                plugins: [createEsbuildPlugin(config)],
            })
        );
        //webpack config goes here if required
        config = dotenvPlugin(config)
        return config;
    }
    
    module.exports = defineConfig({
        e2e: {
            baseUrl: 'https://bookmain.co',
            apiUrl: 'https://bookmain.co/api/books/',
            specPattern: "tests/cypress/e2e/**/*.feature",
            supportFile: false,
            setupNodeEvents
        },
        component: {
            devServer: {
                framework: "next",
                bundler: "webpack",
            },
        },
    });

// package.json

代码语言:javascript
复制
"cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true,
    "stepDefinitions": "tests/cypress/stepDefinitions/**/*.{js,ts}",
    "cucumberJson": {
      "generate": true,
      "outputFolder": "tests/cypress/cucumber-json",
      "filePrefix": "",
      "fileSuffix": ".cucumber"
    }
  },
EN

回答 1

Stack Overflow用户

发布于 2022-10-13 23:34:41

在cypress.config.js中添加以下内容:

代码语言:javascript
复制
const {dotenvPlugin} = require('cypress-dotenv');

module.exports = (on, config) => {
  config = dotenvPlugin(config)
  return config
}

这将解决这个问题。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74049214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档