How To write Test Case is PASS or FAIL using Selenium

How To write Test Case is PASS or FAIL using Selenium
How To write Test Case is PASS or FAIL using Selenium,you can write Test case results PASS or FAIL in Excel using J Excel API and TesNG framework with Selenium WebDriver. Most of the time we are working with Excel,Test Cases in order to verify how many test cases are pass/fail in Excel and it is useful for sending the reports to respective managers. 

Write Test Cases PASS or FAIL in SELENIUM

In this post you will learn clear idea about How To write Test Case is PASS or FAIL using Selenium with real time examples.I have created two classes one for ExcelUtility and another for Write the Excel file for each test cases.

Popular Posts

Selenium Xpath Tutorials
Read Data from Properties File
Selenium WebDriver Methods


Step 1: Using JXL jar-You Can Download from Here
Step 2: Selenium WebDriver Configurations
Step 3: xls Test-Data file.
Step 4: addCell()
Step 5: Test Case Results
Step 6: Test Cases
Step 7: Read the xls file FileInputStream
Step 8: Read Workbook from FileINputStream
Step 9: Read Sheets from Workbook
Step 10: Column,rows

ExcelUtility Class

package com.selenium.Utility;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;

public class Excelutility {

public String Testcase; 
public WritableSheet writablesh; 
public WritableWorkbook workbookcopy;

public void queryParameterization() throws BiffException,IOException,RowsExceededException,WriteException, InterruptedException{

FileInputStream testfile = new FileInputStream("E:\AppiumTutorials\Selenium_Practice\Testdata\TestData.xls");//Now get 
WorkbookWorkbook wbook = Workbook.getWorkbook(testfile);
//Now get Workbook 
SheetSheet sheets = wbook.getSheet("Query_data");
int Norows = sheets.getRows();
//Read rows and columns and save it in String Two dimensional array
String inputdata[][] = new String[sheets.getRows()][sheets.getColumns()];
System.out.println("Number of rows present in TestData xls file is -"+Norows);
//For writing the data into excel we will use 
FileoutputStream classFileOutputStream testoutput = new FileOutputStream("E:\AppiumTutorials\Selenium_Practice\SeleniumYoutube\Testdata\TestData_results.xls");
System.out.println("creating file one");
//To Create writable workbook
workbookcopy = Workbook.createWorkbook(testoutput);
System.out.println("creating file 2");
//To Create Writable sheet in Writable workbook
writablesh = workbookcopy.createSheet("Query_data",0);
System.out.println("creating file 3");

//Using for loop to write all the data to new sheet 
for(int i=0;i<sheets.getRows();i++) { 
for(int k=0;k<sheets.getColumns();k++) {
 inputdata[i][k] = sheets.getCell(k, i).getContents(); 
Label l = new Label(k, i, inputdata[i][k]); 
Label l2 = new Label(4,0,"Results"); 




public void writeexcels(){ 
try { 
} catch (IOException e) { 

try { 
} catch (WriteException e) { 
} catch (IOException e) { 


ALSO READ  How to Get HTML Source of WebElement in Selenium WebDriver using Python

WriteExcel Class

package com.selenium.elements;
import java.util.concurrent.TimeUnit;
import jxl.write.Label;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import com.selenium.Utility.Excelutility;

public class WriteexcelFile extends Excelutility {

 WebDriver driver;
 String baseUrl = "";

 @Test(priority=1,description="Test Case 1-Open Firfox Browser and open baseUrl")

 public void openBrowser() throws RowsExceededException, WriteException{
 driver = new FirefoxDriver();
 System.out.println("baseUrl is open in Firefox Browser");
 String Title=driver.getTitle();

 if(Title.equalsIgnoreCase("HP Loadrunner Tutorial")){



 Testcase = "FAIL";


 Label l3=new Label(4,1,Testcase);

 @Test(priority=2,description="Test Case 2-Submit Query in the System")
 public void submitQuery() throws InterruptedException, RowsExceededException, WriteException{
 String name = writablesh.getCell(1,3).getContents();
 System.out.println("System enters name field.");
 String emails = writablesh.getCell(2,3).getContents();
 System.out.println("System clears the fields");
 String message = writablesh.getCell(3,3).getContents();
 String nametext = driver.findElement("ContactForm1_contact-form-name")).getAttribute("value");
 System.out.println("Print nametext is -"+nametext);

 Testcase = "PASS";


 Testcase = "FAIL";


 Label l3=new Label(4,2,Testcase);


Please watch VIDEO Tutorial


Test Results:

How To write Test Case is PASS or FAIL using Selenium


TESTNG Results:


How To write Test Case is PASS or FAIL using Selenium

Please provide your valuable comments on this topic and Please try to practice this example and provide your feedback.For more real time examples,please Read Selenium Complete Tutorials.

Rajesh K

3 thoughts on “How To write Test Case is PASS or FAIL using Selenium

  1. Tester should always focus in test data that he is going use for validating an application. Aim of this article is to provide importance of test data in testing as well as to provide the standard guidelines to prepare test data that can be used for testing.

    Test Data Introduction:

    Test data is nothing that the inputs that are planned by the tester to test the software/application. These planned data or inputs are added as column in the test case to showcase that these type of input should be given. This documentation of adding the inputs will be done during the test case preparation.

    Based on the input expected result of the application functionality will get differs that are all added as different scenarios during the test case preparation. Check out the top 10 difference between manual & automation testing before going further.
    Best Tips to Design your Test Data Properly

  2. Hi, Thanks for sharing this. but what if we have to write test results for hundreds of corresponding test data? could you please share with me how to write test results for corresponding each test data without hard coding the row number and collum number.

Comments are closed.