无法从命令行运行黄瓜测试-成功构建响应(无错误)

时间:2019-01-29 06:15:41

标签: maven selenium-webdriver cucumber-junit

  

无需编译-所有类都是最新的-获取此   来自Maven-compiler-plugin的响应,并且没有测试用例   为Selenium执行-黄瓜测试运行器文件

     

更改了以测试结尾的TestRunner名称。添加了以下内容   POM.xml文件中配置

         <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18</version>
    <configuration>
    <includes>
    <excludes>**/*TestRunnertest.java</excludes>
    </includes>
    </configuration>
    </plugin>

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>corporate</groupId>
  <artifactId>web</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>web</name>
  <url>http://maven.apache.org</url>


<properties>

 <project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  <build>
    <plugins>

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.6.1</version>
    </plugin>


  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18</version>
    <configuration>
    <includes>
    <excludes>**/*TestRunnertest.java</excludes>
    </includes>
    </configuration>
    </plugin>

  </plugins>
  </build>
  <dependencies>
    <dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.0.7</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>3.141.59</version>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.2.0</version>
</dependency>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
</dependency>
<dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>2.3.1</version>
        <scope>test</scope>
    </dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-email</artifactId>
    <version>1.5</version>
</dependency>
<dependency>
    <groupId>org.apache.directory.studio</groupId>
    <artifactId>org.apache.commons.io</artifactId>
    <version>2.4</version>
</dependency>
  </dependencies>
</project>

TestRunner

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "/Users/neha/eclipse-workspace/webCorp/src/test/java/feature", //the path of the feature files
        glue={"stepDefinition"}, //the path of the step definition files
        //format = { "pretty", "json:target/json/output.json" }, 
        tags = { "~@ignore" },
        plugin= {"com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"}, //to generate different types of reporting
        monochrome = true, //display the console output in a proper readable format`enter code here`
        strict = true, //it will check if any step is not defined in step definition file
        dryRun = false //to check the mapping is proper between feature file and step def file

        )

public class TestRunnertest  {

    @BeforeClass
    public static void startup() {
        System.out.println("Starting test");
    }
}
  • 我希望能够使用以下命令从命令行运行TestRunner文件 cmd mvn测试 -Dcucumber.options =” /用户/neha/eclipse-workspace/webCorp/src/main/java/testRunner/TestRunner.java”

    我可以通过从pom.xml中删除cumul-java,junit和cucmber-junit依赖项来从eclipse运行代码

1 个答案:

答案 0 :(得分:0)

创建TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite" parallel="false">
  <test name="Test">
    <classes>
      <class name="PackageName.TestRunnertest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

创建pom.xml

添加依赖项和插件TestNG.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>MavenOutlook</groupId>
  <artifactId>MavenOutlook</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
  <selenium.version>3.12.0</selenium.version>
  <testng.version>6.9.10</testng.version>
 </properties>

 <dependencies>
  <dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>3.12.0</version>
  </dependency>
  <dependency>
   <groupId>org.testng</groupId>
   <artifactId>testng</artifactId>
   <version>6.9.10</version>
   <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
<dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>1.2.4</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-picocontainer</artifactId>
      <version>1.2.4</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-testng</artifactId>
      <version>1.2.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>com.vimalselvam</groupId>
    <artifactId>cucumber-extentsreport</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.1.2</version>
</dependency>

<dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.2</version>
        </dependency>
        <dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.1</version>
  <type>maven-plugin</type>
</dependency>
 </dependencies>

 <build>
<plugins>
   <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.3.2</version>
        </plugin>
   <plugin>

     <artifactId>maven-surefire-plugin</artifactId>
   <version>2.19</version>
    <configuration>
     <suiteXmlFiles>
      <suiteXmlFile>TestNG.xml</suiteXmlFile>
     </suiteXmlFiles>
    </configuration>
   </plugin>

  </plugins>
 </build>

</project>

打开命令提示符并转到项目目录

并运行测试mvn测试

相关问题