【问题标题】:Getting no result when run through cucumber. Trying to implement BDD通过黄瓜运行时没有结果。尝试实现 BDD
【发布时间】:2015-12-22 05:03:32
【问题描述】:

已经尝试了几乎所有在 SO 上的解决方案,但这里仍然缺少一些东西。

我创建了简单的 JAVA 程序,为黄瓜添加了功能文件和类。当我运行时,我得到了输出:

@Search 场景大纲:成功打开 Google.com [90m# Open_Google.feature:4[0m [36mGiven [0m[36mUser 是空白页[0m [36m当[0m[36m用户输入网址[0m [36m然后[0m[36mGoogle网站应该打开[0m

0 场景

0 步

0m0.000s

功能文件:

Feature: Open Google WebSite

@Search
Scenario Outline: Successful Open Google.com
Given User is with blank page
When User enter URL
Then Google WebSite should open 

测试运行器类:

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;


@RunWith(Cucumber.class)
@CucumberOptions(

        features = "Feature"

        )

public class TestRunner {

}

测试用例类:

public class cucumber_test {

    public static WebDriver driver;

    public static void main(String[] args) {
        // TODO Auto-generated method stub



        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
        driver = new ChromeDriver();

        driver.get("http://www.google.com");
        driver.manage().window().maximize();

        System.out.println("Google open successfully");
    }

}

使用 Selenium Webdriver、JAVA、Junit 和 cucumber。

我做对了吗?黄瓜的使用方法正确吗?

【问题讨论】:

    标签: java selenium-webdriver junit cucumber


    【解决方案1】:

    跑步者似乎无法找到您的功能文件。它位于资源中吗?如果是,请尝试引用整个类路径,如

    import org.junit.runner.RunWith;
    
    import cucumber.api.CucumberOptions;
    import cucumber.api.junit.Cucumber;
    
    
    @RunWith(Cucumber.class)
    @CucumberOptions(
    
        features = "classpath:com/yourgroup/yourartifact/cucumber/features"
    
        )
    
    public class TestRunner {
    
    }
    

    以上只是一个示例,当然您必须根据功能所在的位置更改该类路径。

    【讨论】:

    • 感谢您的帮助,现在它说 _ 在 [classpath:Cucumber_Sample/Feature] 中找不到任何功能
    【解决方案2】:

    您需要参考功能的位置和步骤定义。跑步者应该看起来像这样:

    import org.junit.runner.RunWith;
    
    import cucumber.api.CucumberOptions;
    import cucumber.api.junit.Cucumber;
    
    
    @RunWith(Cucumber.class)
    @CucumberOptions(
        features = {"path/to/features/"},
        glue = {"classpath:package.name.of.stepsDefinitions"},
    )
    
    public class TestRunner {
    
    }
    

    注意功能文件的路径符号 以及 胶合代码(步骤定义)的封装符号

    【讨论】:

    • 我是否需要为 stepsDefinitions 创建任何其他文件?
    • 你能提供你的项目结构吗?我认为这是 isba 路径问题。现在一步定义文件就足够了。
    【解决方案3】:

    我相信你仍然面临同样的问题。你可以试试这个。

     import org.junit.runner.RunWith;
    
       import cucumber.api.CucumberOptions;
       import cucumber.api.junit.Cucumber;
    
    
       @RunWith(Cucumber.class)@CucumberOptions(plugin = {
        "pretty", "json:target/Open-Google-WebSite.json"},
       features = {"src/test/FeatureFilePackage"},
       glue = {"com.java.cucumber_test"})
    
        public class TestRunner {
    
       }
    

    【讨论】:

    • 谢谢,我得到了比以前更好的结果,但仍然存在一些问题,请检查我更新的问题。
    • 哦,您没有创建步骤定义,这是问题所在。当您运行运行程序文件时,它将创建步骤定义,您复制所有步骤定义并放入 cucumber_test 并在每个步骤中编写代码。运行您的运行程序文件,您应该能够看到步骤定义功能控制台输出并将其复制到 cucumber_test 中。它将有待处理的异常。删除该未决异常并根据每个步骤放置您的代码。
    • 我当然会尝试。谢谢。
    • 在哪里生成步骤定义文件?你能帮我找到那个吗?
    • 当你运行 runner 文件时,它会在控制台输出中生成。如果你有正确的配置,它应该生成步骤定义。
    【解决方案4】:

    您的测试似乎正在通过 testng 运行,它没有显示任何特定错误我建议您从 pom 文件中删除 testNg 依赖项运行您的测试(通过 Junit),您将能够看到特定错误并在解决它之后将能够轻松地运行您的课程

    预期的错误可能是“重复步骤定义”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 2020-12-19
      • 1970-01-01
      相关资源
      最近更新 更多