0

Is there a way I can use Data Provider for only part of the code but not for the entire class?

For example, if I want to do
1. Function A - Login
2. Function B - X (with 5 rows in the data sheet excel and I'd like this function to repeat for 5 times)

How do I run login only once? I tried the following but funcA (login) still runs for multiple times.

class X{
  funcA (@Test)
  funcB (@Test(dataProvider))
}
user6252041
  • 73
  • 2
  • 10
  • Your code trials please. – undetected Selenium Jan 24 '18 at 19:42
  • @DebanjanB it's already in the original post. Are you looking for something more specific? – user6252041 Jan 24 '18 at 20:54
  • What you have provided is just the skeleton. Where is your Data Provider? Where is the Data? What attempts have you taken to make things work? Your Research? Error if any? – undetected Selenium Jan 24 '18 at 20:59
  • DataProvider is in my base class. Data is an excel sheet with multiple lines and each line corresponds to one scenario/iteration based on my needs. I don't have a problem with the data provider itself, it works well. I just want to know if there is a way for me to extract part of the code (funcA in my example) such that it doesn't need to loop through the X iterations defined in the dataProvider sheet (eg. I don't want to perform login for every single scenario defined in my data sheet. I just want to do it once at the beginning) – user6252041 Jan 24 '18 at 21:49

1 Answers1

1

If there is only one test method in your class X use @BeforeClass annotation on funcA since it executes before the first test method in the current class (in this case that would be funcB test method). For more info about @BeforeClass and other before annotations you can check out this site.

Milan
  • 203
  • 2
  • 11