Sometimes, you may need to change the test settings during runtime. For example, you need to set the maximum time that UFT allows when loading a Web page or retrieve the same to make use of it further in your automation. It’s the setting option Browser navigation timeout under Web tab.
Another example could be, when you need to change synchronization timeout setting for a specifc scenarion at runtime and want to revert it back for other scenarios or you need to change other run setting options as you see in the snapshot below. These could be related to datatable, resources, iteration etc.
In UFT, we have the Setting object to control how UFT runs tests by setting and retrieving testing options during a run session. This is an Utility Object which enables you to modify test settings during the test run. The test settings can be understand as global variable with dictionary of keys and their values, where the values can be set or retrieved.
Setting(“Key Name”) = Value ‘ set value Value = Setting (“Key Name”) ‘retrieve value
Setting Object Properties
Item: can be used to set or retrieve the value of given setting.
For example,to retrieve Iteration mode from run setting
Below are some of the available KeyNames
DefaultTimeout : Use this key to change/retrieve the maximum time to wait if the object is not found. The time should be in miliseconds.
Setting("DefaultTimeOut")= "20000" CurrentTimeSet = Setting("DefaultTimeOut")
WebTimeout : Maximum time in milliseconds to wait before it is determined that a URL address cannot be found.
Setting("WebTimeout ")= "20000" CurrentTimeSet = Setting("WebTimeout ")
AutomaticinkRun : This Key determines whether automatically created checkpoints will be executed during the test run or not. Its Value can be either True or False.
True: Automatic checkpoints are executed.
False: Automatic checkpoints are not executed.
DefaultLoadTime: : Use this key to change/retrieve the amount of time it should wait for a page to load during the run session. The time should be in seconds.
Setting("DefaultLoadTime ")= "20000" CurrentTimeSet = Setting("DefaultLoadTime ")
SnapshotReportMode : Indicates when the images are captured. The value can be one of the following:
0 – always captures images.
1 – captures images only if an error occurs on the page.
2 – captures images if an error or warning occurs on the page.
3 – never captures images.
Default = 1.
Tools> Options > Gui Testing > Screen Capture
You can get the full list of available KeyNames that you can use to change or retrieve the settings and options. Just Click on Generate Script button at Settings dialog (Test > Setting) and Options Dialog (Tools > Options) as shown in the snapshots below. Once you save the scripts, just open it (no need to run, open it in any file editor). You will find the list of KeyNames and their usage in each statement.
WebPackage: Webpackage poperty enables you to set or retieve values relevant for the web add-in.
Some of the possible keys or setting options that can be used are as below
ReplayType : this setting option is to change the way mouse operations should happen on AUT. It can be either browser events or mouse event. Browser event is similar to DOM events using the Browser methods, wheras Mouse event simulate the actual user action either from keyboard or mouse. For example if you click on a button when ReplayType is Mouse, you will notice that mouse pointer moves to the location of button and fires the event, but n case of browser event it doesn’t.
Values of replaytype can be
1 – Event
2 – Mouse
By default it is set to Event i.e 1
Setting.WebPackage("ReplayType") = 2
RunUsingSourceIndex : Indicates whether the source index property should be used. The value can be one of the following:
0 – Does not use the source index property to identify objects.
1 – Uses the source index property to identify objects
Setting.Packages.WebPackage.Settings("ReplayUsingSourceIndex") = 0
Setting Object Methods
Using this method, you can add a user-defined settings and use it further in your scripting.
For example, In some cases you need to turn off a particular recovery option and again you want that to be enabled. In this situation you can have setting created and use it as required.
Settings.Add “RecoveryEnabled”, “Yes” bEnabled = Settings.Item(“RecoveryEnabled”) Settings (“RecoveryEnabled”) = “No”
Before creating a new user defined settings, it is always a good practice to check it has aready been created earlier or exists already.
If Settings(“RecoveryEnabled”) =”Yes” then Settings(“RecoveryEnabled”) = “No” Else Settings.Add “RecoveryEnabled”, “Yes” bEnabled = Settings.Item(“RecoveryEnabled”) End if
Once you are done with the test or there is no scope for the user defined settings in the current test, You should always Kill it by using the Remove method.
Hope this was helpful, Please provide your feedback/quiestions via the comments below.