Can we Pass an Object Or Map as arguments for the @test method while using dataprovider annotation.

閲覧: 233 回
最初の未読メッセージにスキップ

chenna kesava

未読、
2021/05/05 1:14:402021/05/05
To: testng-dev
I am aware of using the @dataprovider annotation and passing its values to @Test method. we also know that, have to pass exactly same number of arguments in the @Test method as per the number of values in excel.

My question is Can we pass any Object Or Map Or any thing instead of entering all the arguments in the @Test method.

Please suggest me any ways of doing it. 
Also let me know any clarification is required.


⇜Krishnan Mahadevan⇝

未読、
2021/05/05 3:06:152021/05/05
To: testn...@googlegroups.com
What happens when you try doing this using the latest released version of TestNG (7.4.0) ?
If you havent tried it I would suggest that you please give it a shot. TestNG doesnt have any hard and fast rules in terms of what can be passed and what cannot be passed. It all boils down to parameter type/order/length matching via reflection when invoking your test method.

If you are having issues in getting it to work, then please share a sample that can be used to reproduce the problem and post it on the testng-users google forums.

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 Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-dev/97dc186c-a064-460a-addd-d74303a7cfc7n%40googlegroups.com.

chenna kesava

未読、
2021/05/05 3:37:202021/05/05
To: testng-dev
Thankyou Krishnan for the response. I am sharing the sample code below:

I have updated to TestNG 7.4.0

my excel file datacheck.xlsx have 8 fields of data for particular test case. I have given the dataprovider method that retrieves the data and put in data object.

Am utilizing the data Object in @Test method and passing the arguments. It works fine when passed all the arguments. Below code works fine for me.
I need help to avoid writing the all the arguments. Instead using some Object[][] in @Test method.

// Below code is to retrieve the data from excel to Object[][].
@DataProvider
public Object[][] dataone() {
data = Datareader.readExcel("D:\\Users\\Eclipse_Projects\\Selenium\\Testdata\\datacheck.xlsx", "sheet1", "tc1");
return data; 
}

@Test(dataProvider="dataone")
// public void dataone(String Username, String Password, String DocumentType, String Signatory, String Purpose, String Remarks, String Filename, String extra) {
System.out.println("values are : Username : "+ Username+", Password : " + Password+", DocumentType : " + DocumentType+", Signatory :" + Signatory+", Purpose : " + Purpose + " , Remarks : " + Remarks + " , Filename : "+ Filename + "extra : "+extra);

⇜Krishnan Mahadevan⇝

未読、
2021/05/05 3:49:442021/05/05
To: testn...@googlegroups.com
Please do the following:

1. Build a POJO class that represents 1 row of data in your excel sheet. 
2. Refactor your data provider to start constructing POJO objects and have it send back a 2D array of this POJO. 
3. Refactor your test method to start accepting the POJO instead of individual fields.

That should do.

SeLion has an excel data provider that you can perhaps leverage for this, wherein it does the heavy lifting of reading your excel spreadsheet and then packing all the column values into your POJO. All you need to be doing is pass on your pojo class info to it.

Refer to the documentation : http://paypal.github.io/SeLion/html/documentation.html#excel-data-provider to learn how to use it.

You would need to have the data provider as a maven dependency : Maven Repository: com.paypal.selion » SeLion-DataProviders » 1.2.0 (mvnrepository.com)



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 Scribblings @ https://rationaleemotions.com/

全員に返信
投稿者に返信
転送
新着メール 0 件