Reputation: 4596
I have started writting test cases for a project, The first page is login page.
i have started to write test case for valid email adress validation.
public void LoginValidEmailProvided(string baseUrl)
{
_driver.Navigate().GoToUrl(baseUrl);
UserIdField.Clear();
UserIdField.SendKeys("abc.xyz.com");
PasswordField.Clear();
PasswordField.SendKeys("");
LoginButton.Click();
}
Now my question is do we need to write different function for each variation for valid emaiil address checking.
Like on manual testing test usually do
some.com
@some.com
@some
some@
some@@@.com
and many more.
so do we have to write test cases for above varaitions in automate testing. or just one variation is suffucient. as I am checking the return message and comparing with expected and what I get. In each case it returns Invalid credentials. So I have just checked is page contains the message Invalid credentials then the Invalid Emaild address test case passed.
Please advise Thanks
Upvotes: 0
Views: 2752
Reputation: 3021
The better approach would be have two methods one to check valid email address and other to check invalid email address
Advantages of having two methods
You can have valid credentials seperately in a file or a data provider(incase of frameworks) and pass valid credentials only to the check valid_email method and invalid credentials to invalid_email method so that if there is any error you can locate it easily(ex : valid credentials is throwing an error saying that the credentials in invalid) if you combine both the credentials then it will be difficult for you to find which is valid and which is invalid
pseudecode :
public void correct_email(){
enter username and other details
click submit
Get the success page or page title of homepage to check email validation passed
}
public void wrong_email(){
enter username and other details
click submit
Get the error page and compare it with the actual error message
}
EDIT :
1.If you're keeping your valid and invalid credentials together and having one method to validate it how do you know if a valid login credentials failed to login it will also throw an error invalid credentials and you're test will pass and you will not notice this error
2.Moreover if you're using frameworks like ex: testng you will get these data in reports if ur parameterizing your tests so in reports also it gives you a clear view of data passed and failed ie)Parameters run using valid credentials and parameters run using invalid credentials .if you use one method to validate vaiid and invalid credentials all will be listed as one.
Hope this helps you.Kindly get back if you have any queries
Upvotes: 1
Reputation: 3711
Do not create a different method you can use data provider for each test !!!
(you can write a rapper that the data provider will look nicer )
http://testng.org/doc/documentation-main.html
//This method will provide data to any test method that declares that its Data Provider
//is named "test1"
@DataProvider(name = "test1")
public Object[][] createData1() {
return new Object[][] {
{ "Cedric", new Integer(36) },
{ "Anne", new Integer(37)},
};
}
//This test method declares that its data should be supplied by the Data Provider
//named "test1"
@Test(dataProvider = "test1")
public void verifyData1(String n1, Integer n2) {
System.out.println(n1 + " " + n2);
}
will print
Cedric 36 Anne 37
Upvotes: 0