How to dynamically add meta data to report?

42 views
Skip to first unread message

Shiv

unread,
Jun 22, 2023, 8:09:59 AM6/22/23
to qaf users
Hi , 

Example BDD steps:
I have use case, where I want to add new meta data to the test case dynamically at runtime(programmatically) so that it reflects the QAF report. How can i achieve this ?

Example- I have below BDD Gherkins syntax. I want to add new metadata say "referenceUrl":"test.com" at run time. So that it reflects in the report that is generate at completion. 

SCENARIO: Example
META-DATA: {"testcaseid":"tc1","description":"description Example"}
Given I am on fruits and colors activity
When i select '${fruit}'
Then the color should be '${color}'

END






cjayswal

unread,
Jul 11, 2023, 12:41:17 PM7/11/23
to qaf users
You can achieve that by using before or after Invocation testng listener method. If
Here is an example how you can access metadata from ItestReuslt object:

@Override
public void beforeInvocation(IInvokedMethod method, ITestResult tr) {
TestNGScenario scenario = (TestNGScenario) tr.getMethod();
//do the needful
scenario.getMetaData().put("referenceUrl",value);
}

You also can get ITestResult object for current running test outside listener using ApplicationProperties.CURRENT_TEST_RESULT.key. For example
ITestResult tr =  (ITestResult)getBundle().getProperty(ApplicationProperties.CURRENT_TEST_RESULT.key)

Shiv

unread,
Jan 25, 2024, 6:24:53 AM1/25/24
to qaf users
Thanks. It helps. 
Reply all
Reply to author
Forward
0 new messages