我通过功能文件或Runner类运行测试。我无法创建一个罐子,因为我没有项目中的主要方法。请让我知道如何使用它创建一个JAR文件,或者如果需要添加任何内容。
我想在服务器中执行功能方案,以实现我想创建当前项目的exe(使用Eclipse IDE和Maven用作构建工具的Selenium Webdriver,Java的Cucumber,但由于我没有我项目的主要方法。请让我知道如何使用此方法创建一个JAR文件,或者如果需要添加任何其他插件以及如何在此处添加主方法。
This is my POM.xml from the project :
<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.cucumber</groupId>
<artifactId>BasePolicy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BasePolicy</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</project>
--------------------------------------------------------------------
and My java runner class :
package com.cucumber.testcases;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import com.cucumber.Base.BaseDriver;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
// format = {"pretty","html:target/html/" } ,
features = "src/test/java")
public class RunnerClass {
}
您可以通过调用static main method of Main.class
(一句话中的许多主题(来创建一个主要方法来运行黄瓜。
创建一个新类,并向其添加以下主要方法。
public static void main(String[] args) throws Throwable {
Main.main(new String[]{"-g", "classpath to step definition file", "Full path to feature file"});
// My stepdefinition is inside java package at cucumber.sample.test
// My feature file is inside src/test/resources/features/sample.feature
}
对于其他参数,例如标签或插件,请使用"-t","@Tags"
。重要的是要功能文件路径是最后一个选项。
您可以在运行时将这些参数传递到此类中,以使其更加灵活。您需要在代码中使用ARGS参数。