Arpitk12
Arpitk12

Reputation: 3

How to run selenium testNG test cases using maven from command line?

While running my test case from maven using following command

c:\> mvn test

I am getting following result:

 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>

My POM.xml is as follows. Please let me know if anything is missing in pom.xml. My test case is in src\test\java\ folder.

<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>

Upvotes: 0

Views: 3776

Answers (1)

Robbie Wareham
Robbie Wareham

Reputation: 3428

Rename your class to OpencartTest.java OR change the filter attributes in surefire so that it picks up your Opencart.java class. You could also create suite xml file which explicity includes Opencart.java.

Personally, I would just change the name of your class!

Upvotes: 2

Related Questions