Tuesday, September 18, 2012

GetTextLocation example using QTP


Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString

hwnd = Extern.FindWindow ("MSPaintApp", "cmd.gif - Paint")'
Print hwnd

l = -1 'left
t = -1 'top
r = -1 'right
b = -1 'bottom

succeeded = TextUtil.GetTextLocation("rights",hwnd,l,t,r,b)
Print succeeded

If Succeeded Then
 Print "Text found" & " Left:" & l &  " Top:" & t &  " Right:" & r &  " Bottom:" & b
End If

Monday, September 17, 2012

Enabling QTP to indentify WPF windows objects

I was trying to create a test script for an application which had a grid like UI build using WPF. When i tried to use QTP object spy it wasn't able to detect this object. After following up with HP someone in our team found a solution to this probem as:

Using command prompt with Run As Administrator execute the following command to register the DLLs found under "\Program Files (x86)\HP\QuickTest Professional\GlobalAssemblyCache\Net4"

C:\Program Files (x86)\HP\QuickTest Professional\bin> GACRegUtil4x86.exe -ie ..\G
lobalAssemblyCache\Mercury.QTP.Agent.dll



Hope this helps to someone facing the same issue.

Reference:
http://h30499.www3.hp.com/t5/Functional-Testing-QTP-Support/WPF-test-record-problems/td-p/5791825

Typical Structure for Test Automation Framework

DataRepo:
                This holds data. A standard tool like XL or MDB to hold test data and allowing enough flexibility to manipulate and modify data effectively. This tool / component will typically contain a list of test cases and the test data to be fed to the test case.

ActionLibrary:
                Also understood as functional keywords. All possible actions for a page in the AUT are captured in the form of functions. These functions can be called in the form of test steps.

CommonLibrary:
                Library of functions which make the code modular and reusable. This will typically contain following set of common technical functionalities:
1.       Data access
2.       Logging
3.       File handling
4.       Time handling
5.       Test Result Prepare & Publish

ObjectRepo:
                This is a repository to hold information about the objects which are part of the test application. Using this information the test script identifies the object to perform action on it.

Driver:
                This is a common script which ties / glues all the components described above. As a typical flow, driver script will do the following:
1.       Get the test case details (name, test data, etc) from DataRepo
2.       Based on the test steps it decides which functions to call and pass what test data to it
3.       Each function call tries to identify an object using the attributes available from the ObjectRepo to perform action around it.

Tuesday, February 7, 2012

Solution to problems with running QTP on a locked system

Refer: http://www.sqaforums.com/showflat.php?Cat=0&Board=UBB20&Number=584180

In case this page dissapears from above URL:

Quote:
I was able to overcome this problem for Web Applications.Since QTP using events which can be executed on locked box, the only real problem is dealing with dialog boxes. WinButton().Click doesn't work. To get around this problem I am using:WM_COMMAND = 273 '&H111'buttonCode - window id property for the button to clickextern.PostMessage(Hwnd, WM_COMMAND, buttonCode, 0)We run our automation nightly on locked boxes.Warning: Do not use Java Add-in 9.1 for locked execution - it will crash QTP.

############################

There is another way....you can either put this code into a .Net DLL and call it from your test script or you can modify the key in the code manually (or using VBSCRIPT) to achieve the same results.This assumes admin powers or at least enough to modify the registry key in question. I use it and it works quite nicely.Code:

public void DisableScreenTimeout(bool bEnable, int nInterval) { aTimer.Elapsed += new ElapsedEventHandler(OnDisableTimeout); // Set the Interval to nInterval seconds if (nInterval > 0) { aTimer.Interval = nInterval; } else { aTimer.Interval = 0; } aTimer.Enabled = bEnable; }
private static void OnDisableTimeout(object source, ElapsedEventArgs e) { RegistryKey regKey = Registry.CurrentUser; if (null != regKey) { regKey = regKey.OpenSubKey(@"Software\Policies\Microsoft\Windows\Control Panel\Desktop", true); if (null != regKey) { regKey.SetValue("ScreenSaveActive", 0, RegistryValueKind.String); regKey.SetValue("ScreenSaverIsSecure", 0, RegistryValueKind.String); } } }public void DisableScreenTimeout(bool bEnable, int nInterval) { aTimer.Elapsed += new ElapsedEventHandler(OnDisableTimeout); // Set the Interval to nInterval seconds if (nInterval > 0) { aTimer.Interval = nInterval; } else { aTimer.Interval = 0; } aTimer.Enabled = bEnable; }
private static void OnDisableTimeout(object source, ElapsedEventArgs e) { RegistryKey regKey = Registry.CurrentUser; if (null != regKey) { regKey = regKey.OpenSubKey(@"Software\Policies\Microsoft\Windows\Control Panel\Desktop", true); if (null != regKey) { regKey.SetValue("ScreenSaveActive", 0, RegistryValueKind.String); regKey.SetValue("ScreenSaverIsSecure", 0, RegistryValueKind.String); } } }
###################################

You can try with this part of code too.(hisudhakar.spaces.live.com)In starting of the script use SystemUtil.BlockInput, and at end of the script use SystemUtil.UnblockInput.So that QTP will lock and unlock machine in script running.You don't see the locked screen on your machine after executing SystemUtil.BlockInput. The same screen will be there but it don't accept any user input.

Thursday, January 5, 2012

How to kill Remote Sessions Remotely

You'll need a Windows console running as an appropriate user, this can be dealt with using a quick runas command:

runas /noprofile /user:domainname\userid cmd
pause

In the console you can then use qwinsta to query for a server's connections, for example:
C:\WINNT\system32>qwinsta /server:someServerHost0290
SESSIONNAME USERNAME ID STATE TYPE DEVICE
console 0 Conn wdcon
rdp-tcp 65536 Listen rdpwd
rdp-tcp#59 userid2 2 Active rdpwd
userid1 1 Active rdpwd

Guessing that Session 1 is up for a quick death you can then use the rwinsta command to kill the connection:
C:\WINNT\system32>rwinsta /server:someServerHost0290 1

Done.