当前位置: 首页 > 知识库问答 >
问题:

用Vue、柏树和cucumber测试时如何使用类?

穆修杰
2023-03-14

我的babel.config.js文件是:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ]
}

你知道如何让cli-plugin-babel与cucumber Cypress一起工作吗?

原始消息:我有一个test.feature文件,执行test.step.js文件中定义的步骤。以下是我的test.spec.js的内容

import { When, Then } from 'cypress-cucumber-preprocessor/steps';
import { HomePage } from './pages/home.page';

When(/^I open the Home page$/, () => {
    let homePage = new HomePage();
    homePage.goTo();
});

Then(/^I see "([^"]*)" in the main heading$/, msg => {
    cy.contains('h1', msg)
});

export class HomePage {
    goTo() {
        cy.visit("/");
    }
}
npm run test:e2e

Oops...we found an error preparing this test file:

  tests/e2e/features/Test.feature

The error was:

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'


This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

- A missing file or dependency
- A syntax error in the file or one of its dependencies

Fix the error in your code and re-run your tests.

当我使用:

export function goToHomePage() {
    cy.visit("/");
}

您可以在GitHub上签出我的项目:https://github.com/truar/cloudcmr-v2(传递情况为分支主,失败情况为分支pageObject_pattern)。

我假设这是与ES6和柏树有关的东西...但我显然不知道这是怎么回事。此外,我在网上找到的所有东西都说柏树cucumber和打字稿,我不用...

共有1个答案

越勇
2023-03-14

我找到答案了。有关更多详细信息,请参见此公关:https://github.com/cypress-io/cypress/issues/2945

基本上,巴别塔7号和柏树3号之间存在不相容性。我必须更改babel.config.js文件:

module.exports = process.env.CYPRESS_ENV
    ? {}
    : {
          presets: ["@vue/cli-plugin-babel/preset"]
      };

这只是一个变通办法,而不是真正的解决办法。我们在运行赛普拉斯时必须禁用巴别塔。

 类似资料:
  • 我有两张清单。一个包含,另一个包含那些保存在求和树中的

  • 试图实现硒cucumber测试而不是JUnit。 我的疑问是 testng中@Runwith(Cucumber.class)的替代选项是什么

  • 如何使用Maven在以下位置运行cucumber测试。 源文件夹'src/main/java'和'src/main/resources'包括在每个源文件夹中创建的包'com.testing.testproject.login'中的步骤定义和功能文件。 这是我的POM文件: 提前道谢。

  • 我正在尝试运行一个使用Mockito的JUnit cucumber测试。这是我遇到的问题。在我的cucumber赛跑课上,我有 在我的常规JUnit测试中 鉴于我一次只能有一个@RunWith,我如何将Mockito与cucumber结合使用呢?

  • 我有一个简单的单元测试来确保应用程序的主窗口被解除: AbstractMainWindowTest是: ScaleRuler是我的框架,它暂时什么也不做,只是setundered(真)。测试运行良好。如何从Cucumber中执行相同的测试? 我尝试使用WindowAspectSteps来扩展AbstractMainWindowTest,但是窗口变量仍然为null。