Test Automation Scripting Language - Part 3 of 3
Posted by
JORRIT WIT on Tue, Jan 03, 2012 @ 07:32 AM
Test Automation Scripting Language - Part 3 of 3
What is Scripting Language and How is it Used?

Written by Vijay Deshmukh
Strings
A variable can hold strings using following format
Dim aStringVariable
aStringVariable = “Simple Text”
There are different string related functions such as Len, Right, Left, UCase, LCase etc.
Let us consider a small example of reading a text file:
Dim objFile, strFilePath
strFilePath = “c:\sample.txt”
Set objFile = CreateObject(“Scripting.FileSystemObject”)
If objFile.FileExists(strFilePath) then
Set objReadFile = objFile.OpenTextFile(strFilePath, ForReading)
Do While objReadFile.AtEndOfStream <> True then
Msgbox objReadFile.ReadLine
Loop
objReadFile.Close
Else
MsgBox “File “& strFilePath & “ is not found.”
End
Set objFile = Nothing
Let us analyse the code:
CreateObject will create a file system object.
FileExists will check if the file is available at the specified location.
OpenTextFile will open the file. The first argument this function is file path and second argument is if the file is to be opened for Reading, Writing or Apending. In our case it is for reading.
Next Do While loop will read the file line by line and message box will display this line.
The condition to exit the Do While loop is the end of file. This is done using AtEndOfStream.
After the loop, the line objRedFile.Close will close the file.
If the file is not available at specified location, a message is displayed to the user. This is covered in Else part of If..Then condition.
FileSystemObject is created in above example. Similarly, one can create objects for different applications so they can be automated using VB Script. Following are some of the examples:
CreateObject(“Excel.Application”) to create MS-Excel object.
CreateObject(“Outlook.Application”) to create MS-outlook object.
CreateObject(“Word.Application”) to create MS-Word object
CreateObject(“QuickTest.Application”) to create QTP object.
Like any other application object, QTP object is used to launch QTP during batch mode, to add object repositories dynamically and to add library files dynamically etc.
In similar way, VB Script can be used in simple to medium as well as complex scripting such as generating reports at the end of every script run, sending automatic emails to analyse the test run reports or even logging defects automatically in a defect tracking tool.
As you learn VB Script and become more conversant with the syntax of the in-built functions, usage of the methods, you can create complex scenarios. With QTP’s strong object recording mechanism and power of VB script, most of the manual test cases can be automated.
Other uses of Scripting Languages:
- Development of agents which can be used to build an automation test bed and running automation scripts on multiple machines at the same time
- Integration with hardware devices using device drivers
- Scheduling test runs
- Development of stubs and drivers in early phase of code development and unit testing
- Automation of unit test cases
- Development of end to end automation from: creating a build after code merge, unit testing, smoke testing, regression testing, sending the test run reports through email and raising the defects in defect tracking tool
Conclusion:
In conclusion, scripting language in cohesion with suitable automated testing tool can reduce manual efforts drastically. These efforts can be better utilized for analysing the results as well as executing the tests which cannot be automated.
Resources:
Java Script: http://javascript.internet.com/
VBScript: http://msdn.microsoft.com/en-us/library/t0aew7h6(v=vs.85).aspx
TCL: www.tcl.tk
Python: www.python.org
Ruby: http://www.ruby-lang.org/en/
Perl: http://www.perl.org/
PHP:
http://www.php.net/

The opinions expressed on this discussion room are writer's and don't necessarily represent NTT DATA Canada's positions, strategies or opinions.