如何从命令行使用maven运行selenium testNG测试用例?

时间:2013-08-21 05:21:02

标签: maven selenium testng

使用以下命令从maven运行我的测试用例

c:\> mvn test

我得到以下结果:

 D:\arpit_maven\mavenProject\build_demo>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building build_demo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ build_demo
 ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\arpit_maven\mavenProject\build_dem
o\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ build_demo --
-
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ bu
ild_demo ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\arpit_maven\mavenProject\build_dem
o\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ build
_demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ build_demo ---
[INFO] Surefire report directory: D:\arpit_maven\mavenProject\build_demo\target\
surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.031s
[INFO] Finished at: Thu Mar 21 10:29:17 IST 2013
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
D:\arpit_maven\mavenProject\build_demo>

我的POM.xml如下。如果pom.xml中缺少任何内容,请告诉我。 我的测试用例在src \ test \ java \文件夹中。

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>demo1</groupId>
<artifactId>build_demo</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>build_demo</name>
<url>http://maven.apache.org</url>
<properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.33.0</version>

    </dependency>

 <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
 </dependency>
 <dependency>
<groupId>org.testng</groupId>
 <artifactId>testng</artifactId>
<version>6.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.8</version>
    </dependency> 
</dependencies>
<build>
    <resources>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
     <plugins>
     <plugin>
     <groupId>org.apache.mavan.plugins</groupId>
     <artifactId>mavan-compiler-plugin</artifactId>
     <version>2.3.2</version>
     <configuration>
     <source>1.6</source>
     <target>1.6</target>
     </configuration>
     </plugin>
     </plugins>
     </build> 
     <profiles>
    <profile>
        <id>selenium-tests</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.4.3</version>
                    <configuration>
                        <includes>
                            <include>Opencart.java</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
 </profiles>
</project>

1 个答案:

答案 0 :(得分:2)

将您的类重命名为OpencartTest.java或更改surefire中的过滤器属性,以便它获取您的Opencart.java类。您还可以创建包含Opencart.java的套件xml文件。

就个人而言,我只会改变你班级的名字!