Sunday, July 11, 2010

Using Ant to execute Selenium

Prerequisite requirement:
  1. Get a copy of TestNG from this site.Please note that I am not using the Eclipse plugin. The moment of this writingis 5.12.1 
  2. Get the ant from apache’s site. 
  3. Get the JDK from Sun’s site. 
  1. Add a new environment variable called JAVA_HOME under the System Variable group. Set the path to the JDK installationdirectory. Without this the compiler will complain that tools.jar not foundduring the Ant process. 
  2. Add the ant’s bin directory and jdk’sbin directory into Path environment variable under the System Variable group. 
The JAVA code:
  1. Create a JAVA project using Eclipse. 
  2. Add the testng-<version>.jar intobuild path and update all necessary info of the jar file (eg. SourceAttachment, JavaDoc, library location) for easier debugging purpose. 
  3. Create the source code below under thatsrc directory and name it as The code is actually copy fromTestNG’s site. 
    package package1;
    import org.testng.annotations.*;
    public class SimpleTest {
          public void setUp() {
             // code thatwill be invoked when this test is instantiated
          @Test(groups = { "fast" })
          public void aFastTest() {
             System.out.println("Fast test");
          @Test(groups = { "slow" })
          public void aSlowTest() {
             System.out.println("Slow test");
  5. Create the Ant file using code below:
  7. There are a couple of thing to take note here:
    • the Ant must be told that where the location of the testng<version>.jarfile and where are the binary file in pathelement location.
    • the destdir in javac indicate where the output of the binary class file shouldlocate after the compilation.
    • the correct location of the binary class must be set in classfileset otherwisean error complain that the build.xml not found.
  8. After this, the testng-output directory will be generated. Notice that thetestng-results.xml is created automatically for generating the testng-xsltreport purpose.

No comments: