简体   繁体   English

无法通过 Maven 项目执行 cucumber 测试

[英]Unable to execute cucumber test through Maven project

The details for pom file, runner file and console output are given below pom文件、运行器文件和控制台output的详细信息如下

Pom.xml file- Describes the dependencies and plugins used Pom.xml 文件 - 描述使用的依赖项和插件

<dependencies>
      <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.2</version>
      </dependency>
      
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.1</version>
      <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>
    
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.9</version>
    </dependency>
    
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>ooxml-schemas</artifactId>
        <version>1.4</version>
    </dependency>
        
    <dependency>
        <groupId>org.dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>2.1.1</version>
    </dependency>
    
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
    </dependency>
    
    <dependency>
        <groupId>com.vimalselvam</groupId>
        <artifactId>cucumber-extentsreport</artifactId>
        <version>3.1.1</version>
    </dependency>
    
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>3.12.0</version>
    </dependency>
    
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>4.2.2</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>6.9.1</version>
        <scope>test</scope>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>6.9.1</version>
    </dependency>
    
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>6.9.1</version>
    </dependency>
    
    <dependency>
         <groupId>io.cucumber</groupId>
         <artifactId>gherkin</artifactId>
         <version>5.1.0</version>
    </dependency>
    
    <dependency>
         <groupId>io.cucumber</groupId>
         <artifactId>cucumber-jvm</artifactId>
         <version>6.9.1</version>
         <type>pom</type>
    </dependency>
    <dependency>
         <groupId>io.cucumber</groupId>
         <artifactId>cucumber-jvm-deps</artifactId>
         <version>1.0.6</version>
    </dependency>
    
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>6.9.1</version>
    </dependency>
    
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180130</version>
    </dependency>
    
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>26.0-jre</version>
    </dependency>
    
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.7</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.12.1</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.12.1</version>
    </dependency>
    
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.12.1</version>
    </dependency>
    </dependencies>
  
  <build>
  <resources>
     <resource>
       <directory>src/test/resources</directory>
       <filtering>true</filtering>
     </resource>
   </resources>
        <plugins>
          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration> 
                <testSourceDirectory>Adminportal/src/test/java/com/vnext/Testrunner</testSourceDirectory>
                    <testFailureIgnore>true</testFailureIgnore>
                    <includes>
                        <include>**/CucumberRunnerTest.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
  </build>

Cucumber Runner file Cucumber 转轮文件

@RunWith(Cucumber.class)
@CucumberOptions(features = {"/src/test/resource/Features"}
        ,glue={"com.vnext.stepDefinition"}, tags=  "@Login", dryRun=true, monochrome=true
        , plugin = {"pretty", "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html" }
        )

public class CucumberRunnerTest {
    
    public static Properties testProp;
    public static String driverPath;
    public static String browser;
    public static String environment;
    public static LinkedHashMap<String, String> envProperty = new LinkedHashMap<>();
    public static JsonReader jr;
    private static DriverLaunch  dl= new DriverLaunch();
    String envRootDir = System.getProperty("user.dir");
    
    
    @BeforeClass
    public void suitSetup() throws Exception{
        testProp = PropertyFileUtils.readProperty(envRootDir+"/src/test/resource/Properties/Test.properties");
        driverPath= testProp.getProperty("driverPath");
        browser= testProp.getProperty("browser");
        environment = testProp.getProperty("environment");
        System.out.println("Driver Path : "+driverPath);
        System.out.println("Browser : "+browser);
        jr= new JsonReader();
        envProperty=JsonReader.jsonRead(environment, envRootDir+"/src/test/resource/DBSite/DbSiteData.json");
        dl.launchDriver(browser, driverPath);
    }

    @AfterClass
    public void teardown(){
        dl.tearDown();
        Reporter.loadXMLConfig(new File("config/report.xml"));
    }
    
    @AfterSuite
    public void endConnection(){
    }

Console output控制台 output

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.vnext.Testrunner.CucumberRunnerTest
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.561 s - in com.vnext.Testrunner.CucumberRunnerTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.954 s
[INFO] Finished at: 2021-03-14T00:44:13+05:30
[INFO] Final Memory: 39M/497M
[INFO] ------------------------------------------------------------------------

The code is not getting executed.代码没有被执行。 Maven is ignoring the feature file. Maven 忽略功能文件。 Please help me resolve the issue.请帮我解决问题。 I tried commenting the Runwith tag but then also getting the same result.我尝试评论 Runwith 标签,但也得到了相同的结果。

Please Help!请帮忙!

You have quite a few incompatible and unnecessary dependencies in your pom.你的 pom.xml 中有很多不兼容和不必要的依赖项。 I suggest you start with the starter project: github.com/cucumber/cucumber-java-skeleton/我建议你从入门项目开始:github.com/cucumber/cucumber-java-skeleton/

create a separate junit runner class:创建一个单独的 junit 转轮 class:

package options;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;


@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = "pretty",
        glue = "stepdefs",   // the package containing step definitions
        features = "src/test/features")   //the folder where you have your featurefile
public class CucumberTests {
}

Now just run:现在只需运行:

mvn test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过Java命令从命令行执行Maven项目 - Unable to execute Maven project from command line through java command Selenium:如何使用带有Maven的黄瓜并行执行测试用例 - Selenium : How to execute test cases at parallely using cucumber with maven 无法从 maven 命令行调用 cucumber junit 测试 - Unable to invoke cucumber junit test from maven command line SRC &amp; TEST文件夹下Cucumber + Maven + POM项目的目录结构 - Directory Structure for Cucumber + Maven + POM project under SRC & TEST folder 无法通过詹金斯执行简单的Maven项目 - Cannot execute a simple maven project through jenkins 无法通过TestNG执行测试用例 - Unable to Execute Test Case through TestNG Maven 测试未运行 cucumber 测试 - Maven test not running cucumber tests 如何在maven项目的Cucumber测试中运行GlassFish和Selenium? - How can I run GlassFish and Selenium under the Cucumber test in maven project? Jenkins:无法通过 Jenkins 运行本地 Maven 项目 - Jenkins : Unable to Run Local Maven Project through Jenkins Maven 项目:能够单独运行测试,但无法使用 Maven 测试运行整个项目 - 0 场景 0 步骤问题 - Maven project: able to run test seperately but unable to run whole project with Maven tests - 0 scenario 0 steps issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM