Monday, December 7, 2009

Keyword Driven Frameworks

We come across this phrase of Keyword driven frameworks, every time we think of test automation. There are commercial tools that come inbuilt with the keyword driven approach implemented. So what is this Keyword Driven Framework?

In Keyword Driven Frameworks, we design a framework to accept certain keywords as triggers to start the test. It is the Keyword that a tester provides, which drives the test, and hence the name. The main and the most important feature of a Keyword driven framework is its reusability. The same keyword could be used across different applications and platforms.

Consider an example where the test case is for a login web page. While considering a login page, there would be a text field that accepts username, a text field that accepts password and also a Sign In button. A classic Keyword Driven Framework would suggest us to tackle this situation using three keywords – “Open WebPage”, “Enter Values” and “Click”. One needs to write procedures for these three keywords only. The keywords would look somewhat like:

  · Open WebPage(“www.yahoo.com”)
  · Enter Value(“username”, “tester01”)
  · Enter Value(“passwd”, “password”)
  · Click(“.save”)

Now, doesn’t it seem like, if we change the url and object ids, for gmail, it would work? Certainly Yes. It needs to work even for any other site as well, till the page technology does not really differ from the normal. So this means that we achieve reusability of the procedures and hence the framework, in a keyword driven approach.

In order to get a better idea, I have added the code for the same. Please find the code section below for the same below:

Call OpenWebPage("http://www.test.com/")
Call EnterValue("Email", "username")
Call EnterValue("Passwd", "password")
Call ClickButton("signIn")

Function OpenWebPage(strURL)
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  IE. Navigate strURL
  Do Until IE.ReadyState = 4
    Wscript.Sleep 1000
  Loop
End Function

Function EnterValue(strObjName, strValue)
  If strObjName <> "" And strValue <> "" Then
    IE.Document.GetElementByID(strObjName).Value = strValue
  Else
    MsgBox "Invalid Inputs"
  End If
End Function

Function ClickButton(strButton)
  If strButton <> "" Then
    IE.Document.GetElementByID(strButton).Click
  Else
    MsgBox "Button name is not valid"
  End If
End Function

The above code would work for yahoo as well as gmail or any other site. With some more modifications, which includes creating an excel based input test case to read the inputs, and an HTML report to show the results of test case execution. This would make the the process of a keyword driven framework complete, like the one we can find in any commercial tool.

1 comment: