How to change the TestMethod name dynamically in Emailable Report

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to change the TestMethod name dynamically in Emailable Report

Premchand Papineni
Hi

I am New to this Selenium TestNG framework.
I am tring to read the data from excel sheet and pass to the method which i am able to do but my problem is to show in Report with testcase name. Please help me in this.


In my Email report i have to change the Testmethod name to the Testcase name_stepName based on the string from datasheet.

this is my code.


import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.testng.SkipException;
//import org.testng.annotations.AfterMethod;
//import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;



public class Interface_Test
  {

public static String url =null; 
public static String filePath = System.getProperty("user.dir");
public static String str_execute = null;
public static String str_filename = null;
public static String str_MarketType = null;
public  int Step_rowNum =1;
public static XSSFWorkbook workbook;
public static XSSFSheet worksheet;
public static DataFormatter formatter= new DataFormatter();
    public void GetEnv_Details( )
      {
        try
          {
             File src=new File(filePath+"/Test_Automation_Framework2.xlsx");
             // load file
             FileInputStream fis=new FileInputStream(src);
             // Load workbook
             XSSFWorkbook wb=new XSSFWorkbook(fis);
             // Load sheet
             int sheetcount = wb.getNumberOfSheets();
             String  sheetName = null;
             int SheetOrder = 0 ;
             
             for (int i =0; i <sheetcount;i++ )
             {
             sheetName= wb.getSheetName(i);
             if(sheetName.equalsIgnoreCase("Env_Details"))
             {
             SheetOrder =i; 
             }
             
             }
             //System.out.println("SheetOrder is : "+SheetOrder);
             XSSFSheet sh1= wb.getSheetAt(SheetOrder);
             //Read the details into a variable
             url = sh1.getRow(1).getCell(1).getStringCellValue();
             //System.out.println("url is : "+url);    
          }        
        catch (Exception e)
          {     
             System.out.println(e.getMessage());
          }
      }
          
    public void Create_ClientProperties( String str_filename, String str_MarketType, String str_execute )
      {
         
    try
          {
            
       
             File file=new File(filePath+"client.properties"); 
             if (file.exists())
               {
                  file.delete();
               }
             else
               {
                  //Create the file
                  file.createNewFile();
               }
             //String semi = Character.toString((char)34);
             
             StringBuffer dataloadfile_str = new StringBuffer("Hello");
             //Write Content
             FileWriter writer = new FileWriter(file);
             writer.append(dataloadfile_str);
             writer.close();  
           }        
         catch (Exception e)
           {     
             System.out.println(e.getMessage());
           }
        }
     
    
    
@BeforeMethod
    public void create_PFiles()
      {
        GetEnv_Details( );
        
      }


@Test (dataProvider="ReadExcel")
    public void TestCase(String Test_Case, String Description, String Test_Case_ID, String Test_Step_no, String Market_Type, String File_Name, String Execute, String Expected_Result )
  {
if(Execute.equalsIgnoreCase("Y"))
{
       Create_ClientProperties(File_Name, Market_Type, Execute );
    
              }
            else
            {
           
                   throw new SkipException("Skipping - This is not ready for testing ");
              }
   
      } 

@DataProvider
    public static Object[][] ReadExcel() throws IOException
    {
            File src=new File(filePath+"/Test_Automation_Framework2.xlsx");
             // load file
            FileInputStream fis=new FileInputStream(src);
            XSSFWorkbook wb=new XSSFWorkbook(fis);//get my workbook 
//workbook = new HSSFWorkbook (fileInputStream); //get my workbook 
            int sheetcount = wb.getNumberOfSheets();
            String  sheetName = null;
            int SheetOrder = 0 ;
            
            for (int i =0; i <sheetcount;i++ )
            {
             sheetName= wb.getSheetName(i);
             if(sheetName.equalsIgnoreCase("Test_Files"))
             {
             SheetOrder =i; 
             }
             
            }

          
            XSSFSheet sh1= wb.getSheetAt(SheetOrder);// get my sheet from workbook
        XSSFRow Row=sh1.getRow(0);     //get my Row which start from 0   
     
        int RowNum = sh1.getPhysicalNumberOfRows();// count my number of Rows
        int ColNum= Row.getLastCellNum(); // get last ColNum 
         
        Object Data[][]= new Object[RowNum-1][ColNum]; // pass my  count data in array
         
            for(int i=0; i<RowNum-1; i++) //Loop work for Rows
            {  
                XSSFRow row= sh1.getRow(i+1);
                  
                if(row.getCell(6).getStringCellValue().equalsIgnoreCase("Y"))
                {
                System.out.println( "------------- "+row.getCell(6).getStringCellValue());

                for (int j=0; j<ColNum; j++) //Loop work for colNum
                {
                    if(row==null)
                        Data[i][j]= "";
                    else
                    {

                    XSSFCell cell= row.getCell(j);
                        if(cell==null)
                            Data[i][j]= ""; //if it get Null value it pass no data 
                        else
                        {
                   
                            String value=formatter.formatCellValue(cell);
                                Data[i][j]=value; //This formatter get my all values as string i.e integer, float all type data value
                    }
                    }
                }
            }
            }
 
        return Data;
    }
  }

Please find the screenshot as attachment.

Thanks in adavance 
Premchand



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Capture1.JPG (40K) Download Attachment
Capture2.JPG (32K) Download Attachment