Reputation: 91
I'm wondering is it possible to put parameters in method when I use testng.xml. I know about put parameteres in test class. I use page object model approach. Here is my code
<suite name="dev-parametrization" verbose="1" >
<test name="Paragraphs-Tests">
<classes>
<class name="com.java.tests.ParagraphsApiControllerTests">
<methods>
<include name="createParagraph">
<parameter name="paragraphsURL" value="http://192.168.0.139:8880/paragraphs"/>
</include>
</methods>
</class>
</classes>
</test>
Below test class
public class ParagraphsApiControllerTests {
Paragraphs paragraphs = new Paragraphs();
@Parameters({"paragraphsURL"})
@Test(priority = 1)
public void createParagraph() {
paragraphs.createParagraph();
}
And my method - here I want to use parameter from xml. file. Is it possible? How can I do this?
public class Paragraphs {
String paragraphsURL = "http://192.168.0.139:8880/paragraphs";
String apiParagraphsURL = "http://192.168.0.139/api/paragraphs";
public void createParagraph() {
RestAssured.baseURI = paragraphsURL;
Upvotes: 0
Views: 73
Reputation: 803
Don't use the same method name in test class and in Paragraph
class. I changed the test class method name from createParagraph
to testCreateParagraph
.
Testng.xml
<suite name="dev-parametrization" verbose="1" >
<test name="Paragraphs-Tests">
<classes>
<class name="com.java.tests.ParagraphsApiControllerTests">
<methods>
<include name="testCreateParagraph">
<parameter name="paragraphsURL" value="http://192.168.0.139:8880/paragraphs"/>
</include>
</methods>
</class>
</classes>
</test>
Test class
public class ParagraphsApiControllerTests {
Paragraphs paragraphs = new Paragraphs();
@Parameters({"paragraphsURL"})
@Test(priority = 1)
public void testCreateParagraph(String paragraphsURL) {
paragraphs.createParagraph(paragraphsURL);
}
Paragraph class
public class Paragraphs {
public void createParagraph(String paragraphsURL) {
RestAssured.baseURI = paragraphsURL;
}
}
Refer this tutorial for more information
Upvotes: 1