Thursday, March 7, 2013

Testng.xml file functionality and contains

TestNG.xml file is use to run the test in batch mode . below is the format for testng.xml file 

Save the below could as build .xml file report and run it , all the method associate with this testNG.xml file will executated



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
// This is  the Suite name is which can be any thing
<suite name="LeadForm">
// This is the test name . again it can assign as per the our convenience

     <test name="google Lead Form Home Equity Service" >
    <classes>
// This is the name of class and it is case sensitive hence hQF is package name and   HomeEquity is class name

           <class name="hQF.HomeEquity"> </class>
      </classes>
     </test>

  <test name="google Lead Form Refinance" >
   <classes>
     <class name="hQF.Refinance"> </class>
     </classes>
  </test>
   
    <test name="google Lead Form Dept Service" >
   <classes>
           <class name="hQF.DebtConsolidation"> </class>
    </classes>
    </test>
 
    <test name="google Lead Form New Home Service" >
    <classes>
           <class name="hQF.NewHomeLoan"> </class>
      </classes>
     </test>
   
   

</suite>




WebDriver using TestNG annotations


If you are using the TestNG Annotation then no need to use the main() function . it is not supporting to main function. Simply use function :-

package hQF;

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Refinance {

// Useing teh Annontation Test So used normal function
 @Test
 public static void Test() throws InterruptedException
// public static void main(String[] args) throws Exception {
final String var = "prog_bg";
WebDriver driver = new FirefoxDriver();
// WebDriver driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://hsh.com");
Thread.sleep(1000);
List<WebElement> DefualtRadio = driver.findElements(By
.xpath("//input[@value='REFI']"));
System.out.println("ByDefault Refinance radio is selected  "
+ DefualtRadio.get(0).getAttribute("checked"));
}
    else {
// Call the test method
      Test();
       }