Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Write test using Data Provider with @Parameter

39 views
Skip to first unread message

Daniel Panggabean

unread,
Sep 18, 2024, 11:51:03 PM9/18/24
to testng-users
Hello everyone, i have a trouble using Data Provider with @Parameter

Context
  • I'm using appium2, testng 7.5 with java
  • My code (Login test case) already passed and it run in parallel device
  • The user credentials are from @DataProvider (the passed test one is using the same credential)
What i want:
  • Use the different credential for each device
    for example:
    if(testDataId.equals(testDataIdFromDataProvider)){ phoneNumber = phoneNumberFromDataProvider; password = passwordFromDataProvider }

I’ve tried to combine the @Parameter and Data Provider like:

The Test file:

@Test(priority = 1, dataProvider = "loginCredentials", dataProviderClass = LoginDataProvider.class) @Parameters("testDataId") public void handleSuccessLogin(String testDataIdMark, String phoneNumber, String password, String testDataId){ System.out.println("testDataIdMark "+testDataIdMark); System.out.println("phoneNumber "+ phoneNumber); System.out.println("password "+ password); System.out.println("testDataId "+ testDataId); }

The DataProvider file:

public class LoginDataProvider { @DataProvider(name = "loginCredentials") public Object[][] getTestData() { return new Object[][]{ {"1", "123456", "111111"}, {"2", "654321", "222222"} }; } }

The XML file:

<test name="Login"> <parameter name="appiumPort" value="4723"/> <parameter name="platformName" value="android"/> <parameter name="platformVersion" value="5"/> <parameter name="udid" value="xxxxxx"/> <parameter name="appPackage" value="mtda.xxx"/> <parameter name="appActivity" value="com.xxx"/> <parameter name="testDataId" value="1"/> <classes> <class name="testcases.LoginTestCase"> </class> </classes> </test> <test name="Login2"> <parameter name="appiumPort" value="4725"/> <parameter name="platformName" value="android"/> <parameter name="platformVersion" value="7"/> <parameter name="udid" value="xxxxxx"/> <parameter name="appPackage" value="mtda.xxx"/> <parameter name="appActivity" value="com.xxx"/> <parameter name="testDataId" value="2"/> <classes> <class name="testcases.LoginTestCase"> </class> </classes> </test>

But it return error:

has no parameters defined but was found to be using a data provider (either explicitly specified or inherited from class level annotation). Data provider mismatch
Thanks for your time to read and response my mail.

Krishnan Mahadevan

unread,
Sep 20, 2024, 2:05:27 AM9/20/24
to testng...@googlegroups.com
Daniel,

I have answered this same question that you posted on stack overflow here https://stackoverflow.com/questions/78993461/appium-parallel-device-using-data-provider-and-parameter

Please accept the answer if it solves your question.

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-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/58ce1c8f-6f7f-463b-978e-aa668dc4d672n%40googlegroups.com.

Daniel Panggabean

unread,
Sep 22, 2024, 10:00:25 PM9/22/24
to testng-users
Hi @Krishnan, i will try to apply it for my case, thanks!
Reply all
Reply to author
Forward
0 new messages