Java-无法从Maven运行黄瓜测试
作者:互联网
我的Maven项目结构是
如果我尝试通过Eclipse作为JUnitTest(CucumberRunnerTest.java)运行该项目,则该项目运行良好.
但是,如果我尝试通过maven执行它,则会收到以下错误:
pom如下:
<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.ericsson</groupId>
<artifactId>MavenCuke</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenCuke</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber-jvm.version>1.1.8</cucumber-jvm.version>
<selenium.version>2.42.2</selenium.version>
<junit.version>4.11</junit.version>
<cucumber.options>--format pretty --tags @Search</cucumber.options>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>cucumber.api.cli.Main</mainClass>
<arguments>
<argument>--format</argument>
<argument>junit:output/cucumber-junit-report/allcukes.xml</argument>
<argument>--format</argument>
<argument>pretty</argument>
<argument>--format</argument>
<argument>html:output/cucumber-html-report</argument>
<argument>--format</argument>
<argument>json:output/cucumber_report.json</argument>
<argument>--glue</argument>
<argument>src\</argument>
<argument>src\main\resource\com\ericsson\</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber-jvm.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber-jvm.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0-rc1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin-jvm-deps</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber-jvm.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>0.0.23</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber-jvm.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
</dependency>
</dependencies>
</project>
从命令提示符运行时******** mvn集成测试
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenCuke ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenCuke ---
[INFO] Building jar: C:\Users\esusadh\MavenCucumber\MavenCuke\target\MavenCuke-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default) @ MavenCuke ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please commenon MEXEC-6.
Feature: Navigating into ericsson.com and verify text
In order to verify tags
I open browser
and I navigate to ericsson.com
I verify the search text.
@Search
Scenario Outline: Searching for text ←[90m# Cucumber.
feature:9←[0m
←[36mGiven ←[0m←[36mI go to "URL" on "<Browser>"←[0m
←[36mWhen ←[0m←[36mI click on "Links"←[0m
←[36mThen ←[0m←[36mI verify for "Search_Text" against "<Expected_Result>"←[0m
Examples:
@Search
Scenario Outline: Searching for text ←[90m# Cucumber.feature:16←[0m
←[33mGiven ←[0m←[33mI go to "URL" on "Mozilla"←[0m
←[33mWhen ←[0m←[33mI click on "Links"←[0m
←[33mThen ←[0m←[33mI verify for "Search_Text" against "The Company"←[0m
1 Scenarios (←[33m1 undefined←[0m)
3 Steps (←[33m3 undefined←[0m)0m0.000s
You can implement missing steps with the snippets below:
@Given("^I go to \"(.*?)\" on \"(.*?)\"$")
public void i_go_to_on(String arg1, String arg2) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^I click on \"(.*?)\"$")
public void i_click_on(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^I verify for \"(.*?)\" against \"(.*?)\"$")
public void i_verify_for_against(String arg1, String arg2) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
正如我在Search_Text.java中实现此步骤的位置.
如果我使用maven-compiler插件并通过maven运行它,则会得到package.cuip.junit.Cucumber包不存在! (以下是在POM中添加的插件)
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
解决方法:
作为–glue,您应该指定Java测试类的软件包名称.
标签:cucumber-junit,selenium-webdriver,eclipse,maven-2,java 来源: https://codeday.me/bug/20191121/2051398.html