Krunal
Krunal

Reputation: 61

I would like to get MethodName in my report

I am trying to logged my called method name in report when i am creating node.

I tried it with getname(), Method.GetMethodName in ITestresult but not getting proper way to find out.

public static class Reports 
{
    public static void CreateNode(String Description)
    {
        test.createNode(Description);
    }
}



public static Class ModuleClass
{
    public static void Login()
    {
        Reports.CreateNode( ???": method started");
    }
}

In question mark area i would like my method name which printed in report.

Out put like should be -

Login : method started in report.

it is not regarding logging. It base on any method i call from my test library of any specific module.Let's assume there is one method which filling form like below :

public static Class ModuleClass
    {
        public static void FormFilled()
        {
            Reports.CreateNode( ???": method started");
        }
    }

so when i called this method in my execution class like below :

@Test
public void SavingForm()
{
    ModuleClass.FormFilled();
}

then after execution in report i should get :

output FormFilled : method started

Upvotes: 0

Views: 106

Answers (1)

Krunal
Krunal

Reputation: 61

I m getting output by using below line :

new Object(){}.getClass().getEnclosingMethod().getName()

public static Class ModuleClass
    {
        public static void FormFilled()
        {
            Reports.CreateNode( new Object(){}.getClass().getEnclosingMethod().getName() 
 + ": method started");
        }
    }

Upvotes: 1

Related Questions