Friday, December 20, 2013

Run your test cases using Ant.

Welcome to the third post of this subject. In the previous post, we did two test cases  using Eclipse and Selenium WebDriver. In this post we will  make an ANT script  to run the test cases.

Please notice that if you don´t need to run your test automatically in a scheduled way, you might just write the tests using Selenium WebDriver and use just the JUnit´s UI available in Eclipse or Netbeans. 

Now, if you need to automate the daily execution of the test cases you probably want to read the rest of the post :)

First you have to have Apache-Ant 1.9.2, once you have downloaded you have to set your System environment variables: a PATH and a CLASSPATH variable in which you are going to write the apache ant 1.9.2\bin address.


You have to copy the file JUnit.jar in the apache-ant-1.9.2/lib folder. The file JUnit.jar is in eclipse\plugins\org.junit_4.11.0.v201303080030\junit.jar.



To create the script in Ant you have to go to eclipse File->New-> other, this will show you the following window:


Click on the next button, you will give the name of build.xml to your file and put it in src.


To create the script in ant, you have to be sure to add the file junit.jar to the script. This file was added in apache-ant-1.9.2/lib and you also have to be able to add the files .jar of selenium, here you have the directions to do it:


   
     
       
     




Ant allows you to run your test and generate a report in HTML, a very common problem is that when you run the script and you have to generate the report you will see the next error:

BUILD FAILED
Errors while applying transformations: Fatal error during transformation

This error is because of eclipse that is using the Default of ant. To solve it you have to go to Window->Preferences and the following window will appear:


Go to Ant and select RunTime option.


Click on Ant Home and select apache-ant-1.9.2 folder.


You have to make sure that the Ant Home Entries are not as Default and contains the apache-ant-1.9.2 folder address.


Now you can do the Ant script, the next code is the script to execute the test that had been made in the previous post; this script also generates a html report of our tests.
  


  
  
  
  

 
   
   
     
   
   
 

 
  
  
 

 
    
    
    
 

 
   
     
   
 

 
    
     
     
       
   
   
     
       
     
     
   
   

  
    Main target
  

The report can be found in src->reports->html folder.


If you open the report (index.html) it should look like this:


I the next post we will use Hudson to do a scheduled execution of the ANT script.

See you there!


No comments :

Post a Comment