Data Driven Frameworks could be therefore defined as a set of application specific scripts which tests and validates the application against application data. Consider the following architecture of a sample framework.
Fig: A Sample Data Driven Framework
Here, the data pool would contain the data necessary for testing the application. This includes both the input data, as well as the data for result analysis. There will be a large amount of Hardcoded part in the script, apart from the varying data input section.
Let me explain this in an easier way. If we design a data driven framework to test a website namely www.google.com, we cannot test another similar website like www.altavista.com with the same framework. The reason behind this is that the scripts that we use will include sections where the object names of the google web page, which are hardcoded in our framework.
Now, let me just show an example where the test case checks the second page for the search keyword. Find the following VBScript code. The code just tests the google search. You can download the code and input file here (http://www.4shared.com/file/152128664/3d731c19/DDF_Sample.html)
The Code:
Dim IE, strTestInput(100), strTestVal, strActualResult, strTextFile, intCount, i
'Setting the Folder Path
Path = Replace(Wscript.ScriptFullName, Wscript.ScriptName, "")
'Reading the inputs from Text File
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(Path&"testinput.txt") Then
Set strTextFile = FSO.OpenTextFile(Path&"testinput.txt", 1, True)
intCount = 0
Do Until strTextFile.AtEndofStream
strTestInput(intCount) = strTextFile.Readline
intCount = intCount + 1
Loop
'Performing the Search on Google
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
i = 0
Do Until i = intCount
IE.Navigate "www.google.co.in"
Do Until IE.ReadyState = 4
Wscript.Sleep 1000
Loop
IE.Document.GetElementByID("q").Value = strTestInput(i)
IE.Document.GetElementByID("btnG").Click
Wscript.Sleep 3000
strActualResult = IE.Document.GetElementByID("q").Value
If StrComp(strActualResult, strTestInput(i)) = 0 Then
MsgBox "Pass!!"
Else
MsgBox "Fail!!"
End If
i = i + 1
Loop
IE.Quit()
Set IE = Nothing
Else
MsgBox "The file "&Path&"testinput.txt"&" does not exist. Please create the file with test inputs before proceeding"
End If
Note: In order to use the code, one should create a text file named “testinput.txt” with the input values.
The fact is that one cannot test another website with this piece of code. The code is specifically for www.google.com. This could be taken as an example of a data driven test script.
Good One!
ReplyDeleteThanks for the Script part.
ReplyDelete