0
votes

I have Maven Project and all the configuration is correct, recently i configured the project with GIT and Jenkins,Created Jenkin job.

Earlier i was able to run the complete project by Right click on project and Run **--> **Run --> Maven test and test execution use to start but now its not throwing any error but not launching the browser for execution.

But if i run the java file [Single test case] separately using TestNG its working as expected[launching the browser and starts the execution]

As i have configured with Jenkins i cannot run every test case separately. I will have to run the project with Maven test

I have tried the possible solutions :

  1. Clean Project + delete m2 folder + Maven Run [just to make sure its not pointing to any old jar files] --> Did not work for me

Please find the code snippet that i have used in pom.xml

 

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
            </plugin>
        </plugins>
    </build>

Thanks in advance for all the suggestions :)

2
Please share error details, what Maven test is throwing in console. - Ishita Shah
@IshitaShah : It is not throwing any error message but not launching browser nor executing any test cases. But if we run the test cases separately it is executed successfully - Prateek Neelgund
If test does not launching even then also, there may be something on Console window regarding maven test status. I went through it. - Ishita Shah
----------- T E S T S ----------- Running TestSuite LoginTest Test starts from row - 13 Total rows are - 1 Total cols are - 4 log4j:WARN No appenders could be found for logger (freemarker.cache). log4j:WARN Please initialize the log4j system properly. log4j:WARN See logging.apache.org/log4j/1.2/faq.html#noconfig for more info. About to read data from the excel All the data has been retrived from the excel LoginTest Test starts from row - 25 Total rows are - 1 Total cols are - 4 LoginTest Test starts from row - 9 Total rows are - 1 Total cols are - 4 LoginTest - Prateek Neelgund
@IshitaShah : This is what displayed on console and it does not do anything after this. - Prateek Neelgund

2 Answers

1
votes

To trace cause, You may go through by below steps. And you will be found where is actual cause and it gets stuck.

1. Create Simple @Test with Console output:

public class NewTest {
  @Test
  public void f() {
      System.out.println("Hello World");
  }
}

2. Create TestNG.XML at root location of the project to execute above class:

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Suite">
      <test thread-count="5" name="Test">
        <classes>
          <class name="packageName.NewTest"/>
        </classes>
      </test> <!-- Test -->
    </suite> <!-- Suite -->

3. Run and Check TESTNG.XML output

4. Run and Check output from POM.XML

POM.XML:

  <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <suiteXmlFiles> 
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
  </plugins>
0
votes
  1. create a testNG xml and include all test classes there. This could be done by including the top level package:

<test name="sample-Test" preserve-order="true" verbose="2">
    <packages>
        <package name="org.sample.something.*"/>
    </packages>
</test>

2.1 Update your surefire plugin configuration to make it:

        <configuration>
           <suiteXmlFiles>
               <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
           </suiteXmlFiles>
        </configuration>

2.2 OR (more flexible as you can create different profiles pointing to different xml to run different test suites separately) Create a maven profile that will point to your testNG xml

     <profiles>
       <profile>
          <id>selenium-tests</id>
          <build>
             <plugins>
                <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-surefire-plugin</artifactId>
                   <version>2.19.1</version>
                   <configuration>
                      <suiteXmlFiles>
                         <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                      </suiteXmlFiles>
                   </configuration>
                </plugin>     
             </plugins>
          </build>
       </profile>
    </profiles>
  1. mvn clean test -U -Pselenium-tests OR mvn clean test

source for maven

source for xml