Friday

Fitnesse from Command line


In continuation to my previous post "Integrating QC with Fitnesse"
Here are the commandline options for running Fitnesse:

Advantages:
  1. All tests run in a single process unlike the web server test executions.
  2. It's easily debuggable.
  3. It removes the need to start a local FitNesse server to run tests.
  4. Can generate HTML output to a file
  5. Can generate XML output to a file
Sample Command:
java -jar fitnesse.jar -p "&strPort&" -c "&strFITTestScriptName&" > "&strExpectedResultsPath

Command line options:
  1. -debug
    This option will print FitNesse protocol actions to the console.
  2. -v
    This option should give a verbose output about test progress to the console
  3. -results file
    The result of the testrun is saved to a textfile with the given name.
  4. -html file
    The result of the testrun is saved to a html file with the given name.
  5. -xml file
    The result of the testrun is saved to a xml file with the given name.
  6. -nopath
    This option will make FitNesse ignore !path options specified in the wiki pages.
  7. -suiteFilter filter
    Specifying a filter will only run pages with tags matching the filter.

Thursday

VBA - Combine worksheets in Excel and Kill all excel objects


This is a simple vba script that will let you combine excel work sheets and make sure no orphan excel objects are pending.


Sub CopyFromWorksheets()
Dim wrk As Workbook
Dim sht As Worksheet
Dim trg As Worksheet
Dim rng As Range
Dim colCount As Long
'Dim sheetDelimiter As String

' Creates excel app object
Set objExcel = CreateObject("Excel.Application")
  
' Makes the excel invisible
objExcel.Visible = False

' Supress all display alerts
objExcel.DisplayAlerts = False

' Gets the complete path of the active excel sheet
strExcelFilePath = ActiveWorkbook.FullName
 
' Opens the excel file
Set objWorkbook = objExcel.Workbooks.Open(Trim(strExcelFilePath))


Set objWorkSheet = objWorkbook.Worksheets("Merge")
objWorkSheet.Activate

' Gets the count of column
Set objRange = objWorkbook.Worksheets("Merge")
numRowsCount = objRange.Evaluate("COUNTA(A1:A100)")
Worksheets("Merge").Activate

'sheetDelimiter = "######"
Set wrk = ActiveWorkbook 'Working in active workbook

For Each sht In wrk.Worksheets
If sht.Name = "Consolidated Backlog" Then
MsgBox "There is a worksheet called as 'Consolidated Backlog'." & vbCrLf & _
"Please remove or rename this worksheet since 'Consolidated Backlog' would be" & _
"the name of the result worksheet of this process.", vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
Next sht

Application.ScreenUpdating = False
Set trg = wrk.Worksheets.Add(After:=wrk.Worksheets(wrk.Worksheets.Count))
trg.Name = "Consolidated Backlog"
'Get column headers from the first worksheet
'Column count first
Set sht = wrk.Worksheets(1)
colCount = 30

For cntLoop = 1 To numRowsCount
     strSheetName = Trim(UCase(objExcel.Cells(cntLoop, 1).Value))
     If Trim(strSheetName) = "" Then
        Exit For
     End If
     If Trim(strSheetName) = "SHEET NAMES" Then
       GoTo Continue
     End If
     For Each sht In wrk.Worksheets
        'If worksheet in loop is the last one, stop execution (it is Master worksheet)
        If sht.Index = wrk.Worksheets.Count Then Exit For
        If strSheetName = UCase(sht.Name) Then
            'Delimits the copied sheets with a string in a new row
            With trg.Cells(1, 1).Resize(1, colCount)
                .Value = sht.Cells(1, 1).Resize(1, colCount).Value
                 'Set font as bold
                .Font.Bold = True
            End With
           
            trg.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(1, 1).Value = sheetDelimiter
            Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(Rows.Count, 1).End(xlUp).Resize(, colCount))
            rng.Copy trg.Cells(Rows.Count, 1).End(xlUp).Offset(1)
            'Set objRange = sht.Range("A1").EntireColumn
            'objRange.Insert (xlShiftToRight)
            'sht.Range("A1") = sht.Name
        End If
    Next sht
Continue:
Next

objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
Set sht = Nothing
Set objWorkSheet = Nothing
Set objRange = Nothing
Set trg = Nothing
Set rng = Nothing

Application.ScreenUpdating = True
'create WMI object instance
Set objWMI = GetObject("winmgmts:")
If Not IsNull(objWMI) Then
'create object collection of Win32 processes
Set objProcList = objWMI.InstancesOf("win32_process")
For Each objProc In objProcList 'iterate through enumerated
If UCase(objProc.Name) = UCase(procName) Then
objProc.Terminate (0)
End If
Next
End If
Set objProcList = Nothing
Set objWMI = Nothing


End Sub

Happy Coding..

Wednesday

QC OTA - Test Lab



Here are some amazing functions that can be reused wrt QC OTA for Test Lab module:
- Create Test Set
- Add tests to Test Set
- Create the supplied directory structure in the test lab
- Create a test set underneath a given parent
- Return a test set if it exists
- Returns a testsetfolder for the given path
Public Function TestLabCreateTestSet(strFolderPath As String, strTestSetName As String, ByRef CreatedTestSet As TestSet)
    Dim tstSetFolder As TestSetFolder
    Dim testSetFolderF As TestSetTreeManager
    Dim TestSetF As TestSetFactory
    Dim testSet1 As TestSet
    Dim oTestSet As TestSet
   
   
    'Does the test set already exist? If so return it
    Set oTestSet = TestLabGetTestSet(strFolderPath, strTestSetName)
    If Not (oTestSet Is Nothing) Then
        'MsgBox "Test Set Already Exists: " & strFolderPath & "\" & strTestSetName
        Set CreatedTestSet = oTestSet
        Exit Function
    End If
   
   
    Set testSetFolderF = tdc.TestSetTreeManager
    Set tstSetFolder = TestLabGetFolderByPath(strFolderPath)
   
    Set TestSetF = tstSetFolder.TestSetFactory
    Set testSet1 = TestSetF.AddItem(Null)
    testSet1.Name = strTestSetName
    testSet1.Status = "Open"
    testSet1.Field("CY_USER_01") = "Reviewed"
    'testSet1.
    testSet1.Post
   
   
    If Err = 0 Then
        TestLabCreateTestSet = True
        Set CreatedTestSet = testSet1
    Else
        MsgBox Err.Description
        TestLabCreateTestSet = False
    End If
End Function
----------------------------------------------------------
Public Function TestLabAddTestToTestSet(ByVal objTestSet As TestSet, ByVal objTest As Test, ByRef objTestInTestSetObj) As Boolean
    Dim testInstanceF As TSTestFactory
   
    On Error GoTo ErrTrap
    'Get or create a test instance from the factory of the new test set
    Set testInstanceF = objTestSet.TSTestFactory
    Set objTestInTestSetObj = testInstanceF.AddItem(objTest.ID)
   
    objTestInTestSetObj.Status = "No Run"
    objTestInTestSetObj.Post
   
    TestLabAddTestToTestSet = True
    Exit Function
   
ErrTrap:
    MsgBox Err.Description, vbCritical, "TestLabAddTestToTestSet"
    TestLabAddTestToTestSet = False
End Function

------------------------------------------------------------------------
Public Sub TestLabCreateDirectoryStructure(ByVal strPath As String)
   
    Dim arrPath
    Dim n As Integer
    Dim strCurrentPath
    Dim strLastParent
    Dim strLeft
   
    'If they have supplied "root\" in the start of the string, strip this out
    If Len(strPath) > 5 Then
        strLeft = Left(strPath, 5)
        If UCase(strLeft) = "ROOT\" Then
            strPath = Right(strPath, Len(strPath) - 5)
        End If
    End If
   
    arrPath = Split(strPath, "\")
   
    strCurrentPath = "Root"
    strLastParent = "Root"
   
    'Create the directory
    For n = 0 To UBound(arrPath)
        'Update the current path value
        strCurrentPath = strCurrentPath & "\" & arrPath(n)
       
        'If the folder does not exist, create it
        If Not TestLabDoesFolderExist(strCurrentPath) Then
            Call TestLabCreateTestSetFolder(strLastParent, arrPath(n))
        End If
        'Update last parent
        strLastParent = strLastParent & "\" & arrPath(n)
    Next n
End Sub

----------------------------------------------------------------------
Public Function TestLabCreateTestSetFolder(ByVal strParentPath As String, ByVal strFolderName As String)
   
    If strFolderName = "" Then
        TestLabCreateTestSetFolder = False
        Exit Function
    End If
   
    'Add test set folder.
    Dim TestSetF As TestSetTreeManager
    Dim objParent As TestSetFolder
    Dim folder As TestSetFolder
   
       
    Set TestSetF = tdc.TestSetTreeManager
    Set objParent = TestLabGetFolderByPath(strParentPath)
    Set folder = objParent.AddNode(strFolderName)
    folder.Post
   
    If Err = 0 Then
        TestLabCreateTestSetFolder = True
    Else
        MsgBox Err.Description
        TestLabCreateTestSetFolder = False
    End If
       
End Function

-----------------------------------------------------------------------

Public Function TestLabDoesFolderExist(ByVal strPath As String)
   
    On Error Resume Next
    Dim tstSetFolder As TestSetFolder
    Dim testSetFolderF As TestSetTreeManager
    Dim objCurrentFolder As TestSetFolder
    Dim lastFolder As TestSetFolder
    Dim n
    Dim arrPath
   
    Set testSetFolderF = tdc.TestSetTreeManager
    Set lastFolder = testSetFolderF.Root
   
    'For some reason, NodeByPath is not working, but we can check it by getting the children
    arrPath = Split(strPath, "\")
   
    If UBound(arrPath) > 0 Then
        For n = 1 To UBound(arrPath)
            Set objCurrentFolder = Nothing
            Set objCurrentFolder = lastFolder.FindChildNode(arrPath(n))
            Set lastFolder = objCurrentFolder
        Next n
    End If
   
    If (objCurrentFolder Is Nothing) Then
        TestLabDoesFolderExist = False
    Else
        TestLabDoesFolderExist = True
    End If
   
   
    On Error GoTo 0
End Function

-------------------------------------------------------------
Public Function TestLabGetFolderByPath(strPath As String) As TestSetFolder
    Dim objTestTreeManager As TestSetTreeManager
    Dim objCurrentFolder As TestSetFolder
    Dim arrPath
    Dim n
   
    'Get the tree manager
    Set objTestTreeManager = tdc.TestSetTreeManager
    'Get the root object - we will search the children of this
    Set objCurrentFolder = objTestTreeManager.Root
   
    'Split out the path
    arrPath = Split(strPath, "\")
   
    'We already have the root as an object so skip element 0
    If UBound(arrPath) > 0 Then
        'Loop through the path, getting each folder as a child
        For n = 1 To UBound(arrPath)
            Set objCurrentFolder = objCurrentFolder.FindChildNode(arrPath(n))
        Next n
    End If
   
    Set TestLabGetFolderByPath = objCurrentFolder
End Function

--------------------------------------------------------------------
Public Function TestLabGetTestSet(ByVal strFolderPath As String, ByVal strTestSetName As String) As TestSet
   
    Dim tsFilter As TDFilter
    Dim tsList As IList
    Dim oTestSetFolder As TestSetFolder
    Dim aTestSet As TestSet
    Dim TSetFact As TestSetFactory
    Dim arrFolderPath() As String
   
       
    'Get the folder
    Set oTestSetFolder = TestLabGetFolderByPath(strFolderPath)
    Set TSetFact = tdc.TestSetFactory
   
    'When looking for the test sets we can use the "CY_FOLDER_ID" property. This contains the name of the parent folder
    'So we just need to extract what the name of the parent folder is
    arrFolderPath = Split(strFolderPath, "\") 'break up the paths so the parent folder is in the upper bound
    'Create the filter:
    Set tsFilter = TSetFact.Filter
    'Get a list of the test sets - this will contain all of the child test cases
    Set tsList = oTestSetFolder.FindTestSets("", False, tsFilter.Text)
   
    If Not (tsList Is Nothing) Then
        For Each aTestSet In tsList
            'Does this test set name and path match what we are looking for?
            If (UCase(aTestSet.TestSetFolder.Path) = UCase(strFolderPath)) And (UCase(aTestSet.Name) = UCase(strTestSetName)) Then
                'Return value & cleanup
                Set TestLabGetTestSet = aTestSet
                Set tsList = Nothing
                Set tsFilter = Nothing
                Set TSetFact = Nothing
                Set oTestSetFolder = Nothing
                Exit Function
            End If
        Next aTestSet
    End If

    'no matches found, return nothing
    Set TestLabGetTestSet = Nothing
    Set tsList = Nothing
    Set tsFilter = Nothing
    Set TSetFact = Nothing
    Set oTestSetFolder = Nothing
End Function


Source: http://automationandtesting.blogspot.co.uk/2011/11/treeview-for-quality-center-test-plan.html

QC OTA - Test Plan - 2

- Find Test in Test Plan
- Return a SubjectNode object for a given path in the Test Plan

Function TestPlanFindTest(ByVal strTestName As String, ByVal strFolderToSearchPath As String, ByVal SearchChildFolders As Boolean, Optional ByVal strTestType As String, Optional blnSilentMode As Boolean) As Test
   
    Dim oParentNode As SubjectNode
    Dim SubjectNodeList As List
    Dim oSubjectNode As SubjectNode
    Dim intMatchCount As Integer: intMatchCount = 0
    Dim TestFact As TestFactory
    Dim oReturnValue As Test
    Dim TestFilter As TDFilter
    Dim TestList As List
    Dim oTest As Test
    Dim blnTypedMatched As Boolean: blnTypedMatched = True
   
    Set oParentNode = TestPlanGetSubjectNode(strFolderToSearchPath)
    Set TestFact = tdc.TestFactory
   
    'If there was an error getting the parent node then exit
    If (oParentNode Is Nothing) Then
        Set TestPlanFindTest = Nothing
        Exit Function
    End If

    'See if the parent folder has any tests that match the name we are looking for
    Set TestFilter = TestFact.Filter
    TestFilter.Filter("TS_SUBJECT") = Chr(34) & oParentNode.Path & Chr(34)
    Set TestList = TestFact.NewList(TestFilter.Text)
    For Each oTest In TestList
        'Debug.Print "Test Name='" & oTest.Name & "' Test Type=" & oTest.Type
        If (UCase(oTest.Name) = UCase(strTestName)) Then
            'See if we should match the type - by default it is set to matched (true)
            If (strTestType) <> "" Then
                If (oTest.Type = strTestType) Then
                    blnTypedMatched = True
                Else
                    blnTypedMatched = False
                End If
            End If
           
            If blnTypedMatched Then
                intMatchCount = intMatchCount + 1
                Set oReturnValue = oTest
            End If
        End If
    Next
   
    'Now check to see if we wanted to search child folders? If so search them
    If SearchChildFolders Then
        'Get all the child folders of the parent folder
        Set SubjectNodeList = oParentNode.FindChildren("", False, "")
        If Not (SubjectNodeList Is Nothing) Then
            For Each oSubjectNode In SubjectNodeList
                'Debug.Print oSubjectNode.Path
                Set TestFilter = TestFact.Filter
                TestFilter.Filter("TS_SUBJECT") = Chr(34) & oSubjectNode.Path & Chr(34)
                Set TestList = TestFact.NewList(TestFilter.Text)
                For Each oTest In TestList
                    'Debug.Print "Test Name='" & oTest.Name & "' Test Type=" & oTest.Type
                    If (UCase(oTest.Name) = UCase(strTestName)) Then
                        'See if we should match the type - by default it is set to matched (true)
                        If (strTestType) <> "" Then
                            If (oTest.Type = strTestType) Then
                                blnTypedMatched = True
                            Else
                                blnTypedMatched = False
                            End If
                        End If
                       
                        If blnTypedMatched Then
                            intMatchCount = intMatchCount + 1
                            Set oReturnValue = oTest
                        End If
                    End If
                Next
            Next
        End If
    End If
   
   
    'Clean Up
    Set oParentNode = Nothing
    Set SubjectNodeList = Nothing
    Set oSubjectNode = Nothing
    Set TestFact = Nothing
    Set TestFilter = Nothing
    Set TestList = Nothing
    Set oTest = Nothing
   
   
    'Now return a value
    Select Case intMatchCount
        Case 0
            If Not blnSilentMode Then
                MsgBox "Error: The Test could not be found with the parameters: " & Chr(10) & _
                    "Test Name:" & strTestName & Chr(10) & _
                    "Parent Folder Path:" & strFolderToSearchPath & Chr(10) & _
                    "Test Type:" & strTestType & Chr(10) & _
                    "Search child folders?:" & SearchChildFolders, vbExclamation + vbOKOnly, "TestPlanFindTest"
            End If
            Set TestPlanFindTest = Nothing
        Case 1
            Set TestPlanFindTest = oReturnValue
        Case Else
            If Not blnSilentMode Then
                MsgBox "Error: A total of " & intMatchCount & " tests were found with the following criteria: " & Chr(10) & _
                    "Test Name:" & strTestName & Chr(10) & _
                    "Parent Folder Path:" & strFolderToSearchPath & Chr(10) & _
                    "Test Type:" & strTestType & Chr(10) & _
                    "Search child folders?:" & SearchChildFolders, vbExclamation + vbOKOnly, "TestPlanFindTest"
            End If
            Set TestPlanFindTest = Nothing
    End Select

End Function
------------------------------------------------------------------------------------------------
Function TestPlanGetSubjectNode(ByVal strPath As String) As SubjectNode
    Dim TreeMgr As TreeManager
    Dim SubjRoot As SubjectNode
    Dim SubjectNodeList As List
    Dim oSubjectNode As SubjectNode
   
   
    Set TreeMgr = tdc.TreeManager
    Set SubjRoot = TreeMgr.TreeRoot("Subject")
   
    'Trim any trailing \
    If Right(strPath, 1) = "\" Then strPath = Left(strPath, Len(strPath) - 1)
   
    If UCase(strPath) = "SUBJECT" Then
        Set TestPlanGetSubjectNode = SubjRoot
        Set TreeMgr = Nothing
        Set SubjRoot = Nothing
        Exit Function
    End If
   
   
    Set SubjectNodeList = SubjRoot.FindChildren("", False, "")
   
    For Each oSubjectNode In SubjectNodeList
        If UCase(oSubjectNode.Path) = UCase(strPath) Then
            Set TestPlanGetSubjectNode = oSubjectNode
            Exit Function
        End If
    Next
   
    MsgBox "Test Plan path not found: " & strPath, vbExclamation + vbOKOnly, "TestPlanGetSubjectNode Error"
    Set TestPlanGetSubjectNode = Nothing
    Set TreeMgr = Nothing
    Set SubjRoot = Nothing
    Set SubjectNodeList = Nothing
    Set oSubjectNode = Nothing
End Function
---------------------------------------------------------------------------------

QC OTA - Test Plan - 1


Here are some amazing functions that can be reused wrt QC OTA for Test Plan module:
- Copy paste within Test Plan
- Create folder structure within Test Plan
- Does a particular path exist in Test Plan
- Does a [particular test exist in Test Plan

Function TestPlanCopyPasteTest(strSourceFolderPath, strDestFolderPath, strSourceTestName, strNewTestName) As Boolean
'Copy a test, including design steps and parameters.
' For example:
' CopyPasteTest "Subject\TestFolder1", "Subject\TestFolder2", "Test1"
' Copies Test1 to TestFolder2

Dim sourceFolder As SubjectNode
Dim destFolder As SubjectNode
Dim treeMng As TreeManager
Dim iscp As ISupportCopyPaste
Dim clipboard As String
Dim oSourceTest As Test
Dim oNewTest As Test

'Check that the source file exists
If Not TestPlanDoesTestExist(strSourceTestName, strSourceFolderPath, False, "") Then
TestPlanCopyPasteTest = False
MsgBox "Source test does not exist: " & strSourceFolderPath & "\" & strSourceTestName, vbExclamation + vbOKOnly, "TestPlanCopyPasteTest"
Exit Function
End If

'Check that the destination test does not exist
If TestPlanDoesTestExist(strNewTestName, strDestFolderPath, False, "") Then
TestPlanCopyPasteTest = False
MsgBox "Destination test already exists: " & strDestFolderPath & "\" & strNewTestName, vbExclamation + vbOKOnly, "TestPlanCopyPasteTest"
Exit Function
End If

'On Error GoTo errCondition

Set sourceFolder = TestPlanGetSubjectNode(strSourceFolderPath)
Set testF = sourceFolder.TestFactory
' Find the test ID.
Set oSourceTest = TestPlanFindTest(strSourceTestName, strSourceFolderPath, False, "", True)
' Copy the source test.
Set iscp = testF
clipboard = iscp.CopyToClipBoard(oSourceTest.ID, 0, "")

' Paste the test in the destination folder.
Set destFolder = TestPlanGetSubjectNode(strDestFolderPath)
Set testF = destFolder.TestFactory
Set iscp = testF
iscp.PasteFromClipBoard clipboard, destFolder.NodeID

'Now it's pasted, rename it
'Reboot the QC connection as we get some failures around this point
Call RebootQCCon
Set oNewTest = TestPlanFindTest(strSourceTestName, strDestFolderPath, False, "")
oNewTest.Name = strNewTestName
oNewTest.Post

' Clean up.
Set iscp = Nothing
Set treeMng = Nothing
Set sourceFolder = Nothing
Set destFolder = Nothing
Set oNewTest = Nothing
Set oSourceTest = Nothing

TestPlanCopyPasteTest = True
Exit Function

errCondition:
MsgBox "Error: " & Err.Description, vbExclamation + vbOKOnly, "TestPlanCopyPasteTest"
TestPlanCopyPasteTest = False
End Function



-----------------------------------------------------


Sub TestPlanCreateFolderStructure(strFullPath)
Dim arrFolders() As String
Dim n As Integer
Dim strParentPath As String
Dim strThisPath As String
Dim oParentFolder As SubjectNode

'First of all, does the folder structure already exist?
If TestPlanDoesPathExist(strFullPath) Then Exit Sub

'Now split the path up into its individual folders
arrFolders = Split(strFullPath, "\")

'does the first element contain subject? if not, exit
If UCase(arrFolders(0)) <> "SUBJECT" Then
MsgBox "Error: The first element in the folder path must be 'Subject'", vbExclamation + vbOKOnly, "TestPlanCreateFolderStructure"
Exit Sub
End If

'iterate the array
For n = 0 To UBound(arrFolders)
'Create the folder if it doesn't exist
If strParentPath <> "" Then
strThisPath = strParentPath & "\" & arrFolders(n)
Debug.Print "strThisPath=" & strThisPath
'Does this path exist? If not we need to create it
If (TestPlanDoesPathExist(strThisPath) = False) And (arrFolders(n) <> "") Then
'Create it
'Get the parent folder
Set oParentFolder = TestPlanGetSubjectNode(strParentPath)
'Create this folder underneath it
oParentFolder.AddNode (arrFolders(n))
End If
End If

'before we move on, set the parent path
If strParentPath = "" Then
strParentPath = "Subject"
Else
strParentPath = strThisPath
End If
Next n

'Release all objects
Set oParentFolder = Nothing
End Sub

-------------------------------------------------------
Function TestPlanDoesPathExist(ByVal strPath As String) As Boolean
Dim TreeMgr As TreeManager
Dim SubjRoot As SubjectNode
Dim SubjectNodeList As List
Dim oSubjectNode As SubjectNode


Set TreeMgr = tdc.TreeManager
Set SubjRoot = TreeMgr.TreeRoot("Subject")

If UCase(strPath) = "SUBJECT" Then
TestPlanDoesPathExist = True
Exit Function
End If

Set SubjectNodeList = SubjRoot.FindChildren("", False, "")

For Each oSubjectNode In SubjectNodeList
If UCase(oSubjectNode.Path) = UCase(strPath) Then
TestPlanDoesPathExist = True
Set TreeMgr = Nothing
Set SubjRoot = Nothing
Set SubjectNodeList = Nothing
Set oSubjectNode = Nothing
Exit Function
End If
Next

TestPlanDoesPathExist = False
Set TreeMgr = Nothing
Set SubjRoot = Nothing
Set SubjectNodeList = Nothing
Set oSubjectNode = Nothing
End Function

----------------------------------------------------
Function TestPlanDoesTestExist(ByVal strTestName As String, ByVal strFolderToSearchPath As String, ByVal SearchChildFolders As Boolean, Optional ByVal strTestType As String) As Boolean
Dim oTempTest As Test

Set oTempTest = TestPlanFindTest(strTestName, strFolderToSearchPath, SearchChildFolders, strTestType, True)

If (oTempTest Is Nothing) Then
TestPlanDoesTestExist = False
Else
TestPlanDoesTestExist = True
End If

Set oTempTest = Nothing
End Function


---------------------------------------------------

Monday

Read Registry on remote machines VbScript

 

Here is a simple code to read any part of the registry from any machine , provided you have admin rights on the target machine:
  1. Const HKEY_LOCAL_MACHINE = &H80000002
  2. Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "Machine Name" & "\root\default:StdRegProv")
  3. strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
  4. strValueName = "BU"
  5. oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  6. msgbox strValue
Modify the strKeyPath and the strValueName and you can read any value in the registry!

Friday

Agile Adoption wrt Automation


  • The practice of Refactoring code changes the structure (i.e., the design) of the code while maintaining its behavior
  • Costs are reduced because continuous refactoring keeps the design from degrading over time, ensuring that the code is easy to understand, maintain, and change.
Automated Acceptance Tests
  • Automated acceptance tests are tests written at the beginning of the iteration that answer the question: “what will this requirement look like when it is done?”. This means that you start with failing tests at the beginning of each iteration and a requirement is only done when that test passes.
  • This practice builds a regression suite of tests in an incremental manner and catches errors, miscommunications, and ambiguities very early on. This, in turn, reduces the amount of work that is thrown away and therefore enables building less. The tests also catch bugs and act as a safety-net during change.
Best Practices
  • More up front position of the test team
    • Realistic time for test design
    • More visibility in ‘chain’ (design-develop-test-pilot)
  • Simple test designs
  • Early test execution
  •  If Nothing to test
    • Testable items arrived near the end of the iteration
    • Shorten feedback loop
  • Raise priority / allocate more time for tool support
Providing Test Interfaces
  • Developers are responsible for providing the fixtures that automate coaching tests
  • Testers work with developers to understand the system and to provide feedback
  • Tiny little unit tests
Continous Integration in an Agile Project
  • Automate the build and processes around it
  • Test on lacal builds befor checking in code
  • Prioritize tests that should be automated
  • Leverage on Open souce tools like - TestNG , Selenium IDE/RC, SoapUI, Jmeter, BadBoy, Fitnesse etc..
  • Add an automation iteration into the release.
  • A feature is not done till it works and there is an automated test to validate that completion.
  • Create a position of an automation architect, someone who is responsible for the overall automation framework.
Happy Testing!

Tuesday

AutoIt Scripting Language and SDK - Part Three

Understanding – Scripting Style – X control

  • The ActiveX control or dll’s can provide a extended support to the other scripting languages with the features AutoIt provides.
  • An example Notepad automation VBScript is shown here. –
    • Example WSH Script (VBScript)
    • Require Variants to be declared before used
    • Option Explicit
    • ' Declare Variables & Objects
    • Dim oShell
    • Dim oAutoIt
    • ' Initialise Variables & Objects
    • Set oShell = WScript.CreateObject("WScript.Shell“)
    • Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    • ' Start of Script
    • WScript.Echo "This script will run notepad and type in some text"
    • oShell.Run "notepad.exe", 1, FALSE
    • ' Wait for the Notepad window to become active
    • oAutoIt.WinWaitActive "Untitled - Notepad", ""
    • ' Send some keystokes to notepad
    • oAutoIt.Send "Hello, this is line 1{ENTER}“
    • oAutoIt.Send "This is line 2{ENTER}This is line 3“
    • oAutoIt.Sleep 1000
    • oAutoIt.Send "!{F4}“
    • oAutoIt.WinWaitActive "Notepad", "save the changes?“
    • oAutoIt.Send "!n“
    • oAutoIt.WinWaitClose "Untitled - Notepad", "“
    • WScript.Quit
Understanding - Usability of the tool/Script
  • It’s a Development tool that can be used as a test automation tool.
  • It’s free.
  • Good support available in the forum and in the documentations.
  • System load is very low. Features like taking snapshot’s are easy.
  • Data driven testing is also possible with custom build code for database, excel or test files.
  • We can build GUI through script to maintain the Test.
  • The power of regular expression can enhance the script capacity.
  • Web based testing also possible but need some time and work.It is recommended to use selenium and AutoIt as a combination to create a complete test infrastructure for web and windows.
Some points to remember -
  • Scripting language with BASIC-like structure for Windows Desktop Environment.
  • Add-on libraries and modules for specific applications.
  • On-line support forum for AutoIt users and developers.
  • Supports TCP and UDP protocols.
  • Supports COM (component object modeling) objects.
  • Call functions in Win32 DLLs.
  • Run console applications and access the standard streams.
  • Include files in the compiled file to be extracted when run.
  • GUI interfaces, create message and input boxes.
  • Play sounds, pause, resume, stop, seek, get the current position of the sound and get the length of the sound.
  • Simulate mouse movements.
  • Manipulate windows and processes.
  • Automate sending user input and keystrokes to applications, as well as to individual controls within an application.
  • Scripts can be compiled into standalone executables.
  • Unicode support from version 3.2.4.0.
  • 64 bit code support from version 3.2.10.0.
  • Supports regular expressions.
  • Works with Windows Vista's User Account Control.
Comparison with other automation tools –



AutoIt Scripting Language and SDK - Part Two


Understanding – SciTE Editor
  •  SciTE is a cross-platform text editor. Lightweight and built for speed, it is designed mainly for source editing, and performs syntax highlighting and inline function reference for many different languages.
  • The editor comes with the package with the AutoIt command auto complete feature. Which makes scripting easy.
  • It can compile, build and run the scripts.
Understanding – Scripting Style
  • C like import facility. –
    • #include "[path\]filename“, #include , #include-once
  • Variables starts with ‘$’ sign –
    • $Mid="M1009944“
  • Commenting – ‘;’
    • ;This is a comment
  • Looping
  • Regular Expressions
Understanding – Scripting Style -GUI
  •  Any GUI script will need to #include for basic GUI related constants. For advanced controls we need to add additional files.
  • Lets create a window :-
    • We can call it “Hello World”. It will be a window of 200 by 100 pixels in size.
    • Remember : When a new window is created it is hidden - so we must "show" it.
  • Code : -
    • #include
    • GUICreate("Hello World", 200, 100)
    • GUISetState(@SW_SHOW)
    • Sleep(2000) ; and we are ready to execute
  • There are two basic GUI modes: MessageLoop mode and OnEvent mode. The modes are simply two different ways of reacting to GUI events.
    • MessageLoop mode :
      • This mode is best for GUIs where the GUI is "king" and all you care about is waiting for user events.
      • Tight Loop.
      • When an event has occurred the return value of the GUIGetMsg function will show the details.
      • E.g. a button is clicked, the GUI has been closed, etc.
      • In this mode you will only receive events while you are actively polling the GUIGetMsg function so you must ensure that you call it many times a second otherwise your GUI will be unresponsive.
      • By default this mode is active.
    • OnEvent Mode :
      • This mode is best for GUIs where the GUI is of secondary importance and your script has other tasks to perform in addition to looking after the GUI.
      • This mode is similar to the Visual Basic forms method.
      • Halt – execute
      • Instead of constantly polling the GUI to find out if anything has happened we make the GUI temporarily pause the main script and call a pre-defined function to handle the event.
      • E.g. If the user clicks Button1 the GUI halts your main script and calls a previously defined user function that deals with Button1. When the function call is completed the main script is resumed.
      • To switch to this mode “Opt("GUIOnEventMode", 1)” need to be introduced in the script.

AutoIt Scripting Language and SDK - Part One



Definition – What is AutoIt ?

  •  AutoIt is a freeware automation language for Microsoft Windows. In its earliest release, the software was primarily intended to create automation scripts (sometimes called macros) for Microsoft Windows programs but has since grown to include enhancements in both programming language design and overall functionality.
  • AutoIt is a language made for automating the functionalities under Microsoft windows to automate repetitive tasks. E.g. Installation/Un-installation of software, monitoring and triggering batch jobs and tasks, and repetitive test case executions.
History
  •  Developer(s) : Jonathan Bennett & AutoIt Team
  • Stable release : 3.3.0.0 / December 24th, 2008
  • lPreview release : 3.3.1.1 / June 14th, 2009
  • Operating system : Microsoft Windows 95, 98, ME, NT4, 2000, XP, 2003 and Vista (however, support for operating systems older than Windows 2000 was discontinued with the release of v3.3.0)
  • Type : GUI Scripting language Automation
  • License : Freeware
  • Website : www.autoitscript.com/autoit3/
Understanding - Tool
  • The AutoIt tool package can be executable or non-executable(.zip).
  • The package mostly contains 3 component –
    • AutoIt3.exe – The compiler
    • Au3Info.exe – The free object spy[ similar to QTP object spy]
    • Aut2exe.exe – Script to executable converter
  • All 3 of them have 64 bit version for 64 bit systems.
  • The package also contains –
    • Exe2Aut.exe – The De-compiler
    • sqlite3.exe – Free SQL database support
    • AutoItV2toV3.exe – Converter for old AutoIt v2 scripts.
    • AutoIt3Help.exe – A unified help file containing standard AutoIt help and user defined function library help.
  • AutoItX – AutoItX is a DLL version of AutoIt v3 that provides a subset of the features of AutoIt via an ActiveX/COM and DLL interface.
  • Works with VB, VBScript, Delphi, C, C++, Kixtart, and most other languages that support the use of DLLs.
  • Examples – A folder containing examples.
  • Include – A folder contains pre-written functions for use in your AutoIt scripts.