Testng how to pass parameter to the listener -
i know way pass parameter inside listener eater suite.xml or code itself
i need in parallel test know on device i'm running test in order make reports
this example of have / wish achieve
the suite file
<suite name="searchbutton" parallel="tests" thread-count="5"> <test name="samsungs6"> <parameter name="deviceudid" value="04157df40862d02f"/> <classes> <class name="mytestscenario"/> </classes> </test> </suite> or
@test public void researchtext (){ string deviceudid = "1234"; } i want able find device udid in listener
public void ontestskipped(itestresult result) { system.out.println("my deviceudid "); } i tried find
system.getproperty("deviceudid") // or result.getattribute() // or result.getparameters() without success
any idea on how ?
get* methods cannot work if don't use set* somewhere else.
i see 2 options:
- from test setting data in
itestcontext(itestresult#gettestcontext()) injectable. see the related documentation. - from listener annotation metadata on test method (ie:
@udid("1234")). may more difficult use in test if want avoid duplication.
according example:
@test public void researchtext(itestcontext context){ string deviceudid = "1234"; context.setattribute("udid", deviceudid) } public void ontestskipped(itestresult result) { system.out.println("my deviceudid " + result.gettestcontext().getattribute("udid")); } or
<suite name="searchbutton" parallel="tests" thread-count="5"> <test name="samsungs6"> <parameter name="deviceudid" value="04157df40862d02f"/> <classes> <class name="mytestscenario"/> </classes> </test> </suite> @parameters({ "deviceudid" }) @test public void researchtext (string deviceudid, itestcontext context){ context.setattribute("udid", deviceudid) } public void ontestskipped(itestresult result) { system.out.println("my deviceudid " + result.gettestcontext().getattribute("udid")); }
Comments
Post a Comment