Pages

Men

rh

7/16/2012

Interview Questions on QTP Part-3

How to verify the Cursor focus of a certain field?
 Use "focus" property of "GetRoProperty" method.

Any limitation to XML Checkpoints?
Mercury has determined that 1.4MB is the maximum size of a XML file that QTP 6.5 can handle.

How to make arguments optional in a function?
This is not possible as default VBS doesn't support this. Instead you can pass a blank scring and have a default value if arguments r not required.

How to covert a String to an integer?
CInt()---> a conversion function available.

Inserting a Call to Action is not Importing all columns in Datatable of globalsheet. Why?
Inserting a call to action will only Import the columns of the Action called

Can I change the Active Screen page which is shown on every new test?
This page can be changed to be any valid HTML page. The page can be located either locally or on the network.

For example, if you want your entire organization to view the same Active Screen page when they open QTP, you should open the NewTest.inf file located under the dat\snapshots directory of QTP and set the next line:

FileName1=<any full path to an HTML file>
FileName1=\\mercury\public\MainPage.html

How to create an action template?
You can create a template action script that will be used on every new action that is created. You can use this, for example, to add a header comments to each action.

To create the template action you should create a text file with the name ActionTemplate.mst and place it under QTP dat folder.

How to pass parameters when calling actions?

Using the new Action Parameters feature in Quick Test 8.0
Putting the variable in the data table and then accessing this data table from the called action.
Defining the variable as an environment variable that can be accessed from the entire test.

How to configure the report to show only error (by default)?
Ans:You can configure the report to show only error by default by adding the following section to the QTReport.ini file (located under QTP bin directory).

[FilterDialog]
ReportAppDefaultFilter=1 # for error only
ReportAppDefaultFilter=3 # shows all messages (default)

How to use Environment variable?
QuickTest supports using environment variables. Environment variables can be either system variables or user defined variables.

You can define the user defined variables in an external file which will be read by QuickTest when it will be launched.

See the Using Environment Variables section in the QuickTest Professional help.

Does QuickTest have any debugging capabilities?
In order to debug tests you must install the Microsoft Script Debugger. If you did not download and installed it while installing QuickTest, the debugger can be still downloaded from the Microsoft Script Technologies site. After downloading it, double-click on the self-extracting executable and follow the instructions on your screen.

Once the Script Debugger is installed, an arrow points to the current step that is being executed in the Tree View and the Expert View. You can then use the debugger to view local action variables, use the command window, view the objects properties, and more.
More information can be found in the QuickTest User's Guide.

What command-line arguments can I use when launching QuickTest?
Please refer to the QuickTest Command Line utility for more information on how to run QuickTest using a command line.

I have a Microsoft Access database that contains data I would like to use in my test. How do I do this?
The powerful 'Expert View' allows you to access databases using ADO and ODBC. Below is a sample test that uses the information contained in the Authors table of a database to search for books written by the author.

Dim MyDB
Dim MyEng
Set MyEng = CreateObject("DAO.DBEngine.35")
Dim Td
Dim rs

' Specify the database to use

Set MyDB = MyEng.OpenDatabase("BIBLIO.MDB")

' Read and use the name of the first 10 authors

Set Td = MyDB.TableDefs("Authors")
Set rs = Td.OpenRecordset
rs.MoveFirst
For i = 1 To 10
     Browser("Book Club").Page("Search Books").WebEdit("Author Name").Set rs("Author")
     Browser("Book Club").Page("Search Books").WebButton("Search").Click
Next

How do I add a manual wait step to my test?
Ans: A manual wait (think time) can be added to a QuickTest test using the following command:
Call Wait(<time in seconds to wait>)

How do I make the test prompt the user for input while it is running?
The VBScript InputBox function allows you to display a dialog box that prompts the user for input and then continue running the test. You can use the value that was entered by the user later on in the test. See the VBScript reference manual for more information on the InputBox function.

The following example shows the InputBox function used to prompt the user for the password.
Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username").Set "administrator"
Passwd = inputbox ("Enter password", "User Input")
Browser("Mercury Tours").Page("Mercury Tours").WebEdit("password").Set Passwd

How to remove result files from old tests?
You can use the Test Results Deletion Tool to view a list of all the test results in a specific location in your file system or in a Quality Center project. You can then delete any test results that you no longer require.
The Test Results Deletion Tool enables you to sort the test results by name, date, size, and more, so that you can easily identify the results you want to delete.
You can find this utility in the Start Menu > QuickTest Professional > Tools > Test Results Deletion Tool.

How to change the logical name of a Test Object?
When recording an object QuickTest Professional uses one of the object's properties as the logical name for the object (the name displayed in the Expert View and in the KeywardView modes).
You can change the property that is used to be a different one by specifying which property's value you want to use as the logical name for the object.
For example in order to use the alt property as the logical name of an image, run regedit.exe and set the following information:

[HKEY_LOCAL_MACHINE\SOFTWARE\MercuryInteractive\QuickTest rofessional\MicTest\Test Objects\Image]
"tag query name"="alt"

Changing the Mic.ini file
Some of QuickTest Professional information is stored in a text file which is called mic.ini. This file is located under the QuickTest bin directory.
[SectionA]
NameA=ValueA
To enter the above change to the mic.ini file you should perform the following:

Open the mic.ini file located under the QuickTest Professional bin directory using any standard text editorSearch for section name (in this case 'SectionA').
 If it does not exists - add it to the end of the file.
If the line (beginning with the NameA text) exists in the section, then change the value to be ValueA.
If the line does not exist add it to the end of this section (before the next Section begins)

How to change the registry?
Note: 
Errors in the correct editing of the registry may cause severe malfunction to the operating system.
[HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\KeyA]
"ValueA"=dword:0000001
"ValueB"="StringValue"

In order to enter the above change to the registry, you should do the following:

Open regedit (type regedit in the Start>Run dialog)

Navigate to the specified path (in this case navigate to HKEY_CURRENT_USER > Software >...>KeyA)

If the path does not exists, right click on the right pane, choose Key and enter the missing key name
If the value does not exists, right click on the right pane, choose DWORD value or String value and enter the missing variable name.
Right click on the variable, choose Modify and change the value to the correct one

 How to record on non standard menus?
In QuickTest Professional 8.0 you can decide how do you want QuickTest to behave while recording on menus from the UI.

This option is available in the "Advanced Windows Application Options" dialog to be found under
Tools > Options > Windows Applications > Advanced.
More information can be found in the QuickTest User's Guide.

How to terminate an application that is not responding?

You can terminated any standard application while running a script in QuickTest.
If you want to terminate the application, just set this line:
SystemUtil.CloseProcessByName "app.exe"
                         or
SystemUtil.CloseProcessByWndTitle "Some Title"

How to configure QuickTest to record on Embedded HTML Controls?
In order to be able to record context sensitive operations on Embedded HTML Controls (an application which contains an embedded IE HTML viewer), you will need to set the following
Add to the ie_hook section in mic.ini (located under QuickTest bin directory) the following lines:

[ie_hook]
myapp.exe=yes (where myapp.exe is the executable name of the application you want to test)

you should change the following setting in the registry:
[HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\Hooks\myapp.exe]

"bbHook"=dword:00000001
 
"GetMessageHook"=dword:00000001
 
"WndProcHook"=dword:00000001

How do I launch a new browser from a test?
A new browser window (and any other application) can be launched from within a test by adding the following step to your test:

SystemUtil.Run "iexplore.exe", "http://www.mercuryinteractive.com"

How to access the HTML tags directly?
QuickTest provides direct access to the browser's Document Object Model (DOM) through which you may access the HTML tags directly. Access to the DOM is done using the .Object notation. You can find more information about the DOM on the Microsoft Web Workshop web site.

The test below demonstrates how to iterate over all the tags in the page. The test then outputs the inner-text of the tags (the text contained between the tags) to the report using the Reporter object.

' We need the on error because not all the elements have inner-text
 
On Error Resume Next
Set Doc = Browser("CNN Interactive").Page("CNN Interactive").Object
' Loop through all the objects in the page
 
For Each Element In Doc.all
     TagName   = Element.TagName    ' Get the tag name
     InnerText = Element.innerText  ' Get the inner text
     ' Write the information to the report
     Reporter.ReportEvent 0, TagName, InnerText
Next

Where can I find a web page's cookie?
The cookie used by the browser may by accessed through the browser's Document Object Model (DOM). The following example returns the cookie collection from the browser. You can find more information about the DOM on the Microsoft Web Workshop web site.
Browser("Flight reservations").Page("Flight reservations").Object.Cookie

How to change the template test which is used by Quality Center to create new tests?
When creating a new test from Quality Center, the test is based on a template test which is located under "bin/TD2000" directory under the "TestDirector Plugins" installation.
You can replace this test to contain the test template that you wish to be used. Note that if you change the test to use a QuickTest Professional 6.0 (or later) template test then this test can not be opened in Astra LoadTest 5.x

How to change the manual template test which is used by Quality Center when converting manual tests to QuickTest test?
When you have a manual test defined in Quality Center and you want to create from it an automatic test, you can control the way this automatic test will be created.

You can edit the ManualTemplate.txt file located under "bin/TD2000" directory under "TestDirector Plugins" installation to contain the steps which you want to be generated in the QTP test for each manual step.

How to close QuickTest after <n> runs when running from Quality Center?
When running multiple QuickTest Professional tests from Quality Center you can specify that you want to close QTP after specific amount of tests which are executed.

To do so, you should add to the end of the mic.ini file (located under the bin directory of QTP installation) the following lines:

[RemoteAgent]
CloseToolAfterRuns=<number>

How to configure which add-ins will be loaded when working with Quality Center?
Note: From QTP 6.5 version the test is opened with the correct add-ins, the settings below can be used with older versions.

When Quality Center launches QuickTest Professional to run tests, then by default QTP is loaded with all add-ins which are installed on the machine. If you want QTP to be loaded with the last add-ins configuration which was opened on this specific machine you should change the following value in the registry of the machine which QTP is running on:

[HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\AddIn Manager]
"SilentModeWithPredefinedAddIns"=dword:0000001


How to open Quality Center connection dialog faster?
You can launch the Quality Center connection dialog by double clicking on the right pane of the status bar of either QuickTest or the Report.

How do I use QuickTest together with Quality Center?
Quality Center is a powerful test management tool that enables you to manage and control all phases of software testing. It provides a comprehensive view of the testing process so you can make strategic decisions about the human and material resources needed to test an application and repair defects.

Write a code to open a new test and configure the resources for the test.
Dim qtApp                  'As QuickTest.Application ' Declare the Application object variable
Dim qtTestResources 'As QuickTest.Resources ' Declare a Resources object variable

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch                                                                         ' Start QuickTest
qtApp.Visible = True             ' Make the QuickTest application visible
qtApp.New                              ' Open a new test

' Return the Resources object
Set qtTestResources = qtApp.Test.Settings.Resources


' Specify an external Data Table file and a shared object repository
qtTestResources.DataTablePath = "C:\Resources\Default.xls"

qtTestResources.ObjectRepositoryPath = "C:\Resources\Resource.mtr"

' Make this shared repository the default for all new tests
qtTestResources.SetObjectRepositoryAsDefault


Set qtTestResources = Nothing
' Release the Resources object
Set qtApp = Nothing ' Release the Application object

 
Write code to open a test, configures run options and settings, and runs the test , checks the results of the test run.
Ans :

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable

Set qtApp = CreateObject("QuickTest.Application")
' Create the Application object
qtApp.Launch                         ' Start QuickTest
qtApp.Visible = True ' Make the QuickTest application visible

' Set QuickTest run options

qtApp.Options.Run.CaptureForTestResults = "OnError"
qtApp.Options.Run.Runnymede = "Fast"
qtApp.Options.Run.ViewResults = False

qtApp.Open "C:\Tests\Test1", True
' Open the test in read-only mode

' set run settings for the test
Set qtTest = qtApp.Test

qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2 to 4
qtTest.Settings.Run.StartIteration = 2
qtTest.Settings.Run.EndIteration = 4
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs

Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1" ' Set the results location

qtTest.Run qtResultsOpt                    ' Run the test

MsgBox qtTest.LastRunResults.Status ' Check the results of the test run
qtTest.Close                                        ' Close the test

Set qtResultsOpt = Nothing ' Release the Run Results Options object
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object


Write Code to uses the Recovery collection to specify a set of
recovery scenarios to associate with a new test.
  
 Dim qtApp      'As QuickTest.Application ' Declare the Application object variable
Dim qtTestRecovery 'As QuickTest.Recovery ' Declare a Recovery object variable
Dim intIndex             ' Declare an index variable

' Open QuickTest and prepare objects variables

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.New     ' Open a new test
qtApp.Visible = True ' Make the QuickTest application visible
Set qtTestRecovery = qtApp.Test.Settings.Recovery ' Return the Recovery object for the current test

If qtTestRecovery.Count > 0 Then ' If there are any default scenarios specified for the test
    qtTestRecovery.RemoveAll ' Remove them
End If

' Add recovery scenarios
qtTestRecovery.Add "C:\Recovery.qrs", "ErrMessage", 1
' Add the "ErrMessage" scenario as the first scenario
 
qtTestRecovery.Add "C:\Recovery.qrs", "AppCrash", 2 ' Add the "AppCrash" scenario as the second scenario
 
qtTestRecovery.Add "C:\Recovery.qrs", "ObjDisabled", 3 ' Add the "ObjDisabled" scenario as the third 
scenario

 ' Enable all scenarios
For intIndex = 1 To qtTestRecovery.Count          ' Iterate the scenarios
    qtTestRecovery.Item(intIndex).Enabled = True ' Enable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
Next

' Enable the recovery mechanism (with default, on errors, setting)
qtTestRecovery.Enabled = True


Set qtApp = Nothing
' Release the Application object
 
Set qtTestRecovery = Nothing ' Release the Recovery object

Write Code to opens a test and loads all the add-ins associated with the test.
Ans :

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim blnNeedChangeAddins ' Declare a flag for indicating whether the test's associated add-ins are currently loaded
Dim arrTestAddins ' Declare the variable for storing the test's associated add-ins

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object

arrTestAddins = qtApp.GetAssociatedAddinsForTest("C:\Tests\Test1") ' Create an array containing the list of addins associated with this test

' Check if all required add-ins are all already loaded
 
blnNeedChangeAddins = False ' Assume no change is necessary
For Each testAddin In arrTestAddins ' Iterate over the test's associated add-ins list
    If qtApp.Addins(testAddin).Status <> "Active" Then ' If an associated add-in is not loaded
        blnNeedChangeAddins = True ' Indicate that a change in the loaded add-ins is necessary
        Exit For ' Exit the loop
    End If
Next

If qtApp.Launched And blnNeedChangeAddins Then

        qtApp.Quit ' If a change is necessary, exit QuickTest to modify the loaded add-ins
End If

If blnNeedChangeAddins Then

    Dim blnActivateOK
    blnActivateOK = qtApp.SetActiveAddins(arrTestAddins, errorDescription) ' Load the add-ins associated with the test and check whether they load successfully.
    If Not blnActivateOK Then ' If a problem occurs while loading the add-ins
        MsgBox errorDescription ' Show a message containing the error
    WScript.Quit ' And end the automation program.
    End If
End If

If Not qtApp.Launched Then
' If QuickTest is not yet open
    qtApp.Launch ' Start QuickTest (with the correct add-ins loaded)
End If

qtApp.Visible = True ' Make the QuickTest application visible

qtApp.Open "C:\Tests\Test1" ' Open the test
Set qtApp = Nothing ' Release the Application object


Write Code to start QuickTest, opens a new test, and configures it for recording and running on a Web application.

Dim qtApp
'As QuickTest.Application ' Declare the application object variable
Set qtApp = CreateObject("QuickTest.Application") ' Create the application object

qtApp.SetActiveAddins Array("Web") ' Activate the Web Add-in
qtApp.Launch                                      ' Start QuickTest
qtApp.New                                          ' Open a new test

' Configure the Web application to use with this test

qtApp.Test.Settings.Launchers("Web").Active = True
qtApp.Test.Settings.Launchers("Web").Browser = "IE"
qtApp.Test.Settings.Launchers("Web").Address = "http://newtours.mercuryinteractive.com "
qtApp.Test.Settings.Launchers("Web").CloseOnExit = True

' Configure Active Screen access settings

qtApp.Test.Settings.Web.ActiveScreenAccess.UserName = "user1"
qtApp.Test.Settings.Web.ActiveScreenAccess.Password = "mypassword"

' Configure other Web settings
qtApp.Test.Settings.Web.BrowserNavigationTimeout = 60000

qtApp.Test.Settings.Web.NextPageIfObjNotFound = True

qtApp.Visible = True
' Make the QuickTest application visible
Set qtApp = Nothing ' Release the Application object


Write Code to open QuickTest and configures its Web options.

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable

Dim qtWebOptions 'As QuickTest.WebOptions ' Declare the Web Options object variable

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
 
qtApp.SetActiveAddins Array("Web") ' Activate the Web Add-in
 
qtApp.Launch ' Start QuickTest
 
qtApp.Visible = True ' Make the QuickTest application visible
 
Set qtWebOptions = qtApp.Options.Web ' Return the Web Options object

' Configure the Web options

qtWebOptions.AddToPageLoadTime = 30 ' Set the time added to page load time to 30 seconds
qtWebOptions.CheckBrokenLinks = True ' Set to check only current host targeted broken links

' Configure advanced Web options

qtWebOptions.EnableBrowserResize = False ' Set to open the browser to its default size
 
qtWebOptions.RunUsingSourceIndex = True ' Set to use the source index property (for better performance)
 
qtWebOptions.RunOnlyClick = True ' Set to run click events as MouseDown, MouseUp and Click
 
qtWebOptions.BrowserCleanup = True ' Set to close all open browsers when test/iteration finishes
 
qtWebOptions.RecordByWinMouseEvents = "OnClick OnMouseDown" ' Indicate for which events to use standard Windows events

qtWebOptions.RecordAllNavigations = True ' Set to record navigation each time the URL changes
 
qtWebOptions.RecordMouseDownAndUpAsClick = False ' Set to record MouseDown and MouseUp instead of Clicks
 
qtWebOptions.RecordCoordinates = False ' Instruct QuickTest not to record actual coordinates
 

If qtWebOptions.OptimizeFrameCreation Then ' If optimizing Page/Frame object creation is currently selected then
    qtWebOptions.OptimizeUsingNonUserData = "Get" ' Instruct QuickTest to ignore non-user data if using Get transfer method
    qtWebOptions.OptimizeUsingUserData = "Get Post" ' Instruct QuickTest to ignore user data if using Get/Post transfer method
    qtWebOptions.OptimizeUsingAdditionalPageInfo = False ' Instruct QuickTest to not to use additional properties to identify existing page
End If

Set qtWebOptions = Nothing
' Release the Web Options object
 
Set qtApp = Nothing              ' Release the Application object


Write Code to configure QuickTest views and panes for running QuickTest in visible mode.
  
 Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
 
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
 
qtApp.Launch ' Start QuickTest

qtApp.ActivateView "ExpertView" ' Display the Expert View
 
qtApp.ShowPaneScreen "ActiveScreen", True ' Display the Active Screen pane
 
qtApp.ShowPaneScreen "DataTable", False ' Hide the Data Table pane
 
qtApp.ShowPaneScreen "DebugViewer", True ' Display the Debug Viewer pane
 
qtApp.WindowState = "Maximized" ' Maximize the QuickTest window
 
qtApp.Visible = True ' Make the QuickTest window visible

Set qtApp = Nothing ' Release the Application object

 
Additional Coding.......

Code One :
The following example uses the Value property to set the value in the current row of the Destination parameter (column) in the “ActionA“ sheet in the run-time Data Table.
DataTable.Value ("Destination", "ActionA")="New York"

The following example uses the Value property to set the value in the current row of the second parameter (column) in the third sheet.
DataTable.Value (2,3)="New York"

Note: You could omit the word Value in the statements above, because Value is the default property for the DataTable object.
The following example uses the default property to set the value in the current row of the Destination parameter (column) in the current (active) local sheet.
DataTable("Destination", dtlocalSheet)="New York"

No comments :

Post a Comment