Saturday 29 August 2015

QTP Interview Related_Covered almost everything

QuickTest Automation Object Model Overview
You can use the QuickTest Professional automation object model to write scripts that automate your QuickTest operations. The QuickTest automation object model provides objects, methods, and properties that enable you to control QuickTest from another application.

Using the objects, methods, and properties exposed by the QuickTest automation object model, you can write scripts that configure QuickTest options and run tests or components instead of performing these operations manually using the QuickTest interface.

Automation scripts are especially useful for performing the same tasks multiple times or on multiple tests or components, or for quickly configuring QuickTest according to your needs for a particular environment or application.

What is Automation?
Automation is a Microsoft technology that makes it possible to access software objects inside one application from other applications. These objects can be created and manipulated using a scripting or programming language such as VBScript or VC++. Automation enables you to control the functionality of an application programmatically.

What is the QuickTest Automation Object Model?
An object model is a structural representation of software objects (classes) that comprise the implementation of a system or application. An object model defines a set of classes and interfaces, together with their properties, methods and events, and their relationships.

The QuickTest automation object model is a set of objects, methods, and properties that enable you to control essentially all of the configuration and run functionality provided via the QuickTest interface. Although a one-on-one comparison cannot always be made, most dialog boxes in QuickTest have a corresponding automation object, most options in dialog boxes can be set and/or retrieved using the corresponding object property, and most menu commands and other operations have corresponding automation methods.

You can use the objects, methods, and properties exposed by the QuickTest automation object model, along with standard programming elements such as loops and conditional statements to design your script.

Automation scripts are especially useful for performing the same tasks multiple times or on multiple tests or components, or for quickly configuring QuickTest according to your needs for a particular environment or application.

Example:

You can create and run an automation script from Microsoft Visual Basic that loads the required add-ins for a test or component, starts QuickTest in visible mode, opens the test or component, configures settings that correspond to those in the Options, Test or Business Component Settings, and Record and Run Settings dialog boxes, runs the test or component, and then saves the test or component.

You can then add a simple loop to your script so that your single script can perform the operations described above for multiple tests or components.

You can also create an initialization script that opens QuickTest with specific configuration settings. You can then instruct all of your testers to open QuickTest using this automation script to ensure that all of your testers are always working with the same configuration.
===============================================
Extern Object
Description
Enables you to declare calls to external procedures from an external dynamic-link library (DLL).

Declare Method
Description
Declares references to external procedures in a dynamic-link library (DLL).

After you use the Declare method for a method, you can use the Extern object to call the declared method.

Syntax
Extern.Declare(RetType, MethodName, LibName, Alias [, ArgType(s)])

 Argument
 Type
 Description

RetType  String  Data type of the value returned by the method. For available data types, see Extern.Declare Data Types.
Note: String value types (micString and micWideString) are not supported as return values.
To return a string value, use a string out argument in the called procedure.
In the Extern.Declare statement, use micVoid for the RetType argument and micByRef + micString (or other relevant string type) for the ArgType argument. For a complete example, see Returning a String Value Using an Extern.Declare Statement. 
MethodName  String  Any valid procedure name. 
LibName  String  Name of the DLL or code resource that contains the declared procedure. 
Alias  String  Name of the procedure in the DLL or code resource.
Note:
DLL entry points are case sensitive.
If Alias is an empty string, MethodName is used as the Alias.

ArgType(s)  String  A list of data types representing the data types of the arguments that are passed to the procedure when it is called. For available data types, see Extern.Declare Data Types.
Note: For out arguments, use the micByRef flag. 


Example
The following example uses the Extern.Declare and Extern.<declared method> methods to change the title of the Notepad window.

'Declare FindWindow method
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
'Get HWND of the Notepad window
hwnd = Extern.FindWindow("Notepad", vbNullString)
if hwnd = 0 then

MsgBox "Notepad window not found"
end if
'Change the title of the notepad window
res = Extern.SetWindowText(hwnd, "kuku")
The following example retrieves information from an external INI file using GetPrivateProfileString, and uses it in the test. Note the use of the micByRef flag to indicate the out argument.

Extern.Declare micInteger,"GetPrivateProfileStringA", "kernel32.dll","GetPrivateProfileStringA", micString, micString, micString, micString+micByRef, micInteger, micString

Dim key, i, key2
key = String(32, "-")
i = Extern.GetPrivateProfileStringA("WREnv","addons","xxx", key, 32, "wrun.ini")
key2 = Left(key,i)
msgbox key & ";" & key2 & ";" & CStr(i)

The following example checks when the cursor is displayed as an hour glass.
extern.Declare micLong,"GetForegroundWindow","user32.dll","GetForegroundWindow"
extern.Declare micLong,"AttachThreadInput","user32.dll","AttachThreadInput",micLong,micLong,micLong

extern.Declare micLong,"GetWindowThreadProcessId","user32.dll",
"GetWindowThreadProcessId",micLong,micLong
extern.Declare micLong,"GetCurrentThreadId","kernel32.dll","GetCurrentThreadId"
extern.Declare micLong,"GetCursor","user32.dll","GetCursor"
function get_cursor()
         hwnd = extern.GetForegroundWindow()
         pid = extern.GetWindowThreadProcessId(hWnd, NULL)
         thread_id=extern.GetCurrentThreadId()
         extern.AttachThreadInput pid,thread_id,True
         get_cursor=extern.GetCursor()
         extern.AttachThreadInput pid,thread_id,False
end function
Msgbox get_cursor()

***********************************************
ChildObjects Method
Returns the collection of child objects contained within the object. 
Important Information
This method returns a null value for any object that is not a parent object
********************************
Check Method
Description
Checks whether the actual value of an item matches the expected value.
Important Information
You create checkpoints and define the property checks for the checkpoint using one of the Insert Checkpoint options. For more information, refer to the QuickTest Professional User's Guide.

If you want to retrieve the return value of a checkpoint, you must add parentheses around the name of the checkpoint in the statement. For example:

a = Browser("MyBrowser").Page("MyPage").Check ( CheckPoint("MyProperty"))
Syntax
object.Check (Verify)
Argument Description
object A test object of type Browser.
Verify Required. A Variant value.
The checkpoint object that contains the expected values to be compared and verified during the test run.
returns boolean value
=========================================
CheckProperty Method
Checks whether the specified object property achieves the specified value within the specified timeout.
If the expected and actual values do not match, an error is reported and the test or component status is changed to failed.

Note: For test run synchronization, or whenever you do not want to fail the test if the expected and actual values do not match, use the WaitProperty method.

You can also use comparison objects to perform more complex value comparisons. For example, you can instruct QuickTest to check whether a specific property value is greater than the specified value.

An example of the syntax required when using a comparison object is: Object.CheckProperty "items count",micGreaterThan(8)

object.CheckProperty (PropertyName, PropertyValue, [TimeOut])
A Boolean value.  Returns TRUE if the property achieves the value, and FALSE if the timeout is reached before the property achieves the value.
A TRUE return value reports a Passed step to the run results; a FALSE return value reports a Failed step to the run results.
Check Whether Text is Entered in an Edit Box :
Browser("Nested Lists").Page("Page").WebEdit("Name").Set "Mercury"
Browser("Nested Lists").Page("Page").WebEdit("Name").CheckProperty "value", "Mercury"
=================================================
WaitProperty Method
Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.
Tip: This method is useful for test run synchronization. Unlike the Exist method, the WaitProperty method enables you to synchronize the test run based on a specific object property. For example, you can instruct QuickTest to wait for a particular string to appear in a static text control:
' Wait up to 30 seconds for the string "Ready" to appear in the "Status" text control.
Window("Test").Static("Status:").WaitProperty "text", "Ready", 30000

You can also use comparison objects to perform more complex value comparisons. For example, you can instruct QuickTest to wait until a specific property value is greater than the specified value.

An example of the syntax required when using a comparison object is: Object.WaitProperty "items count",micGreaterThan(8)

Wait Up to 4 Seconds For a Link to Be Ready
If Browser("index").Page("index").Link("All kind of").WaitProperty("attribute/readyState", "complete", 4000) Then
    Browser("index").Page("index").Link("All kind of").Click
End If
==========================================
Object Property : Accesses the native methods and properties of the browser.
This property is not supported when working with Browser objects in Mozilla Firefox.

The Document Object Model (DOM) is a set of objects that correspond to the elements you see on a Web page.  You can modify the appearance and behavior of an HTML element by altering a DOM object's properties and calling its methods.

When you use the QuickTest Object property for a Web object, you actually get a reference to the DOM object. This means that any operation that you can perform on a DOM object, you can also perform by running a <WebTestObject>.Object statement on the Web object. For example, you can use the links property of the Internet Explorer document object to retrieve a link collection.

The Web Object property can be used only for supported versions of Internet Explorer and Mozilla Firefox.
**************************************
pwd = "GetPasswordfromSomewhere"
e_pwd = Crypt.Encrypt(pwd)
Browser("dfgd").Dialog("pass").WinEdit("pwd").SetSecure e_pwd
=====================================================
Create Method
Returns a Properties Object (Collection) in which you can add a set of properties and values in order to create the description of an object during a run session. You can then use this object in place of a test object name in a step.
==============================
Environment Object
Enables you to work with environment variables.
You can set or retrieve the value of environment variables using the Environment object. You can retrieve the value of any environment variable. You can set the value of only user-defined, environment variables.

To set the value of a user-defined, environment variable:
Environment (VariableName) = NewValue
To retrieve the value of a loaded environment variable:
CurrValue = Environment (VariableName)

The following example creates a new internal user-defined variable named MyVariable with a value of 10, and then retrieves the variable value and stores it in the MyValue variable.
Environment.Value("MyVariable")=10
MyValue=Environment.Value("MyVariable")
======================================
Timer Property
Accesses the timer with the specified name from the MercuryTimers collection object, or creates a new timer with this name if the timer does not yet exist.

Important Information 
The Timer property is the default property for the MercuryTimers collection object.
Set MyTimer = MercuryTimers.Timer(TimerName)
 Argument
 Type
 Description 
TimerName  String  The name of the specific timer. 

Notes:
You can omit the word Timer in the syntax, because Timer is the default property for the MercuryTimers collection object.
Instead of returning the internal timer object to the MyTimer variable, you can perform MercuryTimer methods directly on the returned object within the same statement, as shown in the following example.
The following example uses two MercuryTimer objects (Timer1 and Timer2) to measure elapsed time in milliseconds, send a report to the run results, convert the time from milliseconds to seconds, and set a transaction.

MercuryTimers("Timer1").Start 'Start measuring time using Timer1.

Wait 1

MercuryTimers("Timer1").Stop 'After one second, stop Timer1.

MercuryTimers("Timer2").Start 'Start measuring time usingTimer2.

'Two seconds later, restart Timer1 (which will continue to measure time from
'the time it stopped while Timer2 continues uninterrupted).

Wait 2

MercuryTimers("Timer1").Continue

'Three seconds later, stop both timers and send a report to the test
'results specifying the elapsed time for each of the timer objects
'(Timer1 ~4000 ms; Timer2 ~5000 ms).

Wait 3

Reporter.ReportEvent micDone, "Elapsed Time", "Timer1: " & MercuryTimers("Timer1").Stop() & "ms, Timer2: " & MercuryTimers("Timer2").Stop() & "ms"

'Set a transaction manually for each of the timer objects. Convert the
'elapsed time for each of the timer objects from milliseconds to seconds so
'the elapsed time will be reported correctly in the transaction.

Services.SetTransaction "Timer1",MercuryTimers("Timer1").ElapsedTime / 1000,Pass

Services.SetTransaction "Timer2",MercuryTimers("Timer2").ElapsedTime / 1000,Pass
**************************************
Reset Method
Returns the elapsed time in milliseconds and resets the timer to zero.
If the timer is already running, the Reset method stops it before resetting the time to zero.

Syntax
retTime = MercuryTimers.Timer(TimerName).Reset
or
retTime = MercuryTimers(TimerName).Reset
Note: You can omit the Timer property in the syntax, because Timer is the default property for the MercuryTimers collection object.
Return Value
A Number. The elapsed time in milliseconds.

Example
The following example resets the stopped MercuryTimer object, Timer1.
MercuryTimers("Timer1").Start 'Start measuring time using Timer1.
Wait 1
MercuryTimers("Timer1").Stop 'After one second, stop Timer1.
'Two seconds later, reset Timer1 so it will start to measure time from zero
Wait 2
msgbox MercuryTimers("Timer1").Reset    '''returns number of milli seconds elapsed.
=========================
ElapsedTime Property
Returns the total accumulated time in milliseconds since the timer started.
Important Information 
The ElapsedTime property is the default property for the MercuryTimer object.
Syntax
retTime = MercuryTimers.Timer(TimerName).ElapsedTime
or
retTime = MercuryTimers(TimerName).ElapsedTime
or
retTime = MercuryTimers.Timer(TimerName)
or
retTime = MercuryTimers(TimerName)
Note: You can omit the Timer property and/or ElapsedTime property in the syntax, because Timer is the default property for the MercuryTimers collection object, and ElapsedTime is the default property of the MercuryTimer object.
Return Value
A Number. The total accumulated time in milliseconds since the timer started.
Example
The following example returns the elapsed time in milliseconds for the MercuryTimer object named Timer1. It then sends a report to the run results, convert the time from milliseconds to seconds, and sets a transaction.

MercuryTimers("Timer1").Start 'Start measuring time using Timer1.

'Three seconds later, stop Timer1 and send a report to the test
'results specifying the elapsed time in milliseconds (~3000 ms).
Wait 3
Reporter.ReportEvent micDone, "Elapsed Time", "Timer1: " & MercuryTimers("Timer1").Stop() & "ms"
'Set a transaction manually and convert the elapsed time from milliseconds to
'seconds so the elapsed time will be reported correctly in the transaction.
Services.SetTransaction "Timer1",MercuryTimers("Timer1").ElapsedTime / 1000,Pass
===================================
Continue Method
Description
Continues running the timer from the time it stopped (without resetting it).
Important Information 
If the timer is already running, the Continue method does not affect it.
Syntax
MercuryTimers.Timer(TimerName).Continue
or
MercuryTimers(TimerName).Continue
Note: You can omit the Timer property in the syntax, because Timer is the default property for the MercuryTimers collection object.
Example
The following example continues the stopped MercuryTimer object, Timer1, from the time it stopped.

MercuryTimers("Timer1").Start 'Start measuring time using Timer1.
Wait 1
MercuryTimers("Timer1").Stop 'After one second, stop Timer1.
'Two seconds later, restart Timer1 (which will continue to measure time from
'the time it stopped).
Wait 2
MercuryTimers("Timer1").Continue
=============================================
ReportEvent Method
Description
Reports an event to the run results.
Syntax
Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]

 Argument
 Type
 Description

EventStatus  Number or pre-defined constant  Status of the Run Results step:
0 or micPass: Causes the status of this step to be passed and sends the specified message to the Run Results window.
1 or micFail: Causes the status of this step to be failed and sends the specified message to the Run Results window. When this step runs, the test or component fails.
2 or micDone: Sends a message to the Run Results window without affecting the pass/fail status of the test or component.
3 or micWarning: Sends a warning message to the Run Results window, but does not cause the test or component to stop running, and does not affect the pass/fail status of the test or component. 
ReportStepName  String  Name of the step displayed in the Run Results window. 
Details  String  Description of the Run Results event. The string will be displayed in the step details frame in the Run Results window. 
ImageFilePath  String  Optional. Path and filename of the image to be displayed in the Captured Data pane of the Run Results window. Images in the following formats can be displayed: BMP, PNG, JPEG, and GIF.
Notes:
Images cannot be loaded from Quality Center.
Including large images in the run results may impact performance.
If an image is specified as a relative path, QuickTest will first search the Results folder for the image and then the search paths specified in the Folders pane of the Options dialog box.

Examples
The following examples use the ReportEvent method to report a failed step.
Reporter.ReportEvent 1, "Custom Step", "The user-defined step failed."
or
Reporter.ReportEvent micFail, "Custom Step", "The user-defined step failed."
The following example uses the ReportEvent method to include a captured bitmap in the run results.
Browser("Browser").Page("WebPage").Image("MyLogo").CaptureBitmap("MyLogo.bmp")
Reporter.ReportEvent micDone, "Display Logo", "This is my logo", "MyLogo.bmp"
==================================
strScreenCapPath = Environment.value("SystemTempDir") & "\" & strTestName & "_"  & strDateTime & "_" & replace(Timer, ".", "") & "_StepNo_" & intStepNo & ".png"       
Desktop.CaptureBitmap strScreenCapPath
=======================
ThinkTime Method :Pauses the execution during a test run to simulate the time a real user pauses between actions.
Services.ThinkTime Seconds 
==========================
QTP Menu bar items missing
QTP Menu bar items missing
Very recently, I found a very weird QTP issue that all menu items went missing. I kept on trying all menu bar items but most of the items went missing. I thought my QTP 11 software got corrupt and I reinstalled it.

After a fresh installation, the same issue was there. I did a lot of hit and trials and finally got the solution. Sometimes the issue comes when we use RestoreLayout method from Automation Object Model. Then unpredictable errors may occur while the script execution is in process including these menu items missing from "File", "Edit", "View" menus etc.

The solution I got is to right click anywhere on the toolbar area, click Customize, choose toolbars tab and click on the Restore all button. This should definitely fix this.

1 comment:

  1. Casino - DRMCD
    ress for casino 강릉 출장안마 games,” he said. ” is a registered trademark ” is a registered trademark 안성 출장샵 안산 출장샵 ” is a registered trademark ” 과천 출장마사지 is a 울산광역 출장마사지 registered trademark and ”

    ReplyDelete