【问题标题】:All the JBehave steps are marked as PENDING when executing them in SerenityBDD在 SerenityBDD 中执行时,所有 JBehave 步骤都标记为 PENDING
【发布时间】:2019-01-28 20:59:26
【问题描述】:

我正在尝试使用 Serenity BDD 和 JBehave 框架中的登录功能执行一个非常简单的故事。但是,我所有的步骤都被标记为 PENDING 并被跳过。请帮助我了解我的代码到底出了什么问题。

我已确保我的故事文件和步骤文件中的步骤完全匹配,并且在空格或制表符方面没有差异。

故事文件

Story: Application Login

Narrative:
As an user, I want to successfully login into the application upon providing valid credential

Scenario:  Login with valid credential
Given Launch the application
When Input the credential
Then Login to the application

步类

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import net.thucydides.core.annotations.Steps;
import tests.LoginTest;

public class LoginSteps {

    @Steps
    LoginTest usr;

    @Given("Launch the application")
    public void launchApp() {
        usr.beforeSuite();
        usr.launchApplication();
    }

    @When("Input the credential")
    public void enterCredential() {
        usr.submitLoginForm();
    }

    @Then("Login to the application")
    public void loginApp() {
        usr.loginCheck();
        usr.afterSuite();
    }
}

测试类

package suite;

import net.serenitybdd.jbehave.SerenityStory;

public class Login extends SerenityStory {

}

POM.XML

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.selenium.bdd.serenity</groupId>
<artifactId>seleniumBDDSerenity</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>seleniumBDDSerentity</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.5</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.14.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>2.0.33</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-jbehave</artifactId>
        <version>1.44.0</version>
    </dependency>
    <dependency>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-core</artifactId>
        <version>4.3.5</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>3.0.0-M3</version>
            <configuration>
                <includes>
                    <include>**/suite/*.java</include>
                </includes>
                <skipTests>false</skipTests>
                <failIfNoTests>false</failIfNoTests>
            </configuration>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>net.serenity-bdd.maven.plugins</groupId>
            <artifactId>serenity-maven-plugin</artifactId>
            <version>2.0.33</version>
            <executions>
                <execution>
                    <id>serenity-reports</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

日志

(BeforeStories)

Running story stories/authentication/Login.story
Application Login
(stories/authentication/Login.story)
Using timeout for story Login.story of 300 secs.

Scenario: Login with valid credential
Given Launch the application (PENDING)
When Input the credential (PENDING)
Then Login to the application (PENDING)

@Given("Launch the application")
@Pending
public void givenLaunchTheApplication() {
  // PENDING
}

@When("Input the credential")
@Pending
public void whenInputTheCredential() {
  // PENDING
}

@Then("Login to the application")
@Pending
public void thenLoginToTheApplication() {
  // PENDING
}

(AfterStories)

【问题讨论】:

  • 我没有在我的 JBehave 中使用 Serenity,但它看起来有点像 Cucumber,如果它找不到步骤,它要么建议步骤,要么是创建的某处的步骤文件(基于您的输出),默认方法名称全部为空(待定),并且它使用该步骤文件而不是您的步骤文件。当我告诉 JBehave 从故事文件生成步骤时,这就是 JBehave 使用我的插件创建的存根文件。
  • @BillHileman 但这是大多数 Jbehave 示例在网上概述的方式,并且对它们没有任何问题。如果您有任何解决问题的建议,请告诉我。
  • 我认为您的运行时正在查找和使用某个 java 步骤文件,它不是您编写和发布的文件。在您的项目树中查找您无法解释的源文件。几乎可以肯定有一个包含您发布的日志部分中的确切代码。另外,再次因为我不使用 Serenity,我不知道这是否适用,但我必须有一个 testrunner 类。你没有表现出任何类似于测试运行者的东西。
  • 谢谢。我已将我的测试类扩展到 SerenityStory,后者又扩展到 JUnitStories,它通过它识别我的 Story 文件并执行它。另外,我在我的项目中只有一个步骤文件,我在这里提到过。不知道为什么它尝试引用它在运行时创建的默认方法,而不是匹配项目中的步骤文件。

标签: annotations pojo jbehave serenity-bdd scenarios


【解决方案1】:

我遇到了同样的问题,我已经解决了。将运行器类移动到放置 LoginSteps 的同一文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多