How to customize TestNG report based on Group instead of @Test?

114 views
Skip to first unread message

Hoang Nguyen

unread,
May 17, 2017, 11:31:30 PM5/17/17
to testng-users
Hi all,

I'm facing one issue about customization TestNG report

One TestCase in my scenario is defined by a group, not a @Test (it can include many @Test)

@Test(groups = {"Test00"})
public class Test00
{
    WebDriver Chrome2;

    Customer_Common Customer_Common_Chrome2;
    Customer_Login Customer_Login_Chrome2;
    @Test(alwaysRun = false)
    protected void AAsetUp() throws Exception
    {
        System.setProperty("webdriver.chrome.driver", "D:\\AutoTest\\Java\\WebDriver\\chromedriver.exe");
    }
    @Test(alwaysRun = false)
    protected void GoToURL() throws Exception
    {
        ....
    }
    @Test(alwaysRun = false)
    protected void Login() throws Exception
    {
        ....
    }
}

Currently the report is show there are 3 tests, because it count based on annotation @Test
My expectation is the report should recognize 1 test.
Any other way to count Test based on Group instead of @Test?

Many thanks,
Hoang

Hoang Nguyen

unread,
May 18, 2017, 6:38:07 AM5/18/17
to testng-users
another thing:
By default TestNG and JUnit treat a annotation @Test is a Test Case
How to custom to treat a Class is a Test Case (instead of annotation @Test). It need for the report correctly.

Krishnan Mahadevan

unread,
May 18, 2017, 11:50:17 AM5/18/17
to testng...@googlegroups.com

Hoang,

 

If you would like to group two or more @Test methods based on the group to which they belong to, then you would need to build the reporting mechanism on your own. I don’t think there are any reporters that are out there, which gives you this grouping out of the box.

 

You would start off by building an implementation of IReporter wherein you build both the logical grouping based on group names and also the view part of it.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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 testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Krishnan Mahadevan

unread,
May 18, 2017, 11:55:26 AM5/18/17
to testng...@googlegroups.com

Hoang,

 

TestNG by default recognizes the small unit of work (a testcase) as a method that is annotated using @Test annotation.

 

So if you would like TestNG to treat a class as a Test case (a class which houses one or more @Test annotated methods ), then again, you would need to build this on your own in an org.testng.IReporter implementation. I don’t think there’s any reporter implementation out there which can do this for you.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <testng...@googlegroups.com> on behalf of Hoang Nguyen <tind...@gmail.com>


Reply-To: <testng...@googlegroups.com>
Date: Thursday, May 18, 2017 at 4:08 PM
To: testng-users <testng...@googlegroups.com>

--

Hoang Nguyen

unread,
May 21, 2017, 11:57:21 PM5/21/17
to testng-users
Hi Krishnan,

That's is my bad while using a lot of @Test in one TestCase 
I've replaced some @Test with @BeforeMethod and @AfterMethod(alwaysRun = false)

package TestLab.May.May18th.Test_Chrome;

import Libs.Utils.*;
import FrameWork.*;
import Libs.Customer.*;
import Libs.CustomerPayments.*;
import Libs.AdminDev.*;
import Libs.WebMail.*;
import Libs.ComData.*;
import Libs.WinApp.*;
import Libs.Appium.*;
import autoitx4java.AutoItX;
import org.openqa.selenium.WebDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.testng.annotations.*;
import org.sikuli.script.*;
import java.util.Map;
import java.util.HashMap;
import java.util.Arrays;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.chrome.ChromeDriver;


@Test(groups = {"Test00"})
public class Test00
{
WebDriver Chrome2;

Customer_Common Customer_Common_Chrome2;
Customer_Login Customer_Login_Chrome2;
   @BeforeMethod(alwaysRun = false)

protected void AAsetUp() throws Exception
{
System.setProperty("webdriver.chrome.driver", "D:\\AutoTest\\Java\\WebDriver\\chromedriver.exe");
      Utils.loadJacobLibraries();
AutoItX autoIT_Chrome2 = new AutoItX();
Map<String, Object> plugin_Chrome2 = new HashMap<String, Object>();
plugin_Chrome2.put("enabled", false);
plugin_Chrome2.put("name", "Chrome PDF Viewer");
Map<String, Object> prefs_Chrome2 = new HashMap<String, Object>();
prefs_Chrome2.put("download.default_directory","D:\\AutoTest\\TestData\\Files\\Download");;
prefs_Chrome2.put("profile.default_content_settings.popups", 0);
prefs_Chrome2.put("plugins.plugins_list", Arrays.asList(plugin_Chrome2));
prefs_Chrome2.put("credentials_enable_service", false);
prefs_Chrome2.put("profile.password_manager_enabled", false);
DesiredCapabilities caps_Chrome2 = DesiredCapabilities.chrome();
ChromeOptions options_Chrome2 = new ChromeOptions();
options_Chrome2.setExperimentalOption("prefs", prefs_Chrome2);
options_Chrome2.addArguments("start-maximized");
options_Chrome2.addArguments("disable-infobars");
caps_Chrome2.setCapability(ChromeOptions.CAPABILITY, options_Chrome2);
caps_Chrome2.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
Chrome2 = new ChromeDriver(caps_Chrome2);
Buffer.Add("Chrome2",autoIT_Chrome2.winGetHandle("data:, - Google Chrome"));

Customer_Common_Chrome2 = new Customer_Common(Chrome2);
Customer_Login_Chrome2 = new Customer_Login(Chrome2);
}
@Test(alwaysRun = false)
public void Test00() throws Exception
{
Utils.RearrangeTCResultsLogFile("D:\\AutoTest\\TestScriptsRepository\\TestLab\\May\\May18th\\Results\\Test_Chrome\\Test00");

Customer_Common_Chrome2.LaunchBrowser("https://mail.google.com");
Customer_Login_Chrome2.Login("us...@gmail.com", "Password", "true", "null");

}
@AfterMethod(alwaysRun = true)
protected void ZZCleanUP_1() throws Exception
{
Utils.CleanUp();
Customer_Login_Chrome2.Logout();
}
@AfterMethod(alwaysRun = true)
protected void ZZCleanUP_2() throws Exception
{
Utils.CleanUp();
Customer_Common_Chrome2.CloseBrowser();
}
}

Vào 22:55:26 UTC+7 Thứ Năm, ngày 18 tháng 5 năm 2017, Krishnan đã viết:
Reply all
Reply to author
Forward
0 new messages