0

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

Prateek Neelgund
  • 11
  • 1
  • 1
  • 6
  • Please share error details, what Maven test is throwing in console. – Ishita Shah Dec 04 '18 at 09:45
  • @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 Dec 04 '18 at 10:38
  • 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 Dec 04 '18 at 10:55
  • ----------- 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 http://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 Dec 05 '18 at 09:24
  • @IshitaShah : This is what displayed on console and it does not do anything after this. – Prateek Neelgund Dec 05 '18 at 09:24
  • Check with maven build - compile and run maven test. – Ishita Shah Dec 05 '18 at 09:37
  • [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Sales_Force_Test_Automation --- [INFO] Nothing to compile - all classes are up to date [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS but once after maven test run resulting with no error but again not launching the browser for execution – Prateek Neelgund Dec 05 '18 at 09:57

3 Answers3

1

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>
Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
0
  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

Vladimir Efimov
  • 797
  • 5
  • 13
  • Thanks for the details solution but unfortunately this solution is not working for me. Please find the updated snippet below : org.apache.maven.plugins maven-surefire-plugin 2.19.1 true src/test/resources/testng.xml ` – Prateek Neelgund Dec 04 '18 at 10:36
  • But still it is throwing an error [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project Sales_Force_Test_Automation: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process [ERROR] org.testng.TestNGException: [ERROR] Cannot find class in classpath: com.ef.sl.testcases.Imports.ImportTest – Prateek Neelgund Dec 04 '18 at 10:37
  • @PrateekNeelgund plz check here https://stackoverflow.com/questions/25543910/error-org-testng-testngexception-cannot-find-class-in-classpath-empclass – Vladimir Efimov Dec 04 '18 at 11:04
  • try -> mvn clean install – Vladimir Efimov Dec 04 '18 at 11:05
  • no luck !!! It is not showing any error, single test file execution working but when i select complete project and give a maven test / maven install , its not launching any browser and also not showing any error – Prateek Neelgund Dec 05 '18 at 07:40
  • Could you please add the console output of running 'mvn clean test'. It sounds like it does not find any tests in the xml (maybe xml is created incorrectly) thus does not run any browser – Vladimir Efimov Dec 05 '18 at 12:54
0

If your testng.xml or xml file with test cases is in root directory of project you can try below command.

  1. This will trigger all test cases present in testng.xml

         mvn clean test -Dsurefire.suiteXmlFiles=testng.xml
    
  2. This will execute single test case

         mvn clean test -Dtest=className
    

Please not that, you need to have surefire plugin into the pom.xml.