Testing Techniques
Friday, December 9, 2011
Guidelines to automated tests
• Concise – Test should be as simple as possible and no simpler.
• Self Checking – Test should report its results such that no human interpretation is
necessary.
• Repeatable – Test can be run repeatedly without human intervention.
• Robust – Test produces same result now and forever. Tests are not affected by
changes in the external environment.
• Sufficient – Tests verify all the requirements of the software being tested.
• Necessary – Everything in each test contributes to the specification of desired
behavior.
• Clear – Every statement is easy to understand.
• Efficient – Tests run in a reasonable amount of time.
• Specific – Each test failure points to a specific piece of broken functionality (e.g.
each test case tests one possible point of failure).
• Independent – Each test can be run by itself or in a suite with an arbitrary set of
other tests in any order.
• Maintainable – Tests should be easy to modify and extend.
• Traceable – Tests should be traceable to the requirements; requirements should be
traceable to the tests.
TEst script sample
Dim oConn, rs, sql, result
result = ""
Set oConn = CreateObject("ADODB.Connection")
oConn.Open "DRIVER={Microsoft ODBC for Oracle};UID=scott;PASSWORD=tiger;SERVER=orahome;"
set rs=CreateObject("ADODB.recordset")
sql = "SELECT empno, ename, sal, job from emp where job = 'MANAGER' order by empno"
rs.Open sql, oConn
rs.MoveFirst
While not rs.eof
result = rs.Fields.Item(0)'Field that you want
rs.movenext
msgbox (result)
Wend
rs.close
oConn.close
File2***********INSERT SYNCHRONIZATION POINT DURING RECORDING****************
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "jojo"
Dialog("Login").WinEdit("Password:").SetSecure "472896762adc9fc1d152d9daba8c13da6f833e56"
Dialog("Login").WinButton("OK").Click
Window("Window").WinToolbar("Running Applications").WaitProperty "enabled", 1, 20000
Window("Flight Reservation").Activate
Window("Flight Reservation").WinObject("Date of Flight:").Type "010109"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "London"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").Activate
Window("Flight Reservation").WinEdit("Name:").Set "prat"
Window("Flight Reservation").WinRadioButton("First").Set
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Window").WinToolbar("Running Applications").WaitProperty "enabled", 1, 30000
Window("Flight Reservation").WinButton("Button").Click
'Synchronization point: To define the time mapping between the QTP and application, we use this concept. If we dont want to perform any operation until an object in our application achieves certain status then we can insert
'synchronization point to instruct QTP to pause the test until the object getting the certain value
FILE3************************DESCRIPTIVE STATIC PROGRAMMING***********************
Dialog("Title:=Login").WinEdit("AttachedText:=Agent Name:").Set "mercury"
Dialog("Title:=Login").WinEdit("AttachedText:=Password:").SetSecure"471a551993659d997ef82be92c753bc43ad5ee89"
Dialog("Title:=Login").WinButton("Text:=OK").Click
Window("Title:=Flight Reservation").WaitProperty "enabled", 0, 10000
Window("Title:=Flight Reservation").ActiveX("acx_name:=MaskEdBox").Type "080808"
Window("Title:=Flight Reservation").WinComboBox("attached text:=Fly From:").Select "Frankfurt"
Window("Title:=Flight Reservation").WinComboBox("attached text:=Fly To:").Select "London"
Window("Title:=Flight Reservation").WinButton("text:=FLIGHT").Click
Window("Title:=Flight Reservation").Dialog("title:=Flights Table").WinButton("text:=OK").Click
Window("Title:=Flight Reservation").Activate
Window("Title:=Flight Reservation").WinEdit("attached text:=Name:","focused:=True").Set "test"
Window("Flight Reservation").WinButton("text:=&Insert Order").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
FILE4**************************CALLING FUNCTIONS*************************
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dim uid
uid ="user"
call flt_login(uid)
call flt_createorder(uid)
SystemUtil.CloseProcessByWndTitle "Flight Reservation"
FILE5*********************FUNCTION.VBS FILE**********************FUNCTION DEFINITION************
Function flt_login(aa)
Dialog("Login").WinEdit("Agent Name:").Set aa
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure "4728dc3daf8caff96e25982256ea4d03596b6cbf"
Dialog("Login").WinButton("OK").Click
End Function
Function flt_CreateOrder(aa)
Window("Flight Reservation").WinObject("Date of Flight:").Type "010109"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set aa
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").WinButton("Button").Click
End Function
FILE6*****************REPORT EVENT AND INTRODUCING CHECKPOINT THROUGH PROGRAMMING*********
******************START END TRANSACTION********************
Dialog("Login").WinEdit("Agent Name:").Set "mercury"
Dialog("Login").WinEdit("Password:").Set "mercury"
Dialog("Login").WinButton("OK").Click
If Dialog("Login").Dialog("Flight Reservations").Exist Then
Reporter.ReportEvent micFail, "Password", "Incorrect Password is Supplied. Exiting the test"
End If
'CHECKPOINT TO CHECK WHETHER WINDOW EXISTS OR NOT
If Window("Flight Reservation").Exist Then
Services.StartTransaction "Order"
Services.StartTransaction "MeasureCreateOrder"
Reporter.ReportEvent micPass, "Password", "Correct Password is Supplied. Continueing the test"
Window("Flight Reservation").ActiveX("MaskEdBox").Type "080808"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Los Angeles"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "tester"
Window("Flight Reservation").WinEdit("Tickets:").SetSelection 0,1
Window("Flight Reservation").WinEdit("Tickets:").Set "3"
Window("Flight Reservation").WinButton("Insert Order").Click
Services.EndTransaction "Order"
Window("Flight Reservation").WaitProperty "enabled", 1, 10000
Window("Flight Reservation").WinButton("Button").Click
'Services.EndTransaction "MeasureCreateOrder"
End If
FILE7********************DYNAMIC DESCRIPTIVE PROGRAMMING************
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "jojo"
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure "47290f08700672b09e55dc0c97033b5d1161ab1a"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Activate
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
'Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON"
'Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").Set "ON"
'Window("Flight Reservation").Dialog("Open Order").Click 22,147
Set mydescription=Description.Create()
mydescription("Class Name").value="WinCheckBox"
Set Checkboxes = window("text:=FLight Reservation").dialog("text:=Open Order").ChildObjects(mydescription)
a=Checkboxes.count
msgbox(a)
Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
Steps for Automating a Test Case
Steps for Automating a Test Case – An Example
Problem: A new user wants to register in rediff.com. The website supports multiple languages and it needs to be tested for multiple languages too. This test needs to be automated.
Steps to automate the test
1. Define a test case “Register User”
2. Define a datasheet and make the test data-driven.
3. Define a properties file and capture field names and table names for the registration screen.
Example,
ROOTPATH = "C:\TestScripts\"
BrowserType = "iexplore.exe"
URL = "http://login.rediff.com/"
SheetName = "English"
MainBrowser = "Rediffmail"
MainPage = "Rediffmail"
EditHtmlTag = "html tag:=INPUT"
ListHtmlTag = "html tag:=SELECT"
ButtonType = “type:=button”
ResetType = “type:=reset”
***************Register User Screen Start *************************
If (ScreenName = "RegisterUser - Add") Then
LoginNameField = "name:=login," & EditHtmlTag
PasswordField = "name:=passwd," & EditHtmlTag
RetypePasswordField = "name:=passwd1," & EditHtmlTag
FirstNameField = "name:=fname," & EditHtmlTag
LastNameField = "name:lname" & EditHtmlTag
GenderField = "name:=gender" & ListHtmlTag
StateField = "name:=state" & ListHtmlTag
PinCodeField = "name:=zip" & EditHtmlTag
EducationField = "name:=edu" & ListHtmlTag
OccupationField = "name:=occupation" & ListHtmlTag
AlternateEmailField = "name:=emailaddress" & EditHtmlTag
End If
***************Register User Screen End *************************
4. As Button and Link names change with languages, capture these constants in the corresponding
Example,
RegisterMeButton = "name:= Register Me," & ButtonType
ResetButton = "name:= Reset," & ResetType
5. Identify and place all module specific functions in the module-specific VBScript. Functions that can be used across the application can be placed in the generic VBScript. When the desired function is not available, define the function based on the following guidelines:
· Decide the purpose of the function
· Provide a descriptive name for the function
· Determine input parameters
· Determine return values, if required
· Implement the function.
6. Reuse the Reusable Actions for frequently performed tasks like clearing and resetting the fields, browsing records, login application, logout application etc.
7. Using the Reusable Actions and functions (common and module specific) build the specific script Register User
8. Using the Reusable actions and specific script, build the driver script “Register”.
9. Execute the driver script.
10. View results in the Test Results file generated by QTP.
Frameword Advantages and Benefits
· High degree of reuse within the application
· Additions, deletions, and updates to the functions are minimal
· Isolation of all layers –— Presentation, Language and Functions
· Object Properties can be changed without changing the script
· Flow can be changed without affecting the Object Properties
· New Languages can be added with minimal changes to the script
Test automation framework Features
· The framework is a set of automated test cases that performs regression testing.
· The test suite also gives the flexibility to run specific tests.
· The test scripts within the tests can be reused across other tests without or few modifications.
· The flow within the test scripts is controlled by the values in the datasheet.
· The use of item key pair in the Actions makes it flexible to update any new changes to the screens.
· The reusable actions can be used by setting appropriate values to the environment variables.
· The framework contains library of reusable functions, which is easy to expand and maintain.
· The framework has a hierarchical architecture making it structured and modular.
· The functions are independent of data.
· The framework also supports testing the application in different languages.
Automation Framework
Automating tests by recording actions and playing the recorded scripts contained the hard-coded value, which had to be changed if anything in the application changed. This activity of changing the script when there is a change in the application not only resulted in unreliable scripts but also high maintenance cost. Hence designing scripts independent of the application became very important. To cater to these needs this automation framework was developed.