Understanding the keyword driven framework

Next, we come to a very important juncture, where we come to understand what a Keyword-Driven framework is. A Keyword Driven framework is one in which keywords are written in an external file, such as .xls or xlsx . The common practice is to use the Keyword-Driven framework along with test data. Such a framework is called a Hybrid Keyword Framework. 

We will have a very simple Excel document for this framework, which will be called Framework.xls, and this sheet will have two tabs, namely TestConfig and TestCases. We have already seen in Chapter 2Understanding the Document Object Model and Creating Customized XPaths, what the TestConfig tab looks like, and we also extracted records for which the Execute column was marked as Y. Let's see what the TestCases tab looks like.

The following screenshot shows the TestCases tab:

The TestCaseID in the TestCases tab should map to the TestConfig tab. If the Execute flag for test case TC001 is 'Y' in the TestConfig tab, then all the test steps for test case TC001 should execute in order from top to bottom.

Let's first extract this data by modifying our initial query which was as shown here:

 select TestCaseID from TestConfig where Execute_Flag='Y'

The modified query is shown here:

 Select * from TestCases where TestCaseID in (select TestCaseID from TestConfig where Execute_Flag='Y')

Let's extract data from the TestCases tab now.

Let's have a look at an Extract Program. 

The code shown below uses the previous query to extract TestCases steps based on Execute Flag:

  public static void main(String[] args) throws FilloException {
Fillo fillo = new Fillo();
Connection conn = null;
Recordset rcrdset = null;
try {
conn = fillo
.getConnection("C:\SeleniumWD\src\main\resources\Framework.xlsx");
String query = "Select * from TestCases where TestCaseID in (select TestCaseID from TestConfig where Execute_Flag='Y')";

rcrdset = conn.executeQuery(query);

while (rcrdset.next()) {
System.out.println(rcrdset.getField("TestCaseID") + ":::"
+ rcrdset.getField("Keyword") + ":::"
+ rcrdset.getField("Object") + ":::"
+ rcrdset.getField("Data"));
}
} catch (FilloException e) {
throw new FilloException("Error in query");
} finally {
rcrdset.close();
conn.close();
}
}

The output from the previous code is as follows:

TC001:::OpenBrowser:::NULL:::NULL
TC001:::Navigate:::NULL:::http://www.freecrm.com
TC001:::EnterText:::USERNAME:::USERNAME
TC001:::EnterText:::PASSWORD:::PASSWORD
TC001:::Click:::LOGINBTN:::NULL
TC001:::click:::LOGOUT:::NULL

One important thing to be noted about this output is that, after getting it, we need to send it to the framework so that the UI automation can proceed. For this purpose, we will require an ArrayList of Map, which we will see in the next section. Let's first look at how we extract the test data.

The data in bold is extracted from the Data column of the Excel sheet. If you notice, for the Navigate keyword we have the data hardcoded, but the data in bold seems to be in the form of variables of some sort. And, of course, they are variables. They represent what are called the Keys of a property file—say, for example, the name of the property file is Login.properties, the contents of which are shown here:

USERNAME=admin
PASSWORD=adminpass

The value on the left side of = is the key and the one on the right is the value.

The code to extract the values of the corresponding Keys is given here:

   public static void main(String[] args) throws IOException {
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream(
"C:\SeleniumWD\src\main\resources\Login.properties");
prop.load(input);
System.out.println("Username: " + prop.getProperty("USERNAME"));
System.out.println("Password: " + prop.getProperty("PASSWORD"));
} catch (FileNotFoundException e) {
throw new FileNotFoundException();
} finally {
input.close();
}
}
}

The output from the above program is
Username: admin
Password: adminpass
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.68.14