Monday, August 25, 2008

Export TestPartner run into xml with xsl

TestPartner run results can be exported using command line, tpexport, or via File|Export from with TestPartner itself.

Another way of exporting run results is via TestPartner.TLB automation. The beauty with TestPartner.TLB is that you can export with it the xsl.

See below for the code.
Option Explicit
Sub TestTPResultDump()
    Dim t As New TPApp
    Dim pCount As Integer
    Dim p As Integer
    Dim sCount As Integer
    Dim sName As String
    Dim tp2 As TestPartner.TPProject2


    t.Login "admin", "admin", "TestPartner_SQL", 1

    pCount = t.Projects.Count

    For p = 1 To pCount
        If t.Projects.Item(p).Name = "ScratchProject" Then
            Debug.Print t.Projects.Item(p).Name
            Set tp2 = t.Projects.Item(p)
            Dim rc As Integer
            For rc = 1 To tp2.Results.Count
                If tp2.Results.Item(rc).Name = "scratch2" Then
                    Debug.Print tp2.Results.Item(rc).Description
                    Debug.Print tp2.Results.Item(rc).Name
                    Debug.Print tp2.Results.Item(rc).LastModifiedBy
                    Dim v As Long
                    v = tp2.Results.Item(rc).CurrentVersion
                    Dim rr As TestPartner.TPResult
                    Set rr = tp2.Results.Item(rc)
                    rr.Open (v)
                    Debug.Print rr.GetXML(v, v, "d:\test.xml")
                    Call rr.GetXML(v, 1, "D:\test.xml", "D:\test.xsl")
    
                    Dim sXLST As String
                    Dim fXLST As Scripting.File
                    
                    Debug.Print rr.GetXSLT(1, sXLST)
                    'Debug.Print sXLST
                    Dim fso As Scripting.FileSystemObject
                    Dim ts As Scripting.TextStream
                    Set fso = New Scripting.FileSystemObject
                    Set ts = fso.OpenTextFile("D:\test.xsl", ForWriting, True, TristateTrue)
                    ts.Write sXLST
                    ts.Close
                    Set ts = Nothing
                    Set fso = Nothing
                End If
            Next rc
            'tp2.Results.Count
        End If

    Next p
End Sub

Note that you need reference to TestPartner(TestPartner.TLB) and Microsoft Scripting Runtime for the above code snippets to work.

See below for the location of the type library:

















~ts

Saturday, August 23, 2008

Handle popup menus manually in TestPartner

One of the areas where TestPartner 6.1.x is challenged in controlling application under test (AUT) is Popup Menus. It handles it one time but sometimes it complains that the menu is not detected but it is clearly infront of the screen. Though it is working ~80% of the time but Murphy's law has it that if anything can go wrong, it will. What I have come up so far is to handle popup menus manually. See below for the code, so far it seems to meet my needs.

Option Explicit
Private Declare Function SetCursorPos Lib "user32" _
    (ByVal x As Long, ByVal y As Long) As Long
Sub Main()
    'open Windows Explorer in "My Computer"
    Window("Desktop Window").Attach
        ListView("Index=1").Select "CD Drive (E:)", tpMouseRight
    
    PopupMenuEx2 "Properties"

    Window("Application=Explorer.exe Classname='#32770'").Attach
        Button("Caption=OK").Click



End Sub
Private Function PopupMenuEx2(sMenuPath As String) As Boolean
    Dim iMenuCount As Integer
    Dim sMenuSplit As Variant
    Dim iMenuPos As Integer
    
    SetCursorPos 1, 1
    Window.MouseMove 1, 1
    
    'Note that this is important. This is to minimize code in SelectMenuItem
    SendKeys "{DOWN}", True
    sMenuSplit = Split(sMenuPath, "~")
    For iMenuCount = 0 To UBound(sMenuSplit)
        SelectMenuItem sMenuSplit(iMenuCount), iMenuCount > 0
        
        If iMenuCount = UBound(sMenuSplit) Then
            SendKeys "{ENTER}", True
            Exit For
        Else
            SendKeys "{RIGHT}", True
        End If
    Next
End Function

Private Function SelectMenuItem(ByVal sMenuStr As String, isSubMenu As Boolean) As Integer
    Dim mnu As TMenu
    Dim ti As TMenuItem
    Dim i As Integer
    Dim sAttachName As String
    Const DELAY = 100
    
    sAttachName = Window.Application
    sAttachName = "Application=" & sAttachName & " ClassName='#32768'"
    If isSubMenu = False Then
        Set mnu = Window(sAttachName).GetMenu(tpPopupMenu)
    Else
        Set mnu = Window(sAttachName).GetMenu(tpMenu)
    End If
    For i = 1 To mnu.Count
        Set ti = mnu.GetItem(i)
        If ti.Text = sMenuStr Then
            Sleep DELAY, tpPauseMilliSeconds
            Exit Function
        End If
        If Not (ti.IsSeparator) Then
            Sleep DELAY, tpPauseMilliSeconds
            SendKeys "{DOWN}", True
        End If
    Next
End Function
~ts

Saturday, August 16, 2008

Print active application and title using pywinauto

Code snippet below shows how to get the window title and application name of the active application. That is the application on top of the z-order. Need to install pywinauto to get this to work.

import pywinauto.application
import pywinauto.handleprops as _handleprops
import pywinauto.win32functions as _win32functions
import time

while 1:
    hwnd = _win32functions.GetForegroundWindow()
    print "Active Window title is %s"%(_handleprops.text(hwnd))
    print "Application name is %s"%(pywinauto.application.process_module(_handleprops.processid(hwnd)))
    time.sleep(2)    

~ts

Tuesday, August 05, 2008

USB Mouse not detected properly in Vista

After using Windows Vista for over a month my USB mice stopped working :(.... Fortunately this is easy to fix via trial and error on what driver best works for Vista. To fix this do the ff:

Step 1. Go to Device Manager (devmgmt.msc).

Step 2. Do Update Driver Software.

Step 3. Browse my computer for driver software.

Step 4. Select "Let me pick from from a list of device drivers on my computer."

Step 5. If it was shown as unknown device, select "Mice and other pointing device" else select "HID-compliant device."

Step 6. Click on "Have Disk..."

Step 7. Drill to C:\Windows\System32\DriverStore\FileRepository. Select a folder with a name that start with msmouse*. Start with the folder that has the latest time stamp. If this driver does not work select the next newer folder until your mouse driver is installed properly.

See below for related figures.

Figures:

capture

Figure 1.

capture2

Figure 2.

~ts