Here’s how you do it.
Assuming that you have an xml like below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="xml_suite" verbose="2">
<listeners>
<listener class-name="com.rationaleemotions.googleforums.groupdeps.xml.XmlListener"/>
</listeners>
<parameter name="suite_level" value="Cedric"/>
<test name="xml_test">
<parameter name="suite_level" value="Julien"/>
<classes>
<class name="com.rationaleemotions.googleforums.groupdeps.xml.XmlTestClassExample"/>
</classes>
</test>
</suite>
Here’s a listener that retrieves the <suite> level and <test> level parameters.
import org.testng.ISuite;
import org.testng.ISuiteListener;
import org.testng.ITestContext;
import org.testng.TestListenerAdapter;
public class XmlListener extends TestListenerAdapter implements ISuiteListener {
@Override
public void onStart(ISuite suite) {
System.err.println("Suite Level parameter : " + suite.getParameter("suite_level"));
}
@Override
public void onFinish(ISuite suite) {
}
@Override
public void onStart(ITestContext context) {
System.err.println("Test Level parameter : " + context.getCurrentXmlTest().getLocalParameters().get("suite_level"));
}
}
And, if you want to retrieve the values from within a @Test method, here’s how you do it.
import org.testng.ITestContext;
import org.testng.Reporter;
import org.testng.annotations.Test;
public class XmlTestClassExample {
@Test
public void testMethod() {
ITestContext context = Reporter.getCurrentTestResult().getTestContext();
System.err.println("<test> level parameter value : " + context.getCurrentXmlTest().getLocalParameters().get("suite_level"));
System.err.println("<suite> level parameter value : " + context.getSuite().getParameter("suite_level"));
}
}
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.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@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.
Venkatesh,
You would have to do quite a lot of work, if you would like to get these custom attributes that you have added, as part of the existing XmlSuite (or) XmlTest classes.
But that being said, you should still be able to plug-in your logic, which extracts these values, but stores them in a custom data structure that you are managing.
Here’s how you do it.
Hopefully that should help you do what you are trying.
PS: I haven’t done this on my own, but am telling you based on what I u’stand reading TestNG code.
Hope that helps!
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/
Reply-To: <testng...@googlegroups.com>
Date: Thursday, March 29, 2018 at 5:49 PM
To: testng-users <testng...@googlegroups.com>
Subject: Re: [testng-users] Read attributes at test and suite level
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.
--
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.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@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.
--
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+unsubscribe@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.