Is there any way to use parameters in a function if the function has @test annotation. I have a function like below:
@Test(@Test(priority=1, alwaysRun =true))
public void Home_page_Flextronics(String sUserName, String sPassword) throws FileNotFoundException
{
CommonFunctions.LaunchApplication();
CommonFunctions.Login(sUserName, sPassword);
CommonFunctions.ClickOnModule("Customers");
CommonFunctions.ClickOnHome();
CommonFunctions.Logout();
}
However when I am trying to run above code its giving me error:
Method Home_page_Flextronics requires 2 parameters but 0 were supplied in the @Test annotation.
If I remove the parameters and use hardcoded values, its working fine and it is requirement of my framework. I have gone through other solutions mostly suggest to use @Parameter annotation or data provider. But I don't want to use that as I want to take testdata from excel sheet. Please let me know if there is any other way present to handle this. Thanks for your help in advance.
You could take a look at Junit Theories (introduction)
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertTrue;
@RunWith(Theories.class)
public class AdditionWithTheoriesTest {
@DataPoints
public static int[] positiveIntegers() {
return new int[]{
1, 10, 1234567};
}
@Theory
public void a_plus_b_is_greater_than_a_and_greater_than_b(Integer a, Integer b) {
assertTrue(a + b > a);
assertTrue(a + b > b);
}
}
This way you can pass parameters to a test. In your method annotated with DataPoints you'll need to fetch all the excell data and return it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With