Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to remember Shortcut Keys in UFT/QTP

In this article, we will discuss on different shortcut keys in QTP/UFT. It is very difficult to understand each of the shortcut Keys and even does not make much change. But can remember the important one highlighted in bold green.

    File Menu


Creating Something New – When we create a new test or business component , it can be created with shortcut key combination with Key N.


New Test - Ctrl + N (For a test, we use Ctrl + N (for new))
New Business Component : Ctrl + Shift + N ((For a Business Component, we use Ctrl +Shift+ N (for new))
Function Library : Alt + Shift + N ((For a Function library, we use Alt +Shift+ N (for new))

Application area : Ctrl + Alt + N ((For an application area, we use ctrl + Alt + N (for new))

Opening something existing – So Open starts with O (So shortcut key combination will have one of the key as O and rest characters same as with new for test, business component, function library and application area.


Open Test : Ctrl + O
Open Business Component : Ctrl + Shift + O
Open Function Library : Alt + Shift + O

Open Application area : Ctrl + Alt + O

Adding new or existing– The shortcut key combination is created as ctrl+Shift + first letter of the component added.In case of existing, use Ctrl+ Alt instead of ctrl + Shift

Add new Test : Ctrl + Shift + T
Add new Business Component : Ctrl + Shift + B
Add new Application area : Ctrl + Shift + A
Add Existing Test : Ctrl + Alt + T
Add Existing Business Component : Ctrl + Alt + B
Add Existing Application area : Ctrl + Alt + A
Close: Ctrl + F4
Close Solution : Ctrl + Shift + F4
Save Current  : Ctrl + S
Save All : Ctrl + Shift + S

Edit Menu


Most of Edit option are same as other application, i.e copy using ctrl+c and paste using ctrl + v.

 Different ones are:
Comment : Ctrl + M
Uncomment : Ctrl + Shift + M
Indent : Tab
Outdent : Shift + tab
Complete word : Ctrl + Space
Argument Info : Ctrl + Shift + Space
Apply “With” to the script : Ctrl + W
Remove “With” : Ctrl + Shift + W

View Menu


One thing in common is all contain Ctrl+Alt

Solution Explorer: Ctrl + Alt + L
Toolbox : Ctrl + Alt + X
Properties : Ctrl + Alt + P
Data : Ctrl + Alt + D
Output : Ctrl + Alt + U
Errors : Ctrl + Alt + E
Tasks : Ctrl + Alt + K

Design Menu


Standard Checkpoint – F12
Existing Checkpoint – Alt + F12
Step Generator : F7
Check Syntax : Ctrl + F7

Record Menu


Record : F6
Stop Run/Recording : F4

Analog Recording : Ctrl + F3
Low Level Recording : Shift + F3

Run Menu


Run : F5
Run now : Shift + F5
Stop : F4
Run from step : Ctrl + F5
Step Into : F11
Step Over : F10
Step Out : Shift + F10
Insert Breakpoint : F9
Remove Breakpoint : Ctrl + F9

Clear All Breakpoints : Shift + Ctrl + F9

Object Repository Menu


Open Object Repository : Ctrl + R

ALM Connection Menu


ALM Connection : Ctrl + Q

Help: F1


How to Export/Import tests in QTP

Test in QTP can be exported to a zipped file with all the objects. In a similar manner, test from previously exported file can be imported to a QTP test.


Export Test – A test can be exported to a zipped file following below steps

export test in QTP

  •  In QTP/UFT, Navigate to File>Export Test
  • Provide the path of the location where exported zip file will be saved.
  • The test is exported to a zip file saved at the location provided.

 

Import Test – Similarly we can import the test in zip file to a QTP test or solution following below steps

import test in QTP

  • In QTP/UFT, Navigate to File>Import Test.
  • Provide the path of the location from where zip file will be imported.
  •  Provide the path of qtp test where the zip file will be converted to a test.

How to compare arrays after sort data in Array using VBScript in QTP

In this article, we will discuss how to work with arrays explaining the below concepts:
  • How to sort data in the array.
  • How to compare two arrays.
  • How to view elements in an array


'''''''''''''''''''''''''''''''''''''''''''''''''Test Data for the example''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
arrayDataA = Array(43,54,65,76,87)
arrayDataB = Array(87,65,54,43,7)


'''''''''''''''''''''''''''''''''''''''''''''''''Calling the functions for arrays''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
call funcArrayComparision(arrayDataA, arrayDataB)
arrayData = sortArray(arrayDataA)
ViewsortArray(arrayDataA)

'''''''''''''''''''''''''''''''''''''''''''''''''Function to sort data in an array'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

public function sortArray(arrayData)
For i = LBound(arrayData) to UBound(arrayData)
  For j = LBound(arrayData) to UBound(arrayData)
    If j <> UBound(arrayData) Then
      If arrayData(j) > arrayData(j + 1) Then
         TempValue = arrayData(j + 1)
         arrayData(j + 1) = arrayData(j)
         arrayData(j) = TempValue
      End If
    End If
  Next
Next
sortArray = arrayData
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''Function to view data in an array'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

public function ViewsortArray(arrayData)
For i = LBound(arrayData) to UBound(arrayData)
 msgbox arrayData(i)
Next
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''Function to compare two arrays'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function funcArrayComparision(arrayA, arrayB)
''Firstly we will check whether the size of array matches, In case, It does not match, we can conclude values do not match 
   If ubound(arrayA) <> ubound(arrayB) Then
msgbox ("The array size is not same, so it is not possible array will match")
   else
   ''Now first of all we need to sort the array content, since we are compring array value by value, we are sorting the data without taking as/desc order in focus
  arrayA = sortArray(arrayA)
  msgbox ("Sorted data in the ArrayA")
  arrayB = sortArray(arrayB)
msgbox ("Sorted data in the ArrayB")
  boolflag = 0
For i = 0 to ubound(arrayA)-1
If arrayA(i) = arrayB(i) Then
msgbox arrayb(i)
boolflag = 1
Exit For
End If
Next
If (boolflag > 0) Then
msgbox ("congratulation ! array content in both the files match")
else
msgbox ("array content in both the files does not match")
End If
End If
End Function

What is the difference between ByRef and ByVal? –QTP Interview question

ByRef and ByVal are two ways to pass arguments to a function or subroutine in VBScript. Understanding the difference between two is simple.

Let us start with ByVal. Suppose a function or subroutine has an argument which accepts a variable with byval,suppose a variable x is passed as argument to the function, The value of variable does not change once the function is executed successfully.

Now let us move to ByRef. ByRef means passing value as a reference. Suppose a function or subroutine has an argument which accepts a variable with byref, suppose variable x is passed as argument to the function, The value of variable changes once the function is executed successfully.

Writing the below function in a notepad and running as a vbscript will help to differentiate ByVal and ByRef


By Ref Code:


Dim x
x= 5
call squareofNumber(x)
msgbox x
Function squareofNumber(ByRef varx)
        varx = varx*varx
        msgbox varx
End function


ByVal Code:


Dim x
x= 5
call squareofNumber(x)
msgbox x
Function squareofNumber(Byval varx)
        varx = varx*varx
        msgbox varx
End function
 By default, if we do not provide ByVal or Byref, it takes the argument as ByRef.


Tips to be followed for a successful test Automation

We associate a lot of Return on Investment with software automation. There is high expectation from test automation that it will reduce the long regression cycles. But more often than not, we see a lot of maintenance cost associated with the test automation.


In this article, we will discuss why does automation fails and what needs to be done to ensure test automation pass. I have collected the information from feedback received from multiple test automation developers and personal experience.


  • Wait and Study application First –In daily life, we learn is to understand the problem and then react. Similarly, we should never rush into software automation. First step before starting automation is to say hello to the application or system of applications which needs to be automated. Ask questions on the technologies in which the application is developed. E.g.: Is it a web application. Are different technologies used in the application, or there any web services used in the application and so on.
  • Understand the expectation from the client on the scope for the automation.
  • Choose the best tool for automation – Based on the technology used in the application, objects in the application, Choose the best tool for automation. E.g.: Tool A is an open source tool supporting Web application only. Tool B supports both Web Application and web Services both and Tool C supports only Web Services. We have to understand the limitations and benefits of different tools and choose the best suited tool for automation.
  • Do a small Proof of concept on the application to understand whether automation is feasible and we are able to cover the complex scenario in the application with focus mainly on interaction with application, e.g.: Object Identification, Interaction with external cards and systems. Another focus area should be which framework approach will be best suited for the automation, whether to go for Keyword, hybrid, data driven or BDD framework.
  •  Get an initial closure on the scope of the automation with the client in the project and the possible estimate to complete the automation, and the expected maintenance cost for the automation.

Right, we have reached a stage, where we as well client feel automation is possible. Now comes the real part, creating the framework for the Project.


Framework is like the initial building blocks. If it is strong, the building will be strong and will sustain for a longer period of time. Below are the key features of a robust framework structure:


  •  Key Component of an automation framework should be :

    • Error handling

    • Test Reporting – Test Reporting should be clean and easy for a tester to interpret which all tests fail or Pass.

    • Different classes/libraries for different types of methods or functions. E.g. suppose we are creating a project in Selenium. We can create different classes for reporting, common functions, database interaction, and different classes for selenium scripts where WebDriver interacts with application.

    • Creating different libraries helps in better maintenance of automation as we need to change the specific library code. Also suppose we move from Selenium to any other tool in future, the framework will be intact and change required in few classes only.

    • Test data Management for test data, global constant and environment variables

    • Maintaining constants and description properties in property file or separate location. In case property of object changes, we will make changes in the file without going in the scripts.

  • One of the reason for automation failing is the automation suite grows too bulky; Try to divide the test suite into logical units with flexibility to end users to easily select the subset of test suites to be executed.
  • With increasing popularity of agile, the code should be continuously integrated and run with CI.
  • Maintain Version control of automation code to ensure we maintain history of automation code and test artifacts.
  • Reviews and dry run for both positive and negative scenario should be done in the dev phase.
  • Never try to automate the application 100%. Automating one time tests scenario cause load of the automation code growing it larger and making it difficult to maintain.
  • Comments as much as possible in the code. Understanding code of another person or own code, if revisited after long time is very difficult, it becomes more difficult if there are no or very less comments in the code

The list can be huge, but again as we discuss, as we should not try to cover 100% of scenarios in automation. On similar line, creating a post with very large information will fail the purpose of the post. Hope you like the post. Many thanks




VBScript Code - Function to convert CSV file into excel and viceversa in QTP using VBScript

We at times are required to convert excel files into csv to read as flat files and sometime require to convert a csv file into excel file to use excel features on the data.

 
Below function shows how to convert an csv file into excel file and vice versa. We can also convert to other formats based on constants

Here constant value 23 is used to create a csv file and constant -4143 to save a file as xls file.Once the destination file is created, we can delete the source file as shown below. In case of any issue in understanding the code, please add in comment section


 Call func_ConversionCSVExcel("E:\Test.csv", "E:\Test_converted.xls", "csvtoexcel")  
 Public Function func_ConversionCSVExcel(strSrcFile, strDestFile, Conversion)  
 on error resume next  
 Set objExcel = CreateObject("Excel.application")  
 set objExcelBook = objExcel.Workbooks.Open(strSrcFile)  
 objExcel.application.visible=false  
 objExcel.application.displayalerts=false  
 If(Conversion = "ExceltoCSV") Then  
   objExcelBook.SaveAs strDestFile, 23  
 else  
   objExcel.ActiveWorkbook.SaveAs strDestFile,-4143  
 End If  
 objExcel.Application.Quit  
 objExcel.Quit    
 Set objExcel = Nothing  
 set objExcelBook = Nothing  
 Set objFSO = CreateObject("scripting.FileSystemObject")  
 objFSO.DeleteFile(strSrcFile)  
 Set objFSO =nothing  
 End Function  

How to load multiple function libraries at runtime from Quality Center in QTP

This post explains how to load multiple libraries at runtime from Quality Center in a QTP test. As the test size grows, it is better to associate or load function library at runtime with all the tests. 

Note we should associate an initialization library with each of the test and then perform following work in the initialization library. 


  • Load all the function library with the test
  • Load the shared object Repository with the test.
  • Remove the local object repository with the test to avoid object conflict
  • Load the environment variables to be used across test
  • Close all instances of application.
  • Providing the reporter configuration for the test. e.g: allowing reporting in QTP Reporter on scenario of error only


In the current post, we will focus only on how to load multiple libraries at runtime from Quality Center or local folder.


In the case of using local folder structure , the path [QualityCenter] Subject\Project_Name \......   changes to c:\QTP_Automation/......

 Const strLibraryNames = "[QualityCenter] Subject\Project_Name\QTP\Libraries\Library1.vbs>[QualityCenter] Subject\Project_Name\QTP\Libraries\Library2.vbs>[QualityCenter] Subject\Project_Name\QTP\Libraries\Library3.vbs>[QualityCenter] Subject\Project_Name\QTP\Libraries\Library4.vbs"  
 callfunc_LoadFunctionLibrary(strLibraryNames)  
 Function func_LoadFunctionLibrary(strLibraryName)  
  ''Load multiple Library Files seperated by '>'  
  collLibrary = split(strLibraryName, ">")  
    ''Now collLibrary is an array with each element in array storing the path of library  
  For i = 0 to ubound(collLibrary)  
  LoadFunctionLibrary collLibrary(i)  
  Next   
 End Function  

How to create and work with Class using VBScript Code in QTP

Using Class in VBScript, we are able to create an instance of object and use properties and methods of the object. 


Points to remember with VBScript Class concept:

  • We can define variables, methods, properties, and event members in the class.
  • All the members of a class can be declared as Private or Public.
  • Members declared as Private are visible within the Class block. 
  • Members declared as Public are accessible from within and outside the class.
  • Members are by default Public. If we don't provide member as Private or Public


Syntax of Class Statement in VBScript


Class ClassName

       Statement of Code

End Class


Understanding Implementation of class in VBScript with an example


'' Here we have defined a class with name as VBSriptClass

Class VBScriptClass

''Once we have created a class, next we need to define the members of the VBScript.

''We have taken all the types of members in this example

'' A variable can be defined as Private or Public 


Private var_ClassName 
Public var_Name

''Class Events - Class_Initialize and Class_Terminate are events which we can define in a class

''We can define the action which we need to perform when we instantiate a class in the class_initialize sub as shown below.

Private sub Class_Initialize(  )
msgbox "We have initialised the test. This pop up will appear the moment new instance of class object is created"
End Sub

''When Object is Set to Nothing/destroyed, Class_Terminate event is executed and actions are performed as defined in the sub. 

Private Sub Class_Terminate(  )
msgbox "We have terminated the test. This pop up will appear the moment instance of class object is destroyed/set as nothing"
End Sub

'' Property Let and Get allows to set and extract values from properties in the class

''get method allows to extract value set for property in the class

Public Property Get ClassName
       ClassName = var_ClassName
End Property 

''Let method allows to set value for the Property

Public Property Let ClassName (strClassName) 
         var_ClassName = strClassName 
End Property 

''We can define function in the class. the below example will sum two numbers

''Only Public functions can be used in code outside of the class 

public function sum(a,b)
        sum = a+b
        addition a,b
End Function

''Private method cannot be called outside the class but can be called by another function within the class

Private function addition(a,b)
       msgbox a*b
End function

''A sub/function which is not defined as either Private/Public can be assesed outside the class and works as public method

Sub DisplayUserName 
      msgbox UserName 
End Sub 
End Class 


Using Class members outside the class code


''We can define an instance or object of class as set in below code

Set objClass = New VBScriptClass

''Once the instance of the clas is created, we can used the public members of the class as shown below.

'' Set value of the property of the method.

objClass.ClassName  = "Are we talking about Dance Classes?"
msgbox objClass.sum(12,15)
msgbox objClass.ClassName

'' Close the instance of the class object

Set objClass = nothing


How to use err object to continue test execution in VBSript and QTP


''Err object holds the information for last runtime error that occurred in the test execution


'' In the piece of code, we can add on error resume next to continue with execution . It will not abort the execution but will store the information of the error.


'' Once a new runtime error occur, in that case , the err object stores the information of new error. So handle must be taken to add reporting in test and clearing the error


''Methods for err object are err.raise and err.clear


'' On error Resume next will continue with execution. try to comment the On error resume next , and then see what happens in case on error resume next statement is not provided.


On Error Resume Next 

'' Err.raise <number> will generate err object for err number provided. At runtime as an error is encountered, err object populates the information of error. 

Err.Raise 9err_number= Err.number 

'' Using err.description, we can extract information about the error

err_description= Err.description 

'' In case no error is encountered in the execution , the err. number has number as 0. Therefore we can use If else loop based on value of err.num and report to the QTP Report.

If numerr <> 0 Then 

 ''Reporter.Reportevent ........

msgbox (numerr & " Some error in application")

Else

''Reporter.reportevent ........

End If



'' Once we have validated a piece of code, we should clear the err using err.clear

err.clear

msgbox err.number



''you will see msgbox will display value as 0 now. 



How to create array from string separated by delimiter using vbscript split function


Suppose we have a string with value as : stringA = "nitin>joshi>qa>qtp>automation"

'' We can create an array using split function


Strarray = Split(StringA, ">")
'' we can loop through the array element using:

 intPropSet = Ubound(Strarray)  ''this gives the length or upper bound index of array.

  for i = 0 to intPropSet

      msgbox strarray(i)

  Next


''This can be useful to loop in validating multiple values ''e.g : Validating existence of multiple links with name as nitin or joshi or qtp or automation


''We can combine the values in an array using join statement


If (IsArray(Strarray)) then

   stringB = Join(Strarray, ">")

   msgbox "array with text: " + stringB

Else

   msgbox "not an array"

End If


So while understanding How to create array from string separated by delimiter using vbscript split function, we have now understanding of Join, split, IsArray,Ubound and lbound also