Sunday, October 14, 2018

How to pass heterogeneous parameters from testng.xml in TestNG?

In the previous post we have seen passing only String data as parameters from testng.xml, that is we passed homogeneous data to test method.

But sometimes we have to pass different types of data, that is heterogeneous data to the test method. How to do it in TestNG from testng.xml file.

Check the below example, suppose we are filling a registration form which requires different data types like String, int, long Boolean. Then we need to write a test method that accepts different data types as below

Add the parameter to be passed in testng.xml as below.

If we observe, though the test method accepting different data types we are not specifying data type for parameters in testng.xml, wouldn't that be a problem when we execute the test? answer is "No". Because TestNG is intelligent enough to convert the received data to required type. And we can't specify data type in testng.xml file.

Let us execute the test and see whether TestNG is able to accept the heterogeneous data and perform actions using it. See the below screenshot after execution all the data is accepted and printed in the console.

This is how we can work with heterogeneous test data in TestNG.

Please comment your suggestion or queries on this post. #HappyLearning #HappyTesting #QABABU

No comments:

Post a Comment

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...