Generate XSLT Report+ Ant build.xml+ Resolving Unknown file:23:146: Fatal Error! Could not find function: if Issue +No suites, classes, methods or jar file was specified






We usually depend on Testng for generating the default reports. Apart from that we use XSLT reports as well to generate PIE Charts based on Failed,Passed,Skipped Testcases.
During this process we face lot of issues. Few of the most commonly observed issues are as follows:
[xslt] Unknown file:23:146: Fatal Error! Could not find function: if
[xslt] : Fatal Error! Fatal error during transformation Cause: Fatal error during transformation
In order to resolve this we have to follow the below steps. At every step we will check and see whether issues are resolved or not.
Step 1 :
Make sure the build.xml file contains 'SaxonLiaison' processor added.
Example:<xslt in="${outputdir}/test-output/testng-results.xml" style="${basedir}/testng-results.xsl" out="${outputdir}/testng-xslt/index.html"  processor="SaxonLiaison">

Re-run the build.xml and verify the issue is resolved. If the issue is not resolved goto Step2.

Step 2 :
Make sure the following jars added to the lib folder and Project build path as well.
saxon-8.7.jar -> Link to download the saxon jar-> Click here
SaxonLiaison.jar ->Link to download the SaxonLiaison jar->Click here
guice-3.0.jar->Link to download guice-3.0.jar->Click here
Re-run the build.xml and verify the issue is resolved. If the issue is not resolved goto Step3.
Step 3:
Re-verify the build.xml available in the project directory by downloading from this link Click here .Try to do necessary changes.
Re-run the build.xml and verify the issue is resolved. If the issue is not resolved goto Step3.
Step 4:
Re-verify the testng-results.xsl available in the project directory by downloading from the link Click here.Try to do necessary changes.
Re-run the build.xml and verify all the issues are resolved.
If even after the issues are not resolved, please refer to the directory structure mentioned in the below screenshot.
Resolving "No suites, classes, methods or jar file was specified" in Ant TestNG- Make sure the testng.xml is availble in the src folder as mentioned in the image below. Refer to the point1.











Implementation of Testng @DataProvider using EXCEL (Data Driven Framework) & JXL to Read XLS

@DataProvider
In order to store the multiple set of input data we use @DataProvider.
We are going to read the xls file which contains input data and store in @DataProvider.
Steps to Achieve :
  a. Store the input data in an xls file.
  b. Read the data from the xls using an third party jar jxl2.6.jar
   Link for Downloading JXL Jar ->http://www.findjar.com/index.x?query=jxl
   jxl stands for -> java excel library
 c. Add the jar to the build path.
 d. Store the data in @Dataprovider
 e. Use the @Dataprovider in the @Test methods.
JExcel API ->http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/
  WorkBook contains sheets
  Sheets contains rows and column
  Each and every values stored in the rows and columns in a cell.
  Retrieve the contents of the cell using row index and column index and store in an array
Program:
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ReadExcelJXL {
@Test(dataProvider="DP")
public void sales_coupon_count(String username,String password)
{

System.out.println("The value of username" + username);
System.out.println("The value of password" + password);

}
@DataProvider(name="DP")
public String[][] readExcel(  )
{
File file = new File("inputData.xls");
String inputData[][] = null;
Workbook w;

try {
w = Workbook.getWorkbook(file);

// Get the first sheet
Sheet sheet = w.getSheet(0);

int colcount=sheet.getColumns();

int rowcount=sheet.getRows();

inputData= new String[rowcount][colcount];

for ( int i=0;i<sheet.getRows();i++)
{
for (int j=0;j<sheet.getColumns();j++)
{
Cell cell=sheet.getCell(j,i);
inputData[i][j]=cell.getContents();
}
}
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return inputData;
 }
}
Output
The value of username-->xyz
The value of password-->abc
The value of username-->abc
The value of password-->welcome
The value of username-->ab1123
The value of password-->welcome123
PASSED: sales_coupon_count("xyz", "abc")
PASSED: sales_coupon_count("abc ", "welcome ")
PASSED: sales_coupon_count("ab1123 ", "welcome123")

===============================================
    ReadExcelJXL
    Tests run: 3, Failures: 0, Skips: 0
===============================================


===============================================
DataDriven
Total tests run: 3, Failures: 0, Skips: 0
===============================================
inputData.xls






Using Selenium Grid with Two Nodes-FF & Chrome(HUB)


Steps for Setting Up the Grid

1. Download the Selenium Sever Jar File using the link

2. Pre-requisite for Every Machine 
Copy  the Selenium Server in every host hub,remote node1,remote node2

3. To check the default port number used by Hub '4444' is reserved or not
Command --> netstat -a -n | findStr 4444
We have to check this command only in hub machine.

4. Starting the Hub. Navigate to the location where the selenium-server jar is downloaded and execute the below command.
java -jar selenium-server-standalone-2.44.0.jar  -role hub

5. Starting the Hub using particular port. If the default port '4444' is already in use. Then we have to pass another port number in the command line for the argument -port as mentioned below:
java -jar selenium-server-standalone-2.44.0.jar  -role hub -port 4545

6. Verifying the Hub Console
7.Starting Node1: Navigate to the location where selenium server jar is located and execute the below command
java -jar selenium-server-standalone-2.44.0.jar  -role webdriver -browser "browserName=firefox,version=35,maxInstances=1,platform=WINDOWS" -hubHost localhost -port 4546

8. Starting Node2: Navigate to the location where selenium server jar is located and execute the below command
java -jar  selenium-server-standalone-2.44.0.jar -role webdriver -browser "browserName=chrome,version=40,maxInstances=1,platform=WINDOWS" -hubHost localhost -port 4547 -Dwebdriver.chrome.driver=D:\\Selenium\\chromedriver_win32\\chromedriver.exe 

9. Selenium WebDriver Script for FF
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName("firefox");
caps.setVersion("35");
caps.setPlatform(Platform.WINDOWS);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);

10. Selenium WebDriver Script for CH
 DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName("chrome");
caps.setVersion("40");
caps.setPlatform(Platform.WINDOWS);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);

Selenium WebDriver Program:

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.Platform;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class GridTests {
RemoteWebDriver  driver;
DesiredCapabilities caps;
@Parameters({"browsertype","url"})
@BeforeTest
public void invokebrowser(String browserType,String url) throws MalformedURLException
{
if(browserType.equals("FF"))
{
caps = DesiredCapabilities.firefox();
caps.setBrowserName("firefox");
caps.setVersion("10");
caps.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);
System.out.println("in FF");
//driver =new FirefoxDriver();
}
else if(browserType.equals("IE"))
{
System.out.println("in IE");
File f =new File("IEDriverServer.exe");
System.setProperty("webdriver.ie.driver",f.getAbsolutePath());
driver = new InternetExplorerDriver();
}
else
{
caps = DesiredCapabilities.chrome();
caps.setBrowserName("chrome");
caps.setVersion("40");
caps.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);

System.out.println("in CH");
}
driver.get(url);
}
@Test
public void verifyTitle()
{

Assert.assertEquals(driver.getTitle(),"Facebook");

}
}