Till
now we have discussed about the doLogin() method where we are passing the
default username & password. But in our SignInTest there are multiple test
scenarios with different combinations. So, we should write the script in such a
way that it will run as per the scenarios. To achieve this, we can use
@DataProvider for @Test method.
Before you go ahead with this step, make sure we have followed STEP 5: Add Required .xls Files of Data. & STEP 6: Add .xls File Reading Utility in Framework.
If
you have gone through step by step as mentioned, then you can implement the
below steps or else please go through STEP-5 & STEP-6 first.
For
parameterizing the test cases, follow the below steps:
- Download the .zip from here.
- Extract the .zip file.
- Copy the TestDataProvider.java file inside com.demo.pom.util package.
- Copy & replace the SignInTest.java file inside com.demo.pom.testcases package.
Code Overview:
TestDataProvider.java
This class will contain all the data providers in a
single class file. The class will have a @DataProvider annotation & the
method name. The method name is the dataProvider name in @Test annotation.
Please check the below code:
@DataProvider()
public static Object[][]
getSignInTestData() throws IOException {
return DataUtil.getTestData("SignInTest");
}
In Step-6 we have already discussed
about the DataUtil class. Here, in getSignInTestData() method we are returning a two dimensional
object array which will contain the Column Name & Data for the SignInTest.
SignInTest.java
In this class, we have modified the @Test annotation
by passing the below parameters:
- dataProvider = "getSignInTestData”: The name of the data provider which will be same as the method name in TestDataProvider class.
- dataProviderClass = TestDataProvider.class: Data provider class name.
Key is nothing the column name in the excel sheet. e.g. in line no 27 Object page = lunchPage.gotoSignInPage().doLogIn(data.get("UserName"), data.get("Password")); we are getting the data for UserName & Password columns.
Once you have completed
the above steps, Right Click on SignInTest.java > Run As > TestNG Suite
& verify the results.
Challenges:
- While running the test cases you may observe that for each scenario it’s opening a new browser instance.
- There is no validation check whether the login is success or not.
- No check for Skiping the test case or test scenario.
No comments:
Post a Comment