How can I make condition to use data provider for test?

148 views
Skip to first unread message

Eyal

unread,
Aug 30, 2021, 6:29:14 AM8/30/21
to testng-users
Let's say I have a test that needs to get 2 jsons file (but differents)
so I want to say to the test that if the file is x then provide him, else provide another one

⇜Krishnan Mahadevan⇝

unread,
Aug 31, 2021, 12:33:02 AM8/31/21
to testng-users
How are you going to be adding the condition that controls the data provider ?

A simple way would be to pass the toggling mechanism via a JVM argument which your data provider can query and then pass the respect file.

The "@DataProvider" annotated method can also accept an "ITestContext" object. So you could have this dynamic behaviour built by passing in parameters as well from your suite xml, which can be read via the ITestContext object in your TestNG data provider.

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/


On Mon, Aug 30, 2021 at 3:59 PM Eyal <eyal...@gmail.com> wrote:
Let's say I have a test that needs to get 2 jsons file (but differents)
so I want to say to the test that if the file is x then provide him, else provide another one

--
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/9ca97685-693a-48af-9318-1b26fc114a34n%40googlegroups.com.

Baubak

unread,
Sep 17, 2021, 8:17:27 PM9/17/21
to testng-users
Nice solution Krishnan. I should try that.

I solved a similar problem by injecting the data-provider values from the OnStart method of the TestListener.
Reply all
Reply to author
Forward
0 new messages