I want to print the value \"iPhone5\" from the key parameter name =\"webdriver.deviceName.iPhone\" .
There are basically two ways in which you do this from within a Test Class (A test class is essentially a class that houses one or more @Test/configuration methods)
ITestContext object. You can get access to the current method's ITestResult object by calling Reporter.getCurrentTestResult().getTestContext()ITestContext object. For more details on native injection please refer to the TestNG documentation hereHere's a sample that shows both these in action.
import org.testng.ITestContext;
import org.testng.Reporter;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class SampleTestClass {
private static final String KEY = "webdriver.deviceName.iPhone";
@BeforeClass
public void beforeClass(ITestContext context) {
String value = context.getCurrentXmlTest().getParameter(KEY);
System.err.println("webdriver.deviceName.iPhone = " + value);
}
@Test
public void testMethod() {
String value = Reporter.getCurrentTestResult().getTestContext().getCurrentXmlTest().getParameter(KEY);
System.err.println("webdriver.deviceName.iPhone = " + value);
}
}