如何在cucumber-jvm中的另一个功能中调用功能?

Ran*_*ray 5 junit selenium cucumber cucumber-jvm

我有一个功能文件

Feature: Create Profile

Scenario: Create Profile
Given I want to create a profile
When I create a profile
Then I should be navigated to Home Page
Then sign out link should exist
Run Code Online (Sandbox Code Playgroud)

因此,上面的命令运行正常,并断言确实返回了主页,并且存在退出链接。

现在,我还有另一个功能文件。

Feature: Go to my account page

Scenario: Go to my account page
Given I want to go to my account page    
When I go to my account page
Then I should be navigated to the my account page
Run Code Online (Sandbox Code Playgroud)

在运行"When I go to my account page"步骤之前,用户应"Create Profile"

所以我要做的是

When I create a profile
Then I should be navigated to Home Page
Then sign out link should exist
Run Code Online (Sandbox Code Playgroud)

之前When I go to my account page

但是我看到我重复了“创建配置文件”功能/方案中的相同代码。

如何在“转到我的帐户页面”方案中运行整个“创建个人资料”功能/方案?

我在Selenium和JUnit中使用Cucumber-jvm。

Art*_*rov 1

您看到后台 DSL 功能了吗?它适用于您的情况,但可能不是您真正要问的。在这种情况下,您可以要求用户通过以下方式创建配置文件:

Feature: Create Profile
  Background:
    Given I create a profile
    And I should be navigated to Home Page
    And sign out link should exist

  Scenario: Create Profile
    # do nothing because all actions are in background

  Scenario: Go to my account page
    When I go to my account page
    Then I should be navigated to the my account page
Run Code Online (Sandbox Code Playgroud)

但是您必须将两个功能文件合并为一个功能文件。

另请查看 @Before 和 @After 黄瓜注释 - 这样,如果以前的解决方案不适合您,您可以运行一些代码来初始化(或创建)测试帐户。