Tuesday 15 November 2011

Treeview for Quality Center Test Plan Using OTA & OTA Code Examples

I've uploaded a spreasheet containing examples of how to interact with the Quality Center OTA Test Plan and Test Lab Modules. 

You can download the spreadsheet here.

The examples attached to the buttons show a tree view selection dialog for the Test Plan. 


   



















The VBA Code Included also has examples for other OTA interactions as follows: 
Test Plan (QCTestPlanCommonFunctions)   
  • TestPlanCopyPasteTest - Uses OTA to copy a Test Case in the Test Plan.
  • TestPlanCreateFolderStructure - Uses OTA to create a folder structure in the Test Plan.  
  • TestPlanDoesPathExist - Uses OTA to return True / False if a directory / path exists in the Test Plan  
  • TestPlanDoesTestExist - Uses OTA to return True / False if a test exists in the Test Plan.   
  • TestPlanFindTest - Uses OTA to return a test for a given path and/or it's subfolders   
  • TestPlanGetSubjectNode - Uses OTA to return a Folder as a Subject Node object  
Test Lab(QCTestLabCommonFunctions)   
  • TestLabAddTestToTestSet - Uses OTA to add a test to a test set in the test lab.
  • TestLabCreateDirectoryStructure - Uses OTA to create a directory structure in the test lab  
  • TestLabCreateTestSet - Uses OTA to create a test set in a directory  
  • TestLabDoesFolderExist - Uses OTA to Returns True / False as to whether a folder exists  
  • TestLabGetFolderByPath - Uses OTA to returns a TestSetFolder object for a given path  
  • TestLabGetTestSet - Uses OTA to return a TestSet for a given path  
    
A couple of things:    
  • This code can sometimes fail after being run several times. I can't find the reason why, but usually closing Excel and reopening it fixes the issues.    
  • In your code, if you have a loop that creates a folder and then uses "TestLabGetFolderByPath" to find it, you may find it fails. Inserting a call to the function "RebootQCCon" resolves this.    

Friday 4 November 2011

Quality Center OTA: List all Tests in the Test Plan

The code below is a simple way to show all of the Folders and Tests in the Quality Center test plan. You could use this as a basis to develop a treeview of the testplan in another tool.

This code is designed to be run from Excel VBA, but you can easily adapt it for VBScript. It assumes that you have already connected to Quality Center which is represented by the "tdc" variable in the code.

This should help anyone having problems with the error "Field < Subject > requires a value from the corresponding list" - the answer to this problem is to encapsulate the subject with quotes - shown below with chr(34) wrapped around TS_Subject. It took me 2 hours to resolve that issue, no thanks to the OTA documentation!!

Sub ExploreTestPlan()
   
    Dim TreeMgr As TreeManager
    Dim SubjRoot As SubjectNode
    Dim TestFact As TestFactory
    Dim TestFilter As TDFilter
    Dim TestList As List
    Dim oTest As Test
    Dim SubjectNodeList As List
    Dim oSubjectNode As SubjectNode
   
    '*** make sure you have connected to QC with the tdc object ***


    Set TreeMgr = tdc.TreeManager
    Set SubjRoot = TreeMgr.TreeRoot("Subject")
    Set TestFact = tdc.TestFactory
    Set SubjectNodeList = SubjRoot.FindChildren("", False, "")
   
    For Each oSubjectNode In SubjectNodeList
        'Print out the subject path
        Debug.Print oSubjectNode.Path
       
        'Does this have any tests?
        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
        Next
       
    Next
   
End Sub

Sunday 12 June 2011

Integrating TestPartner with Quality Center

It’s possible to integrate TestPartner tests with the Quality Center test lab and execute the tests locally on a machine. In order to do this, the following issues need to be addressed:
  •  A “VAPI-XP-TEST” needs to be setup in Quality Center. This acts as a placeholder for the TestPartner Test.
  •  The VAPI test needs to be executed from the QC test lab and actually launch the test in TestPartner on the local machine.
  • After the test has run we need to be able to analyse the results and determine the overall run status so that we can update the Quality Center test lab with a “Passed” or “Failed” status.
  • After analysing the results, we need to attach them to the Quality Center test lab, so that any testers investigating the reasons for failure can look into potential problems.
Before you start, download the “Test Partner Results Extractor.xls” file to the machine where you need to execute the tests on. This component is required to perform the results analysis after executing the test, and is explained later on. For the purpose of this example I recommend you create a directory and download the file to "C:\TestPartner\".


So here's how you do it.....


1)  Setting up the VAPI-XP-TEST
 
- Go to the Quality Center Test Plan

- Select Tests > New Test and choose these settings (note: you must give the VAPI test the same name as your TestPartner TestScript / Visual Test).


- Press Ok. 

- If there are any mandatory QC fields, fill them in.

- In the VAPI wizard, choose these settings:


- Click on Finish.

- Now select the test from the test lab, and click on the “Test Script” tab.

- Paste the following code into the Test Script:


' ====================================================
' VAPITest01 [VBScript]
' Created by David Hartley
' 01/06/2011 16:34:25
' ====================================================

' ----------------------------------------------------
' Main Test Function
' Debug - Boolean. Equals to false if running in [Test Mode] : reporting to Quality Center
' CurrentTestSet - [OTA COM Library].TestSet.
' CurrentTSTest - [OTA COM Library].TSTest.
' CurrentRun - [OTA COM Library].Run.
' ----------------------------------------------------
Sub Test_Main(Debug, CurrentTestSet, CurrentTSTest, CurrentRun)
 
  ' clear output window
  TDOutput.Clear

  '***************** VARIABLES TO BE MODIFIED **************************
  Dim strTPDatabase : strTPDatabase = "Test Partner"
  Dim strTPUsername : strTPUsername = "David Hartley"
  Dim strTPPassword : strTPPassword = "pass"
  Dim strTPProject : strTPProject = "Common"
  'Test Name - this code can launch a Visual Test or a Test Script. Only fill in the test name
  'for the type of test you are launching, e.g if it's a visual test then leave strTPTestScriptName blank
  Dim strTPTestScriptName : strTPTestScriptName = ""
  Dim strTPVisualTestName : strTPVisualTestName = CurrentTSTest.TestName
  Dim strTestPartnerResultsExtractorName : strTestPartnerResultsExtractorName = "Test Partner Results Extractor.xls"
  Dim strResultsDirectory :  strResultsDirectory = "C:\TestPartner\"
  '***********************************************************************************************

  Dim WshShell, objExecObject, strOutput
  Dim strCommand, strTestTypeCommand, strRes
  Dim strTestName
  'Now setup some variables to handle to test results
  Dim strMacroName : strMacroName = "ExtractResultsFromTP"
  Dim strExpectedExcelResultsPath
  Dim strTimeStamp
  Dim strTemp
  Dim objExcel, objExcelWorkbook

  'setup the timestamp in YYYYMMDD_HHMM format
  'get the year
  strTimeStamp = year(now())
  'get the month
  strTemp = month(now())
  if len(strTemp) = 1 then strTemp = "0" & strTemp
  strTimeStamp = strTimeStamp & strTemp
  'get the day
  strTemp = day(now())
  if len(strTemp) = 1 then strTemp = "0" & strTemp
  strTimeStamp = strTimeStamp & strTemp & "_"
  'get the hour
  strTemp = hour(now())
  if len(strTemp) = 1 then strTemp = "0" & strTemp
  strTimeStamp = strTimeStamp & strTemp
  'get the minute
  strTemp = minute(now())
  if len(strTemp) = 1 then strTemp = "0" & strTemp
  strTimeStamp = strTimeStamp & strTemp
  'get the seconds
  strTemp = second(now())
  if len(strTemp) = 1 then strTemp = "0" & strTemp
  strTimeStamp = strTimeStamp & strTemp

  'setup testname variable
  if strTPTestScriptName <> "" then
     strTestName = strTPTestScriptName
  else
     strTestName = strTPVisualTestName
  end if

  'Now we can setup the expected excel results path
  strExpectedExcelResultsPath = strResultsDirectory & strTestName & " Results " & strTimeStamp & ".xls"

  'Now start setting up variables used to send the command
  if strTPTestScriptName <> "" then
      strTestTypeCommand = """ -s """ & strTPTestScriptName &  """"
  else
      strTestTypeCommand = """ -t """ & strTPVisualTestName &  """"
  end if

  'create a windows shell object
  Set WshShell = CreateObject("WScript.Shell")
  'construct the command we want to send to it
  strCommand = "TP -d """ & strTPDatabase &  """ -u """ & strTPUsername &  """ -p """ & strTPPassword &  """ -r """ & strTPProject &  strTestTypeCommand
  'this is useful for debug purposes
  TDOutput.Print "Launching TP with this command:"
  TDOutput.Print strCommand
  'Now run the command which will launch TestPartner - if nothing happens, put the command into a
  'command prompt window (start > run > "cmd") to see if there are any errors from it

  Set objExecObject = WshShell.Exec(strCommand)
  strOutput = objExecObject.StdOut.readall()
  if strOutput <> "" then
     TDOutput.Print strOutput
     'if this was a visual test, then this outputs a playback error but we can still go on to retrieve the results
     if instr(strOutput, "Playback error") <= 0 then
          If Not Debug Then
             TDOutput.Print "Test Failed to launch"
             CurrentRun.Status = "Failed"
             CurrentTSTest.Status = "Failed"
          end if
          exit sub
     end if
  end if

  'if we reach here then the test ran correctly, we can now go and retrieve the results using the excel workbook
  Set objExcel = CreateObject("Excel.Application")
  'objExcel.visible = true 'show excel *** Uncomment this if you want to see what is happening ***
  'open the extractor workbook - this will do the donkey work of retrieving the results
  TDOutput.Print "Opening " & strResultsDirectory & strTestPartnerResultsExtractorName
  set objExcelWorkbook = objExcel.Workbooks.Open(strResultsDirectory & strTestPartnerResultsExtractorName,false,true)'opens it readonly
  'now setup the variables on the config sheet
  objExcelWorkbook.sheets("config").select
  'setup the variables
  objExcelWorkbook.sheets("config").cells(1,2) = strTPDatabase
  objExcelWorkbook.sheets("config").cells(2,2) = strTPUsername
  objExcelWorkbook.sheets("config").cells(3,2) = strTPPassword
  objExcelWorkbook.sheets("config").cells(4,2) = strTPProject
  objExcelWorkbook.sheets("config").cells(5,2) = strTestName
  objExcelWorkbook.sheets("config").cells(6,2) = strTimeStamp
  objExcelWorkbook.sheets("config").cells(7,2) = strResultsDirectory

  'now run the macro to generate the results (this causes VAPI to crash so wrap error handling around it)
  TDOutput.Print "Retrieving results"
  on error resume next
  objExcel.run strMacroName
  on error goto 0

  'if we're not in debug mode then open the results and determine the pass/fail status
  If Not Debug Then
     TDOutput.Print "Opening results worksheet: " & strExpectedExcelResultsPath
     'now open the results worksheet to determine the pass/fail status
     set objExcelWorkbook = objExcel.Workbooks.Open(strExpectedExcelResultsPath,false,true)'opens it readonly
     'what is the overall status of the results (this is calculated by the Excel Workbook)?
     if objExcelWorkbook.sheets("Results").cells(1,5) = "Pass" then
        TDOutput.Print "Test passed"
        CurrentRun.Status = "Passed"
        CurrentTSTest.Status = "Passed"
     else
        TDOutput.Print "Test Failed"
        CurrentRun.Status = "Failed"
        CurrentTSTest.Status = "Failed"
     end if
     objExcelWorkbook.saved = true
     objExcelWorkbook.close

    'now upload the workbook results to the curentRun - this means
    'that when you double click the results in QC you will see this as an
    'attachment
    TDOutput.Print "Uploading results from: " & strExpectedExcelResultsPath
    set attachF = CurrentRun.Attachments
    Set theAttachment = attachF.AddItem(null)
    theAttachment.FileName = strExpectedExcelResultsPath
    theAttachment.Type = 1
    theAttachment.Post

  end if

  objExcel.quit
  set objExcelWorkbook = nothing
  set objExcel = nothing
  TDOutput.Print "Finished"
End Sub
' ====================================================

 

- Now you need to configure the variables specific to the test. In the header, change these variables:

   strTPDatabase – The name of the database to connect TP to.

   strTPUsername – A username that can execute the test.

   strTPPassword – password for that username.

   strTPProject – The name of the project where the test is saved in.

   strTPTestScriptName – If the test is a TestScript, set this value to “CurrentTSTest.TestName”, otherwise set the value to blank “”.

   strTPVisualTestName– If the test is a Visual Test, set this value to “CurrentTSTest.TestName”, otherwise set the value to blank “”.

   strTestPartnerResultsExtractorName - The name of the excel tool that analyses the results, the default value is "Test Partner Results Extractor.xls".

   strResultsDirectory – A location on the machine where the results will be saved to. The excel tool (strTestPartnerResultsExtractorName) must also be placed in this directory. You must include a “\” character at the end of the path name.



2)  Executing from Quality Center

Now the VAPI test has been setup, you can execute the test from Quality Center. Create a test lab and select the VAPI test. To run it, use the run button – you can only run it on the local machine (so check the “Run All Tests Locally” box).


Whilst it’s running, the Output dialog should display some useful messages. The script works by sending a shell command to invoke TestPartner: “TP –d [database] –u [username] –p [password] –r [project] –t (or –s) [testname]”




3)  Analysing Results and Attaching them to Quality Center

Once the test has been run, the VAPI test then invokes Excel and loads the “Test Partner Results Extractor.xls” spreadsheet. This spreadsheet contains a macro which will go and retrieve the test results, export them to an XML file and then import the XML into an Excel workbook, which is saved to the local drive. This happens silently in the background.

Once the results have been opened in Excel, the Excel code parses the results columns and determines if the run has passed or failed, which the VAPI code then uses to set the pass or failed status in Quality Center.

The VAPI code then takes the saved results workbook and attaches it to the Quality Center Test Set results so that you can see the run results and reasons for the pass / fail status. In the screenshot below you can see a green paperclip in the attachments – this is where you can find the results.


 Clicking the paperclip takes you to the excel file containing the results.



So that explains how to launch Test Partner tests from Quality Center, obtain a passed/failed status and have the results uploaded to Quality Center. There are a few things to consider with this approach:
  • The tests can only be executed locally on the machine.
  • The results are in Excel format – this means that screenshots are not included so you may still need to go into TestPartner to investigate the results.
  • Sometimes QC doesn’t save the changes you’ve made to your VAPI script – to check if it has, load another VAPI script and then load your script to see if the changes have been applied.
  • If TestPartner fails to launch the test (check your parameters have been setup, especially the test type), then there will not be any attachments in Quality Center – simply a Failed status.

A big thanks to this article that helped me develop the Excel tool featured in this example.






Wednesday 6 April 2011

Installing Quality Center 11 on Windows 2008 (Virtual PC)

Have you ever wanted to try out Quality Center but not had a server to install it on? Well Microsoft have released a pre-configured virtual PC for Windows server 2008 which has a 30 day trial (the same as Quality Center). So providing your machine is capable of running Virtual PC's then that's pretty much all you need in order to trial Quality Center and it's features. This is great if like me, you wish to play round with Quality Center at home or test out Quality Center upgrades.

So before you jump in, you'll need to download the following:
  1. Microsoft Virtual PC to run the server (free).
  2. Windows server 2008 virtual pc file (free).
  3. HP Quality Center 11 download (free, but you need to register with HP)
  4. SQL Server - I chose to use SQL Server 2005 Express (also free):
    1. SQL Server 2005 Express.
    2. Microsoft SQL Server Management Studio Express.
I'm going to try and keep this short, so if you're in need of any extra information have a search for it online or drop me a question in the comments.

So here is what you need to do to install Quality Center 11 onto the Windows Server 2008 Virtual PC:
  1. Run the virtual machine.
  2. To grant the virtual machine internet access:
    • Change the virtual machine's network settings to NAT mode
    • In the virtual machine, go to the network settings and change the local network properties to use the DNS server 192.168.131.254 (see screenshot below)
  3. Install IIS on the server. I followed the steps on this page.
  4. Install SQL Server 2005 Express
  5. Install SQL Server 2005 management studio
  6. Use SQL Server 2005 management studio to change the password for the SA account.
  7. Using the SQL Server Configuration Manager, ensure that the SQL Server Browser Service is Running (I had to enable this service as it was not on by default).
  8. Install QC 11 onto the server
  9. The ALM platform configuration wizard should be self explanatory, I chose these options:
    • License key - Quality Center Enterprise Edition
    • Application Server - JBoss (if you see an option to use IIS as the webserver, choose it)
    • Database Server: see screenshot below. Note: I've renamed the server to win2008
  10. Then finish off the Wizard. I found that the JBoss service failed to launch, so there is an additional step you need to take:
    • Navigate to C:\ProgramData\HP\ALM\jboss\bin and execute the run.bat file. This will configure the jboss server for you. 
  11. Now if you open Internet Explorer on the server and navigate to http://localhost:8080/qcbin/ you should see the Quality Center splash screen - that's it, QC is setup for you!

    Tuesday 5 April 2011

    Resolved: Quality Center 11 Installation Issue "Failed to validate database parameters"

    I've been having issues trying to get Quality Center 11 installed, I kept getting the "Failed to validate database parameters" error message on the database server screen.

    The server setup was as follows:

    Windows Server 2003
    SQL Server 2005 Express

    There were a couple of things I had to do:

    1. Under the SQL Server Configuration Manager, ensure that the SQL Server Browser Service is Running (I had to enable this service as it was not on by default).
    2. The DB Host name should include the server name followed by \sqlexpress. So on my box it was set to: win2003\sqlexpress. Note: I have tried this on Windows Server 2008 and I did not need to provide \sqlexpress (although you do need to enable mixed authentication mode)
    3. Use MS-SQL Authentication - use the sa account details for the db admin and username details (you should check that you know these details first)
     Hopefully that should get you past the database page - it took me hours to get around all of this!

    Tuesday 29 March 2011

    Class Not Registered Error: QTP and Quality Center

    I've been looking at upgrading some tests from QTP 9.2 to QTP 11 with Quality Center 9.2.

    One problem I was having was trying to execute tests remotely; I kept getting the "Class Not Registered" error in Quality Center. It turns out that you need you to install the QTP 11 QC Addin on both the machine you are launching the test on, AND the machine that you are running Quality Center from.  Once the add-in was installed in both places (you can get this from the QC Help Menu and clicking through to the add-ins page) this error was resolved.....took me a while to figure it though!

    Monday 7 February 2011

    Reporting on QTP Iteration Test Results

    Using Quality Center to report on test runs works fine if you have a low number of tests or a test case to QTP test ratio of 1:1. However, if you are running multiple test iterations which all represent different test cases, then using Quality Center to keep track of test results is very difficult. Unfortunately, QTP does not yet have a built in method to let you determine the execution status of each iteration, nor does it provide a solution suitable for enterprise level automation reporting.

    The purpose of this tool is to show you how you can use excel to design a report and pull out all of the information you need to determine the test result of each iteration and report this on a scalable level.

    For the benefits of releasing something to the community, this is a very simple example. But it is possible to develop this idea further into a fully fledged Excel report that you can execute after each test iteration run, which will analyse multiple results in a very short space of time. (I currently have a version of this analysing 150 scenarios across 9 different language websites, so in excess of 1350 individual iteration results). The great thing about this is that it sits alongside Quality Center without any customisation that you need to put into your QTP code.   

    More information is included on the spreadsheet itself - so please go ahead and give it a try using the link below:

    QTP Reporting Tool - Iteration Results Viewer

    Wednesday 2 February 2011

    Resolved: QC Error: The server process could not be started because the configured identity is incorrect. Check the username and password

    If you're trying to launch QTP tests onto a Windows Server machine, you may receive the following error "The server process could not be started because the configured identity is incorrect.  Check the username and password".

    This is because QTP needs to run in session 0 within the Windows Server, which has the administrative permissions required to launch your QTP tests. If you remote desktop into the server you can see your session ID by bringing up task manager (ctrl + alt + del) and clicking on the "users" tab.

    If there is not a session 0 to connect to, then you can create one using the following command from the Start > Run menu:

    mstsc /v:<servername> /admin 

    Just replace <servername> with the name of your server e.g:

    mstsc /v:server1 /admin

    Monday 31 January 2011

    USB Devices Not Recognised on a Sony Vaio S Series

    Up until today I was loving my Sony S Series until I couldn't get it to recognise my USB Hard Drive (Western Digital Passport). After a fair bit of trial and error, I found out it wasn't just this hard drive, but all of my usb memory sticks were not being recognised.

    Update: Initially, I thought this was a hardware issue but a colleague of mine had the same issue on a Dell laptop - I think it's a windows 7 issue and it seems to happen when your laptop comes out of sleep mode. I seem to have resolved the problem by performing the following steps:

    1. Open Control Panel > Power Options
    2. Then for your current power plan, click on "Change Plan Settings" 
    3. Click on "change advanced power settings"
    4. USB Settings > USB Selective Suspend Settings > Set "On Battery" and "Plugged in" to DISABLED.
    That's it - problem should be solved.