Not able to see consistency in Ant generated reports and JUnit tests run on same classes | Selenium Forum
P
Preetinder Virk Posted on 17/02/2020

Hi,

 

I refer to Module 21 of Selenium for Project JUNIT AND DATA DRIVEN FRAMEWORK. I am coding it in line with code provided and find a great discrepancy between Ant generated reports and errors reported through JUnit tests run on same classes. I even updated my project to Maven but ant genearted reports are not same as that of the Eclipse run reports. I am adding a Doc for the issue here

As you see the results of running JUNit and Ant are different with correct error messages in JUnit but offthe hand in Ant.

Example Ant O/P I get is:

 

run:

    [junit] Running tests.suite1.FirstSuiteRunner

    [junit] Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 0.308 sec

    [junit] Test tests.suite1.FirstSuiteRunner FAILED

[junitreport] Processing /Users/<me>/Documents/ReportsRepo/rep/TESTS-TestSuites.xml to /var/folders/jb/j707q50968j173xhc3m9391h0000gn/T/null2062636952

[junitreport] Loading stylesheet jar:file:/usr/local/apache-ant-1.10.7/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl

[junitreport] Transform time: 457ms

[junitreport] Deleting: /var/folders/jb/j707q50968j173xhc3m9391h0000gn/T/null2062636952

 

BUILD SUCCESSFUL

Total time: 2 seconds

Build is successful but there are 4 errors. I have run Project via maven, Junit, and build.xml and they all pass with correct errors reported.

This is my Build.xml file:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>

<project name="Module_Junit_Ant" default="usage" basedir=".">  

<!-- ========== Initialize Properties =================================== -->
    <property environment="env"/>
    
    <property name="ws.home" value="${basedir}"/>
	<property name="ws.jars" value="/Users/preetinderkaurvirk/Desktop/Selenium Code - Oct 18/Selenium Code - Oct 18/AllJars/"/>
    <property name="test.dest" value="${ws.home}/build"/>
    <property name="test.src" value="${ws.home}/src"/>
	<property name="test.reportsDir" value="/Users/preetinderkaurvirk/Documents/ReportsRepo/rep"/>

	

	<path id="testcase.path">


	    <pathelement location="${test.dest}"/>

	    <fileset dir="${ws.jars}">
	      <include name="*.jar"/>
	    </fileset>

	  </path>

    
    <target name="start-selenium-server">
        <java jar="${ws.home}/lib/selenium-server.jar"/>
   </target>

    <target name="setClassPath" unless="test.classpath">
        <path id="classpath_jars">
            <fileset dir="${ws.jars}" includes="*.jar"/>
        </path>
        <pathconvert pathsep=":" 
            property="test.classpath" 
            refid="classpath_jars"/>
    </target>

    <target name="init" depends="setClassPath">
        <tstamp>
            <format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
        </tstamp>
        <condition property="ANT" 
            value="${env.ANT_HOME}/bin/ant.bat" 
            else="${env.ANT_HOME}/bin/ant">
                    <!--<os family="windows" />-->
        			<os family="mac" />
        </condition>
        
    </target>
  
    <!-- all -->
    <target name="all">
    </target>

    <!-- clean -->
    <target name="clean">
        <delete dir="${test.dest}"/>
    </target>

    <!-- compile -->
    <target name="compile" depends="init, clean" > 
		<delete includeemptydirs="true" quiet="true">
            <fileset dir="${test.dest}" includes="**/*"/>
		</delete>
        <echo message="making directory..."/>
		<mkdir dir="${test.dest}"/>
        <echo message="classpath------: ${test.classpath}"/>
        <echo message="compiling..."/>
        <javac 
            debug="true" 
            destdir="${test.dest}" 
            srcdir="${test.src}" 
            target="13" 
            classpath="${test.classpath}"
        >
        </javac>
          <copy file="src/log4j.properties" todir="build/"/>
      </target>

    <!-- build -->
    <target name="build" depends="init">
    </target>

   
	  

    <target name="usage">
        <echo>
            ant run will execute the test
        </echo>
    </target>

	<path id="test.c">
	        <fileset dir="${ws.jars}" includes="*.jar"/>
	</path>
	
	  
	
	<target name="run" >  
		<delete includeemptydirs="true" quiet="true">
		            <fileset dir="${test.reportsDir}" includes="**/*"/>
				</delete>
			    <java jar="${ws.jars}" fork="true" spawn="true" />  
			    <junit fork="yes" haltonfailure="no" printsummary="yes">
				    <classpath refid="testcase.path" />  

			      <!--  <classpath ="${test.classpath}"/> -->  
			    <batchtest  todir="${test.reportsDir}" fork="true">  
			    <fileset dir="${test.dest}">  
			       
			        <include name="tests/suite1/FirstSuiteRunner.class" />
			        <!--include name="tests/suite1/FirstSuiteRunner.class" />-->
			        

			         
			    </fileset>  
			    </batchtest>    
			        <formatter type="xml" />  
				    <classpath refid="testcase.path" />  
			</junit>  
			    <junitreport todir="${test.reportsDir}">    
			        <fileset dir="${test.reportsDir}">  
			            <include name="TEST-*.xml" />  
			        </fileset>  
			        <report todir="${test.reportsDir}" />  
			    </junitreport>  
			</target>
	
	<target name="email" >
		       <java classname="util.SendMail" classpath="${test.dest}" classpathref="testcase.path" />
	    </target>

	
</project>

Could you inform where is this inconsistency coming from? And why errors reported are different ? 

 

Thanks


A
Ashish Thakur Replied on 18/02/2020

Please share the complete console output from both. Additionally, share the reports as well.


P
Preetinder Virk Replied on 19/02/2020

Hi,

 

Here is the zip file attached. The red color coded errors showing up in Console O/P are clearer in .rtf extensions though I have listed the .txt files too. Please observe that for first run test was Pass in Eclipse but failed on Ant. Also in second run in the folder Err22 there were 2 errors reported in Eclipse but different error in Ant and Reports.

 

Thanks


A
Ashish Thakur Replied on 21/02/2020

For further investigation, we need the code. So, please export the project in a compressed zip file and share it with us.

Also please mention all the commands that you are using to execute the code.


P
Preetinder Virk Replied on 22/02/2020

Hi,

 

Attached is zip file. User name and password can be input for the website. Ant commands on Mac:

 

cd /Users/preetinderkaurvirk/Desktop/Selenium\ Code\ -\ Oct\ 18/Selenium\ Code\ -\ Oct\ 18/code/Module\ 21\ -\ Junit\ Data\ Driven/Module18/Old/Module18_Junit_DataDriven

ant clean

ant compile 

ant run

 

I can also run the test in Eclipse as a Test NG test.

 

Thanks


A
Ashish Thakur Replied on 28/02/2020

Please share the all jars folder.


P
Preetinder Virk Replied on 28/02/2020

Sharing jars folder via Drive:

 

https://drive.google.com/file/d/1V9_gWHip8S4zdng0x3CAn-pHwSU7pVFD/view?usp=sharing


A
Ashish Thakur Replied on 03/03/2020

Please rectify your project first.

Please watch module 9 on a urgent note and watch the video carefully.

Update the project accordingly.

Please do not add jars manually in a maven project.

Share the project again after the update.


P
Preetinder Virk Replied on 04/03/2020

I will watch the video again and then update here


A
Ashish Thakur Replied on 05/03/2020

Share the project once rectified.


Related Posts