0
votes

I am using ITestListener, Extent Manager for Generating Extent Report. It is working fine. I'm calling 5 @Test methods from another method. The Reports (TestNG & Extent Report) usually showing only 1 output for the executed test. Please suggest any other way to get the @Test Output when they called from another method. I want to control execution of my methods through from excel instead of creating long XML files.

Please Check my sample Code: Suggest any other way to acheive the Report

My TestNG XML file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="logixexpress" parallel="false">
    <listeners>
        <listener class-name="common.CommonITestNGListener"></listener>
    </listeners>
    <parameter name = "Browser" value = "Chrome"></parameter>
    <parameter name = "DataFile" value = "\\TestData\\Express.xlsx"></parameter>
    <parameter name = "AppRepoFile" value = "\\OR\\AppRepo.properties"></parameter>
    <test name="Express Test Execution">
        <classes>
            <class name="logixexpress.Driver">
            </class>
        </classes>
  </test> 
</suite> 

My Driver Script:

public class Driver extends commonhelper{
public static int Drvrownum  = 3;

@Test
public void ExecuteDriver() throws Exception {
for (int i = Drvrownum; i < (ExcelWS.getLastRowNum() + Drvrownum); i++) {
    String mname = GetDatafromCell("Global", Drvrownum, "ActionName");
    String EF = GetDatafromCell("Global", Drvrownum, "ExecutionFlag");
    if (EF.equalsIgnoreCase("false")) {
        Drvrownum = Drvrownum + 1;
        continue;
    }
    else {          
        switch (mname) {
        case "WorkQueue":
                WorkQueue wq = new WorkQueue();
                wq.RunWQcases();
                Drvrownum = Drvrownum + 1;
                break;                          
        case "XXX":
            System.out.println("All Iterations Completed");
            Drvrownum = Drvrownum + 1;
            return;             
        default:
            break;
           }
       }    
    }
  }

}

And my test Script:

public class WorkQueue extends commonhelper{
public static int WQrownum  = 2;
public static String EXLFilePath = scrpath + "\\TestData\\Express.xlsx";

@Test
public void RunWQcases() throws Exception {
setExcelFile(EXLFilePath, "WorkQueue");
for (int i = WQrownum; i < (ExcelWS.getLastRowNum() + WQrownum); i++) {
  String WQMname = GetDatafromCell(WQrownum, "ActionName");
  String AEF = GetDatafromCell(WQrownum, "ExecutionFlag");
  if (AEF.equalsIgnoreCase("false")) {
      WQrownum = WQrownum + 1;
      continue;
  }
  else {
      switch (WQMname) {    
      case "ExecuteWQ":
          ExecuteWQ();
          WQrownum = WQrownum + 1;
          break;        
      case "openchart":
          openchart();
          WQrownum = WQrownum + 1;
          break;                
      case "XXX":
          System.out.println("Sub Class Iterations Completed");
          WQrownum = WQrownum + 1;                  
          return;
      }
  }
 }
}

@Test
public void ExecuteWQ() throws Exception {
driver.findElement(By.linkText("Work Queue")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Coding WQ")));
driver.findElement(By.linkText("Coding WQ")).click();     
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//table[@class='main']")));
}

@Test
public void openchart() throws Exception {
WebElement wqtable = driver.findElement(By.xpath("//table[@class='main']"));
  List<WebElement> trow = wqtable.findElements(By.tagName("tr"));
  for (int i = 0; i < trow.size(); i++) {
      boolean getrow = false;
      List<WebElement> tcol = trow.get(i).findElements(By.tagName("th"));
      System.out.println("Number of Columns = " + tcol.size());
      for (int j = 0; j < tcol.size(); j++) {
          if (tcol.get(j).getText().equalsIgnoreCase("Action")) {
              driver.findElement(By.className("grid-edit")).click();
              getrow = true;
              break;
        }
          }
      if (getrow) {
          break;
      }
  } 
  Thread.sleep(2000);
 }
}
1
Share the block of Code.Ishita Shah
Please provide test class with tests.Kovacic
You need to pass the extent report object to your other classes. I resolve this by creating my own extent object class and share it among all my test classes.Bill Hileman
Yes I think in this post Extent Report should not be there. I am really sorry i confused every one. Please check my mentioned code and help me to solve my Issue. I am unable to Edit and remove the Extent Report tagRamesh
Hi Bill, Can you please provide the code to pass the extent object to other classes by looking into my attached code.Ramesh

1 Answers

0
votes

If I correctly understand the question the problem is that the TestNG report does not give any information about the test methods which are being called from another methods. The question includes extent report but for now, I will answer only for the TesNG part,

No.

Inside your @Test method, if you call another @Test method, and you have included only the calling function in your xml file, TestNG will execute both methods but count only 1 as executed tests. For example, if you write something like:

@Test
public void test1()
{
 test2()
 test3()
}

@Test
public void test2()
{
}

@Test
public void test3()
{
}

And you have included only test1 method in your xml file, TestNG will consider only ONE test method is executed and will prepare the reports accordingly.

Additionally, it is a bad practice to design your tests in such a way. Individual tests should be completely independent to each other in all ideal cases. You should probably club both of your tests if it is a single flow. If it is not and you have to use output of one test to another, you can see this .