Thursday, 12 November 2015

QTP KeyWord Frame work driver script



'===============================================================
' QTP KeyWord Frame work driver script
'===============================================================
'Project Name :-Esources
'Script Name  :-Key Word Frame Work Driver Script
'Author       :-Sumit Raut
'Created Date :-12 Nov 2015
'--------------------------------------------------------------
'Declearing the variables
Option explicit
Dim fname,intmrc,i,mexe,mmid,inttcrc,j,tcmid,tcexe,tctcid,k,inttsrc,tstcid,kwd,strres,resfilnam
'intmrc=rowcount of modules sheet
'mexe=refers to execution flag of modules sheet
'mmid=module id


'Association of environment file,repository and function library
'Environment.LoadFromFile "E:\nareshuft63\automation\environmnet\pbank.xml"
'RepositoriesCollection.Add Environment.Value("rep")&"pbank.tsr"

RepositoriesCollection.Add "C:\Users\Sunshine\Desktop\UFT Again\OR\estotoal.tsr"
'ExecuteFile Environment.Value "C:\Users\Sunshine\Desktop\UFT Again"

ExecuteFile "C:\Users\Sunshine\Desktop\UFT Again\esources.qfl"

'Adding the new sheets to datatable
DataTable.AddSheet("dtmodules")
DataTable.AddSheet ("dttestcases")
DataTable.AddSheet ("dtteststeps")

'Deleting the default sheets of datatable
DataTable.DeleteSheet ("Global")
DataTable.DeleteSheet("Action1")

'Importing the excel sheets data into datatable sheets
fname="C:\Users\Sunshine\Desktop\UFT Again\keyword.xls"
'C:\Users\Sunshine\Desktop\UFT Again\keyword.xls
DataTable.ImportSheet fname,"modules","dtmodules"
DataTable.ImportSheet fname,"testcases","dttestcases"
DataTable.ImportSheet fname,"teststeps","dtteststeps"

'Working with dtmodules sheet of datatable
intmrc=DataTable.GetSheet("dtmodules").GetRowCount
MsgBox "m rowcount="&intmrc
For i = 1 To intmrc Step 1
DataTable.GetSheet("dtmodules").SetCurrentRow (i)
    mexe=DataTable.Value("execution","dtmodules")
    If ucase(trim(cstr(mexe)))="Y" Then
    mmid=DataTable.Value("moduleid","dtmodules")
    MsgBox "module id="&mmid
  
'Working with dttestcases sheet of datatable
    inttcrc=DataTable.GetSheet("dttestcases").GetRowCount
    MsgBox "tc rowcount="&inttcrc
    For j = 1 To inttcrc Step 1
        DataTable.GetSheet("dttestcases").SetCurrentRow (j)
        tcmid=DataTable.Value("moduleid","dttestcases")
        tcexe=DataTable.Value("execution","dttestcases")
        If (trim(cstr(tcmid)))=(trim(cstr(mmid))) and (ucase(trim(cstr(tcexe))))="Y" Then
        tctcid=DataTable.Value("testcaseid","dttestcases")
        MsgBox "tc tcid="&tctcid
          
'Working with dtteststeps sheet of datatable
inttsrc=DataTable.GetSheet("dtteststeps").GetRowCount
MsgBox "ts rowcount="&inttsrc
For k = 1 To inttsrc Step 1
    DataTable.GetSheet("dtteststeps").SetCurrentRow(k)
    tstcid=DataTable.Value("testcaseid","dtteststeps")
    If trim(cstr(tstcid))=trim(cstr(tctcid)) Then
        kwd=DataTable.Value("keyword","dtteststeps")
        MsgBox "Keyword="&kwd
      
'Introducing the select case conditional statement
Select Case kwd
    Case "apl"
    'strres=fnAppLaunch(strurl)
    strres=fnAppLaunch("http://www.esources.co.uk/")
  
    Case "algn"
    'strres=fnAppLogin(strun,strpwd)
    strres=fnAppLogin("estesting2015","testing")  
  
  
    Case "algt"
    strres=fnAppLogout()
  
    Case "apc"
    strres=fnAppClose()
End Select

'Updating the results into the teststeps and testcase sheets of datatable
DataTable.Value("status","dtteststeps")=strres
If DataTable.Value("status","dttestcases")<>"fail" Then
   DataTable.Value("status","dttestcases")=strres
   else
   DataTable.Value("status","dttestcases")="fail"
End If
    End If
Next
else
DataTable.Value("status","dttestcases")="blocked"
        End If
    Next
      
    End If
Next

'Exporting the results of datatable into excel file 
resfilnam=replace(replace(replace(now,"/",""),":","")," ","")
'DataTable.Export Environment.Value("res"filnam&")&reskwdfw.xls"
DataTable.Export "C:\Users\Sunshine\Desktop\UFT Again\keywordresult.xls"




Wednesday, 24 July 2013

QTP- When to associate a library file with a test and when to use execute file?

When to associate a library file with a test and when to use execute file? 

 

  • When we associate a library file with the test, then all the functions within that library are available to all the actions present in the test.
  • When we use Executefile function to load a library file, then the function are available in the action that called executefile. 
  • By associated a library to a test we share variables across action (global variables basically), using association also makes it possible to execute code as soon as the script runs because while loading the script on startup QTP executes all the code on the global scope.
  • We can use executefile in a library file associated with the test to load dynamic files and they will be available to all the actions in the test.

QTP AOM Script : Launch QTP, Create new test and Save it


QTP AOM Script : Launch QTP,  Create new test and Save it
===============================================
dim qtpapp

set qtpapp=createobject("quicktest.application")

qtpapp.launch

qtpapp.visible=true

qtpapp.new

qtpapp.test.saveas "C:\qtpapp"

qtpapp.visible=true

qtppapp.quit

set qtpapp=nothing


Saturday, 22 June 2013

QTP :-Useful Datatable Methods

Data table methods are used for performing the operations on the runtime data table

1. Add- sheet: It is used for adding the new sheet for the runtime data table

Syntax: Datatable.Addsheet("SheetName")

Ex. Datatable.Addsheet("Sumit")




2. Delete- sheet: It is used for deleting a specified sheet from the run time data table

Syntax:
Datatable.Deletesheet("SheetName")
Datatable.Deletesheet(SheetID)


Ex. Datatable.DeleteSheet("Sumit")
Ex. Datatable.DeleteSheet(3)


3. Import: It is used for importing the data present in all the sheets in an excel file to the runtime data table
Syntax:
DataTable.Import("pathoffile")


ex datatable.Import("c:\esbbxl.xls") 



'4. Import Sheet: It is used for importing specified sheet of data from the excel file to the specified sheet in the runtime data table
'Syntax:
'Datatable.Importsheet “path of the excel file, source sheet id, destination sheet id”


datatable.ImportSheet "c:\esbbxl.xls",2,3 


//Imports 2nd sheet from esbbxl file  into 3rd sheet of datatable, i.e action 2 in our case.
1. Global
2.Action 1
3. Action 2 







 



 




QTP: Some useful Typecasting functions QA Enginners use in real time

QTP: Some useful Typecasting functions  QA Enginners use in real time

1. CINT
 This functions coverts string into integer.
Ex.

dim avalue="7"
dim bvalue="10"

if avalue >bvalue then

print avalue is greater

end if

Output:





Corret Code:





















dim avalue,bvalue


avalue="7"
bvalue="10"

if (cint(avalue) >cint(bvalue)) then

msgbox  "avalue is greater"

end if

Output: does not print anything as 7 is not greate than 10



CBool
To return a Boolean value of an expression for true/false condition

QTP- Registeruserfunc method : How to regsiter public function to test object

Register User Function is used to append a new method (Function/ Procedure) or to take priority over of a presented method for a certain QTP Class during run session. Register User Function is relevant for Test Objects similar to VbEdit, VbList, WebEdit, WebList, Dialog, Window and Browser etc…

To Register a Function, foremost define a Function and mark Register User Function declaration at the end of Function Library or in test script. You can Register a New Method for a Test Object Class or Use an Existing Method Name to take priority over the existing Functionality of the specified Method.

If the Function is defined and it is not registered, it operate as a Global Function, you can monitor all your defined functions in Step Generator (F7) if they are globalized. Once the Function is registered, you can’t see the registered function in Step Generator.

The Register Method applicable only in test Script or in Function Library. QTP clears all Registrations at the beginning of Every Run Session.

Syntax: RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault

Arguments:
ToClass: To which Class you want to register the method.
Method Name: String which you like to see in methods List for that class.
Function Name: The name of the user defined function which you have defined.

Note: The Function should be located in your Action or in a Library file which you have associated to your Test Script.
SetAsDefault: Indicating that the registered function should be used as a default method for test object/not

Examples:
1. The following Example describes how to append a new method to QTP Class

Sub AddNewMethod (Object, ParameterValue)
If Object.Exist Then
Reporter.ReportEvent micPass, "Object Exist", "XXXXXXXXX Object is existed on this Page"
Else
Reporter.ReportEvent micFail, "Object Exist", "XXXXXXXXX Object is existed on this Page"
End If
End Sub

Declaration: RegisterUserFunc "WebEdit", "AddNewMethod","AddNewMethod",True

After finishing the delcaration of Function and its Registration save file as “FileName.vbs” and associate to the test script. You will find the registered new method in list of methods which supports WebEdit Class and displays as

Browser("QTP Descriptive Programs").Page("QTP Descriptive Programs").WebEdit("email").AddNewMethod

2. The Following Example describes how to add new function to an existing QTP Class/ method.

Function MySet (Object, x) [Ex: obj = Browser("MercuryTours").Page("FindFlights").WebEdit("Country")]
Dim y
Y = Object.GetROProperty("value")
Reporter.ReportEvent micDone, "previous value", y
MySet=Object.Set(x)
End Function

RegisterUserFunc "WebEdit", "Set", "MySet"

The behavior of the above function is to capture and report the value of an edit box before the new value is entered. We are registering the above function with existing set method of Test Object WebEdit i.e., modifying the Set Method behavior with newly distinct function.

Note: Once a new method is registered, the method becomes a recognized method to that specific Test Object until you unregister that method. If your method overrides an existing QTP method unregistering that method resets the method to its normal behavior. Unregistering new methods deletes that method from list of methods which supports by the Test Object. To Un-Register a Function make use of the following Syntax.

Syntax: UnRegisterUserFunc TOClass, MethodName
Arguments:
ToClass: To which Class you want to register the method.
Method Name: String which you like to see in methods List for that class.

Example: UnRegisterUserFunc "WebEdit", "Set"

Thursday, 13 June 2013

SystemUtil Object Usage in QTP

SystemUtil Object Usage in QTP


SystemUtil Object:
SystemUtil Object used to control applications and processes during a run session

Methods:

Run: Used to Runs a file or application.
e.g: Systemutil.Run "www.google.co.in","","",""

CloseProcessByName: Closes a process according to its name.
e.g: Systemutil.CloseProcessByName("Excel.exe")

BlockInput: Used to Prevents keyboard and mouse input events from reaching applications.
e.g: Systemutil.BlockInput

UnblockInput: Used to Re-enables keyboard and mouse input events after a BlockInput statement was used to block them.
e.g: Systemutil.UnblockInput

CloseDescendentProcesses: Used to Closes all processes opened by QuickTest.

CloseProcessByHwnd: Used to Closes a process that is the owner of a window with the specified handle.

CloseProcessById: Used to Closes a process according to its Process ID.

CloseProcessByWndTitle: Used to Closes all processes that are owners of windows with the specified title. 

Rest Assured Chectsheet

REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...