@DataProvider Question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

@DataProvider Question

praveen133t
Let's say I have a text file with the following data

username=testuser
password=testpassword
address=testaddress
zipcode=12345


I have a test as below

public class DPTest {

   @Test(dataprovider="testdp")
   public void userTest_01(String username, String Password) {

   //Test goes here

   }
}

Another class

public class DPTest2 {

   @Test(dataprovider="testdp")
   public void userTest_02(String email, String address, String password) {

   //Test goes here

   }
}


Can my dataprovider read the values from the above mentioned text file and supply it to the test methods?

As per my udnerstanding the data provider is going to read all the lines in the sheet and supply it to the test method and throw and error saying "data provider is trying to provide 6 params but Test can only accept 2 params" ?

Please help me.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @DataProvider Question

⇜Krishnan Mahadevan⇝

The data in your text file
username=testuser
password=testpassword
address=testaddress
zipcode=12345

Is this 6 rows of data or is is this 1 row of data with 6 columns ? 

Please help clarify this part first.

If it is 1 row with 6 columns and you want to use the same data provider with different test methods which need different parts of this data

for e.g., 1 test method could just need userName and password (for some login), while there could be another test method, which needs all the 6 columns for say database validation, the best way of getting this done is to create a POJO [ Plain Old Java Object] (or) a simple class and define data members to it based on your actual dataset's columns and then pass this to each test method.

That way, your test method would still get the entire object, but has the luxury of extracting whatever it needs.

IMO, this would be the only way in which you can use the same data provider with multiple test methods, wherein each test method needs different data (from the same data source ofcourse)





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/


On Thu, Jun 5, 2014 at 3:20 AM, Tushaar <[hidden email]> wrote:
Let's say I have a text file with the following data

username=testuser
password=testpassword
address=testaddress
zipcode=12345


I have a test as below

public class DPTest {

   @Test(dataprovider="testdp")
   public void userTest_01(String username, String Password) {

   //Test goes here

   }
}

Another class

public class DPTest2 {

   @Test(dataprovider="testdp")
   public void userTest_02(String email, String address, String password) {

   //Test goes here

   }
}


Can my dataprovider read the values from the above mentioned text file and supply it to the test methods?

As per my udnerstanding the data provider is going to read all the lines in the sheet and supply it to the test method and throw and error saying "data provider is trying to provide 6 params but Test can only accept 2 params" ?

Please help me.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: @DataProvider Question

praveen133t
In reply to this post by praveen133t
Hi Krishnan,

It's 6 different rows. This data is not just for one test case. It could be for hundreds of test cases. A test case can consume one row or even all rows. 

I got it working. I created a new annotation and I'm passing the variable names as parameter to the annotation. Eg : @readXML({"username","password"})   or  @readXML({"username","password","email"})

I wrote a logic to read the xml or text file based on the parameter supplied to the newly created annotation.

 I hope it's the right way to handle it. could you pls tell me if there is a better way to do it?

Thanks!

On Wednesday, June 4, 2014 4:50:16 PM UTC-5, Tushaar wrote:
Let's say I have a text file with the following data

username=testuser
password=testpassword
address=testaddress
zipcode=12345


I have a test as below

public class DPTest {

   @Test(dataprovider="testdp")
   public void userTest_01(String username, String Password) {

   //Test goes here

   }
}

Another class

public class DPTest2 {

   @Test(dataprovider="testdp")
   public void userTest_02(String email, String address, String password) {

   //Test goes here

   }
}


Can my dataprovider read the values from the above mentioned text file and supply it to the test methods?

As per my udnerstanding the data provider is going to read all the lines in the sheet and supply it to the test method and throw and error saying "data provider is trying to provide 6 params but Test can only accept 2 params" ?

Please help me.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.