Making changes to Settings of UFT

How we can change the “Browser navigation timeout” in UFT?
Solution1:-

In first solution we can change by following steps:-

Step1:-File->Settings->Web->BrowserNavigationTimeout

BrowserNavigationTimeout in UFT
Step2:-Select “Apply” and “OK”
Solution2:-
We can change it dynamically using coding at Runtime
Step1:- Copy the following script in any Editor(Notepad) and save with extension .vbs
‘Decalring the object variable for UFT
Dim objUft
‘Creating object of UFT
Set objUft= CreateObject(“QuickTest.Application”)
‘Launching the Apllication and making it visible
objUft.Launch
objUft.Visible = True
‘Setting the Browser Navigation Timeout value 
objUft.Test.Settings.Web.BrowserNavigationTimeout = 80000
‘Destroing the object
set objUft= Nothing
Step2:-Double click the saved file

Step3:-Check the “BrowserNavigationTimeout”

How to get the count of the Google search Result of a page using DP?


Using Descriptive programming (DP) to count number of results on Google search page?

Solution:- Here we will use “Static type of DP” (by provide the set of properties and values directly) to find the Search results count.
Dim sSearch : sSearch = "UFTHelp.com"

'Function call to fetch the Result count
fnSearch(sSearch)


'*********************Function to count search result*************************
Public Function fnSearch(sInput)
Dim objGoogle,sResult,sCount
'Open the browser with Google.com
SystemUtil.Run "iexplore.exe", "http://www.google.com"

'Creating the object of google page
Set objGoogle = Browser("title:=Google").Page("title:=Google")

'Set value for searching and click on search
If objGoogle.WebEdit("name:=q","type:=text").Exist(4) Then
objGoogle.WebEdit("name:=q","type:=text").Set sInput
End If

' clicking on search
If objGoogle.WebButton("name:=Google Search","type:=submit").Exist(2) Then
objGoogle.WebButton("name:=Google Search","type:=submit").Click
End If



'Fetching the Results count displayed
If Browser("title:=Google").Page("title:=.*Google Search").WebElement("html id:=resultStats").Exist(2) Then
sResult= Browser("title:=Google").Page("title:=.*Google Search").WebElement("html id:=resultStats").GetROProperty("innertext")
Msgbox sResult

End If


'Incase we want exact result we can split the result to fetch the exact value
sCount = split(sResult)
msgbox sCount(1)

End Function


Understanding GetRoProperty

Example of class in Vbscripting

Here is a example for defining a Class, setting the values using Property and working with methods using Object of class.

Understanding Class in Vbscripting‘********************************Code for Class********************************
‘Defining a Class
Class UFTHelp
      ‘Declaring variables inside class
      Private sTool,sVersion
           
      ‘Using Let property for Setting the values of class members
      Public property Let Tool (sUFT)
            Select case sUFT
                  Case “UFT”
                        sTool = sUFT
                  Case “QTP”
                        sTool = sUFT
                  Case Else
                        Msgbox “Please enter Correct Tool to learn”
            End Select
      End Property
     
      ‘Method declaration
      Public Sub version(sHP)
       
            Select case sHP
                  Case “11.5”
                        If sTool = “UFT” Then
                              Msgbox “I want to learn ” &sTool&” “&sHP
                        End If
                  Case “11”
                        If sTool = “QTP” Then
                              Msgbox “I want to learn ” &sTool&” “&sHP
                        End If
                       
                  Case Else
                        Msgbox “Please enter correct Version of Tool”
            End Select
      End Sub
End Class
‘Creating objects of class
Dim objHelp
Set objHelp = New UFTHelp
‘Setting the value of Local variable(Change value of TOOL and version to observe the behaviour)
objHelp.Tool= “UFT”
‘Calling the methods of class 
objHelp.version(“11.5”)
‘Destroying the object
Set objHelp = nothing

Understanding Class in VBScripting


What is a Class?

A Class is a template or a blueprint for an object. An object exists only in memory at runtime; a class is a programming construct that we can work only directly during design time. Now for using object at runtime we need to define a class at design time. Objects are thus only created at runtime based on the template provided by class.

Example:-
One’s class is defined; we can create numerous objects in memory.

Scope of Class members?
Within a Class block, members are declared as either Private or Public using the appropriate declaration statements. Anything declared as Private is visible only within the Class block. Anything declared as Public is visible within the Class block, as well as by code outside the Class block.

How to create class?
To create a class we use the Keyword “Class”, like we use Function or Sub to define functions or Subroutine.

Syntax:-
Class UFTHelp
                ‘Code for class
End Class
Class: – Keyword used to define the class
UFTHelp: – User defined name of the class

What is a property?
When an object is created from class, then we use properties to access and store data from the object.

Types of property?

1. Property Let:-It allows code outside of a class to place a value in a property variable. Thus it is same like a “Sub” Procedure in that it does not return a value.

2.Property Get:-Is the inverse of a “Property Let” , thus it allows code outside of class to read value of property variable,thus it is same like a “Function” procedure in that it returns a value.

3. Property Set: – Is same to “Property Let”, but it is exclusively used to set values for an object-based properties. Point is that it is used to set values for an object (FilesystemObject), rather than a variable with a numeric, date.

Defining a Method?
It is same as defining a Function or Sub procedure


Important:-
We cannot nest classes.
Test script can have multiple classes
Keywords cannot be used to define the name of the class
By default all members of class are Public
Property Let must accept at least one value.

Exit Statements in UFT

Let us discuss various Exit statements which are quite useful in automation testing Using UFT.These statements are part of Vbscripting(Latest version) and when implanted in the code provides better control on the flow of execution of automated Tests.
It is also used in Error handling as and when some exception occurs we can use ‘Exit’ statements.
Syntax:-
  1. Exit Do
  2. Exit For
  3. Exit Function
  4. Exit Property
  5. Exit Sub

Detail:-

1.Exit Do, it is used to Exit a Do….Loop Statement. It transfers the control to the statement following the loop statement.
Example:-
‘Code to Exit, when condition is meet
Dim iVar
iVar = 1
Do
    ‘Printing the value
    Print iVar
    ‘Incrementing the value
    iVar = iVar +1
    ‘Incase value is ‘5’ then exit do
    If iVar = 5 Then
        Print “Exit Do”
        Exit Do
    End If
Loop while iVar<10 

Exit Do in UFT
2.Exit For, It is used to Exit a For….Next Loop, again control is transferred to the statement following the Next statement
Example:-
‘Code to Exit, when condition is meet
Dim iVar
iVar = 1
For iVar = 1 To 10
    ‘Printing the value
    Print iVar
    ‘Incase value is ‘5’ then exit do
    If iVar = 5 Then
        Print “Exit For”
        Exit For
    End If

Next



3.Exit Function, as the name indicated it is used to Exit the function and execution is transferred to the statement that called the function.
Example:-
‘Code to Exit, when condition is meet
Dim iVar
iVar = 1

‘FUnction call 
fnExit iVar
‘Executing the next statement
Print “Out of the Function “

‘Function to Print the values
Function fnExit(iVar)
    For iVar = 1 To 10
        ‘Printing the value
        Print iVar
        ‘Incase value is ‘5’ then exit do
        If iVar = 5 Then
            Print “Exit Function”
            Exit Function
        End If

    Next

End Function

4.Exit Property, Immediately exits the Property procedure in which it appears. Execution continues with the statement following the statement that called the Property procedure.

Example:-
Note to understand the Example , try to replace last line as objHelp.Name = “QTP”

‘************Defining the code for Class*************
Class UFTHelp
 Private sQTP

‘Setting the Property
Public property Let Name (sUFT)
 sQTP = sUFT
               
Select case sqtp
 case“UFT”
                MSGBOX ” Exit Property used “
                ‘Exit Property used
                Exit Property
                MSGBOX “I am not executed “
 case“QTP”
                MSGBOX “No Exit property used”
                MSGBOX “I am getting executed”
end select
End Property
End Class
‘************Code for using the Class************
Dim objHelp
‘Creating the Object of Class UFTHelp
Set objHelp = New UFTHelp
‘Setting the value of variable
objHelp.Name = “UFT”


5.Exit Sub, similar to Exit Function, difference lies in the fact that it is used to Exit an Sub rather than a function.
Important:-
Exit Do:-When used within nested Do…Loop statements, Exit Do transfers control to the loop that is one nested level above the loop where it occurs.
Exit For:- When used within nested For loops, Exit For transfers control to the loop that is one nested level above the loop where it occurs.

Test Directory structure of UFT files.

Scenario: – We have created new Test with the name “blog” and let us observe the folder structure created by UFT.

Test directory structure in UFT




On creating of new GUI Test in UFT, by default two actions (Action0, Action1) is created.

Each test is created with default action0 and action1



Action1:– It contains details about our first Action and is visible in “Editor” (Keyword view of QTP) of UFT.

  • Snapshots:-It contains all the snapshots taken during recording of the AUT.It is used when recorded screens are displayed in “Active Screen” in UFT.
  •  Resource.mtr:-Binary file containing the information for the I/O Parameters of the action.
  • ObjectRepository.bdb:– This is local Repository of Action, (Berkeley Database, an oracle Product)
  • Script.mts:-Most important of, this file contains the UFT code.


Action0:– it is like storehouse having settings which are applicable to all the actions present in the Test. For instance, “Number of iterations”, “Call to Existing action”.


Lock.lck:-It comes into play, when Test is already opened and it locks the resources of test, such that when we try to access same Test in another instance of UFT , test loads in  “Read Only” mode . Thus it solves the concurrency problem, by blocking other user from modifying the already opened test. It has information such as Username, Computer Name and Date details when changes are made to Test.

Default.xls.lck:– It locks the DataTable file, preventing different users to make changes to the same Data file of Test.(It is created only when “Default.xls” file is opened)

TestName.usr (blog.usr):-It is used when working with LoadRunner(HP-Product)

Default.cfg:-This is a configuration file, used with LoadRunner

Default.xls:– Excel file, containing the complete  Datatable data.By default it will have two sheets.(Global,Action1).To play with this, open this file, add and save data to “Global” sheet and load the Test again in UFT, added data will reflect in Datatable of UFT “Global” sheet.

Parameters.mtr:-Binary file, which contains information about I/O parameters of Test

Test.tsp:-It is a binary test settings file, contains UFT test settings.

Default.usp:-Again a run logic file for LoadRunner

How to register for HP Exams?

Note:- This post is updated as of 13 Feb, 2017.


Registering for HP exams, as a first timer is quite a  cumbersome task, on the request of readers, I am giving step-step procedure for registration of HP0-M47 exam ( but this can be taken as generalized steps for any HP exam). 

This process involves two basic phases i.e. Creation of HP-Learners ID and Pearson login to schedule the exam.

Please contact us in case of any doubts or confusion regarding the exam.

Following are the steps that need to be followed for HP certification:-

Step1:– Visit the link Click me
Step2:-Select from the following options as per your eligibility:-
  • Get started – for customers
  • Get started – for partners
HPE Learner ID

Step3:- Register for the Partner Ready Portal

Partner ready portal for HP certification




Step4:- Sign up for partner ready portal.

Sign up for partner ready portal



Step5:Register your official email > verify and try to search your company


Note:- Incase you are not able to search try to create

Register company for HPE Partner portal


Step6:– Follow step by step, registration process


Step7:– This will create your HP Learners ID, it can take 2- 4 days, incase HP team has any conflicts they will contact you, by the mode specified, during the registration process.


Step8:-Click on the link Pearson VUE   and  Create profile.(It will work only if you have HP-Learners ID) 
            

Variable type in UFT


How to get Subtype of variable?

It is very easy, we need to use the function provided in vbscripting i.e. Vartype

Syntax:-

Vartype(variableName)

Vartype returns values in the form  shown below:-


Vartype return in vbscripting

Example:-
We need Vartype of a string variable,
 Var1 = “UFThelp”

Msgbox (Vartype(Var1)) ‘8 will be returned

example of vartype in uft

DataType

Datatypes in UFT

Data types in Vbscript:-

It has only one dataype called as Variant ,as the name indicates its data type changes as per  the context in which it is used.Idea is vbscript is loosely typed language, so you are using variables without declaring, the type of data that will be stored in the variable.


Scenario: – we need to add to numbers and concatenate two strings.

Solution: – we require 2 variables of integer type and 2 of string type .

We will use the same variables to serve dual purpose.

‘Declaring variables
Dim var1, var2

‘Assigning the integer values 
var1 = 1 : var2 = 2

Msgbox (“Result is addition: “&var1+var2)

‘Reassigning the values with strings
var1 = “UFT” : var2 = “Help”

msgbox (“Reuslt is concatenation: “&var1+var2)


Addition of numbers

String concatenation




Thus everything is context dependent, above variables behaved as integer, when an integer values were assigned and as string datatype on assigning string values.

In nutshell, we can just put the kind of data we want in a Variant, and the Variant behaves in a way that is most appropriate for the data it contains.


Major subtypes (categories) of variant:-

SubTypes in qtp

Important:-
  • We can make number behaving as strings by enclosing in “ ”
  • We can use conversion functions of vbscript to convert from one subtype to another.
  • We can use VarType function, to check the subtype of a variable