Parameterisation in JUNIT
Parameter
Annotation In Junit
Parameter annotation work same as we do in DataProvider
annotation
Here we use 2 annotations
1à Parameter annotation
2à Run With Annotation
@Parameter annotation
Method under the parameter annotation is a static method
This return a list
Value returned by Parameter annotation need to be assigned
to variable in constructor
@RunWith annotation
@RunWith(Parameterized.Class)
Need to pass it before class to show that class will run with
parameters
package org.abc;
import
java.util.Arrays;
import java.util.List;
import org.junit.Test;
import
org.junit.runner.RunWith;
import
org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import
org.openqa.selenium.chrome.ChromeDriver;
// Paramter annotation
in junit
@RunWith(value=Parameterized.class)
public class Case2 {
String
uname, pass;
public Case2(String
uname, String pass)
{
this.uname = uname;
this.pass = pass;
}
@Test
public void TestCase()
{
System.setProperty("webdriver.chrome.driver","C:\\Documents
and Settings\\Administrator\\My
Documents\\Downloads\\chromedriver_win32_2.1\\chromedriver.exe");
ChromeDriver f = new ChromeDriver();
f.get("http://mail.in.com");
f.findElementById("f_id").sendKeys(uname);
f.findElementById("f_pwd").sendKeys(pass);
f.findElementByClassName("signin");
}
@Parameters
public static List
Para()
{
Object
arr[][]={{"uname","pass"},
{"uname1","pass1"},
{"unam22","pass2"}};
return Arrays.asList(arr);
}
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment