Integrate with ALM via VAPI-XP

Supported in versions: LoadRunner Enterprise 2020 or later; ALM 15.0 or later

This section describes how to integrate ALM with LoadRunner Enterprise via VAPI-XP. This enables you to run LoadRunner Enterprise performance tests, save test results, and view reports directly from ALM.

ALM integration flow

The following diagram illustrates the integration between LoadRunner Enterprise and ALM:

 

Back to top

Prerequisites

Before you begin, you must perform the following on the ALM client machine:

  1. Download and install the TFS plugin for LoadRunner Enterprise on the machine hosting the ALM client.

    The plugin is available from: https://github.com/MicroFocus/Performance-Center-TFS-Plugin/blob/master/Extension/PC.Plugins.Installer.msi.

  2. Create a PowerShell script file.

    1. Navigate to the plugin installation folder (the default path is: C:\Program Files (x86)\Micro Focus\LoadRunner Enterprise Plugin), and create a PowerShell script file named AlmLreIntegration.ps1.

    2. Copy and paste the following text into the AlmLreIntegration.ps1 file, and enter the LoadRunner Enterprise server URL, username, and password.

      #
      # AlmLreIntegration.ps1
      #
      param([string] $varPCServer="<LRE Server URL (e.g. http://<my LRE server>/LRE/)>", [string] $varUserName="<my UserName>", [string] $varPassword="<my Password>", [string][Parameter(Mandatory=$true)] $varDomain, [string][Parameter(Mandatory=$true)] $varProject, [string][Parameter(Mandatory=$true)] $varTestID, [string] $varAutoTestInstance="true", [string] $varTestInstID="", [string] $varPostRunAction="CollateAndAnalyze", [string] $varProxyUrl="", [string] $varProxyUser="", [string] $varProxyPassword="", [string] $varTrending="DoNotTrend", [string] $varTrendReportID="", [string] $varTimeslotDuration="30", [string] $varUseVUDs="false", [string] $varUseSLAInStatus="true", [string] $varArtifactsDir="", [string] $varTimeslotRepeat="DoNotRepeat", [string] $varTimeslotRepeatDelay="1", [string] $varTimeslotRepeatAttempts="3")
      #Write-Host "+++++++++Verifying required environment variable++++++++++"
      $pcworkdir = $PSScriptRoot
      $exit_code = 0
      #Write-Host "++++++++/Verifying required environment variable++++++++++"
      $varAutomationDll = "PC.Plugins.Automation.dll"
      $varCommonDll = "PC.Plugins.Common.dll"
      $varConfiguratorDll="PC.Plugins.Configurator.dll"
      if (-Not((Test-Path -Path ("{0}\{1}" -f $pcworkdir, $varAutomationDll)) -and (Test-Path -Path ("{0}\{1}" -f $pcworkdir, $varCommonDll)) -and (Test-Path -Path ("{0}\{1}" -f $pcworkdir, $varConfiguratorDll))))
      {
      Write-Host "files not found with the extension under " $pcworkdir
      Write-Host "trying to use the files from the environment variable PC_LAUNCHER"
      $pcworkdir = $env:PC_LAUNCHER
      }
      if ((Test-Path -Path ("{0}\{1}" -f $pcworkdir, $varAutomationDll)) -and (Test-Path -Path ("{0}\{1}" -f $pcworkdir, $varCommonDll)) -and (Test-Path -Path ("{0}\{1}" -f $pcworkdir, $varConfiguratorDll)))
      {
      #Write-Host "++++++++++++loading+libraries*+++++++++++++++++++"
      $assembly = [Reflection.Assembly]::LoadFile(("{0}\{1}" -f $pcworkdir, $varAutomationDll))
      $assembly = [Reflection.Assembly]::LoadFile(("{0}\{1}" -f $pcworkdir, $varCommonDll))
      $assembly = [Reflection.Assembly]::LoadFile(("{0}\{1}" -f $pcworkdir, $varConfiguratorDll))
      #Write-Host "++++++++++++/loading+libraries*++++++++++++++++++"
      Start-Sleep -s 2
      #Write-Host "+++++++++++++executing command+++++++++++++++++++"
      $report = [PC.Plugins.Configurator.Configurator]::Perform($varPCServer, $varUserName, $varPassword, $varDomain, $varProject,
      $varTestID, $varAutoTestInstance, $varTestInstID, $varPostRunAction,
      $varProxyUrl, $varProxyUser, $varProxyPassword,
      $varTrending, $varTrendReportID, "", $varTimeslotDuration,
      $varUseSLAInStatus, $varUseVUDs, $varArtifactsDir, "", "", $varTimeslotRepeat, $varTimeslotRepeatDelay, $varTimeslotRepeatAttempts )
      #Write-Host "+++++++++++++++++Log Content+++++++++++++++++++++"
      Start-Sleep -s 2
      if($report -ne "")
      {
      Start-Sleep -s 2
      $isLogFileEnded = [PC.Plugins.Configurator.Configurator]::IsLogFileEnded($report)
      do
      {
      $isLogFileEnded = [PC.Plugins.Configurator.Configurator]::IsLogFileEnded($report)
      $newContent = [PC.Plugins.Configurator.Configurator]::GetNewContent($report)
      if($newContent -ne "")
      {
      Write-Host $newContent
      }
      Start-Sleep -s 2
      } While (-not $isLogFileEnded -and $isLogFileEnded -ne $null)
      $taskStatus = [PC.Plugins.Configurator.Configurator]::GetTaskStatus($report)
      if ($taskStatus -ne $null)
      {
      Write-Error $taskStatus
      if($taskStatus -match "SLA Status is Not Completed")
      {
      $exit_code = 2
      }
      else
      {
      $exit_code = 1
      }
      }
      foreach ($fileName in ("Reports.zip", "PC.Plugins.Automation.Logs.log")){
      $temp = Split-Path -Path $report
      $ora = Join-Path -Path $temp -ChildPath $fileName
      $temp2 = Split-Path -Path $temp
      $dest = Join-Path -Path $temp2 -ChildPath $fileName
      if (Test-Path $dest) {
      Remove-Item $dest -Force
      }
      if (Test-Path $ora) {
      Copy-Item $ora -Destination $dest -Force
      }
      }
      [PC.Plugins.Configurator.Configurator]::DeleteUnusedFilesFromArtifact($report)
      }
      }
      else
      {
      if ($pcworkdir -ne $null)
      {
      Write-Error "Assembly files not found under " $pcworkdir
      }
      else
      {
      Write-Error "Environment variable PC_LAUNCHER not set"
      }
      $exit_code = 1
      }
      #Add-Type -AssemblyName System.Windows.Forms
      #[System.Windows.Forms.MessageBox]::Show("$exit_code")
      exit $exit_code
  3. Configure ALM as described in Configure ALM and run a performance test below.

Back to top

Configure ALM and run a performance test

This task describes how to configure and run a LoadRunner Enterprise performance test from ALM via VAPI-XP.

  1. Prepare the ALM client as described in Prerequisites.

  2. Log on to ALM and select a domain and project.

  3. Navigate to the Test Plan module (under Testing, select Test Plan).

  4. Create a new VAPI-XP test based on the VAPI-XP test example below. For more about VAPI-XP test types, see VAPI-XP Tests in the ALM Help Center.

  5. Define the parameters according to your choice.

  6. Navigate to the Test Lab module (under Testing, select Test Lab).

  7. Create a new test set and add a VAPI-XP test into it. At runtime, you can provide different parameter values for each test instance that you add.
  8. Run the test set. After the test has finished running, check the status of test instance has passed in the Test Runs module (under Testing, select Test Runs).

    You can view details of the test run in the execution log (in Attachments).

  9. View test runs in the reports.

    1. A report for each test instance is uploaded to the relevant run. To see the execution report of a test set run, select the run, click the Attachments icon, and extract the contents from Reports.zip.

    2. Open the Reports.html file to display the Analysis Summary Report.

      Run status is updated based on the SLA status.

Back to top

VAPI-XP test example

In this example, the following inputs are defined as parameters at the test level and can be changed during runtime.

  • Domain. The name of the LoadRunner Enterprise domain.

  • Project. The name of the LoadRunner Enterprise project.

  • TestID. The ID of the LoadRunner Enterprise test to be executed.

For more about working with parameters, see Test Parameters in the ALM Help Center.

Example VAPI-XP test script

' vapi2 [VBScript]
' Created by Application Lifecycle Management
' 10/22/2020 12:05:23 PM
' ====================================================

' ----------------------------------------------------
' Main Test Function
' Debug - Boolean. Equals to false if running in [Test Mode] : reporting to Application Lifecycle Management
' CurrentTestSet - [OTA COM Library].TestSet.
' CurrentTSTest - [OTA COM Library].TSTest.
' CurrentRun - [OTA COM Library].Run.
' ----------------------------------------------------
Function UploadAttachment(CurrentRun, path)
	Set objRunAttach = CurrentRun.Attachments	
	Set newAtt = objRunAttach.AddItem(Null)
	newAtt.FileName = path
	newAtt.Type = 1	
	newAtt.Post
End Function

Function FileExists(FilePath)
   Set fso = CreateObject("Scripting.FileSystemObject")
   If fso.FileExists(FilePath) Then
	FileExists=CBool(1)  
   Else
	FileExists=CBool(0)	
   End If
End Function

Sub Test_Main(Debug, CurrentTestSet, CurrentTSTest, CurrentRun)
   ' *** VBScript Limitation ! ***
   ' "On Error Resume Next" statement suppresses run-time script errors.
   ' To handle run-time error in a right way, you need to put "If Err.Number <> 0 Then" 
   ' after each line of code that can cause such a run-time error.
   'On Error Resume Next


   ' clear output window
   TDOutput.Clear
   Dim strResultsDirectory :  strResultsDirectory = "C:\"
   Dim WshShell
   Set WshShell = CreateObject("WScript.Shell")
   WshShell.CurrentDirectory = strResultsDirectory
    
   Dim Domain
   Domain = CurrentTSTest.Params.ParamValue("Domain")
   Dim Project
   Project = CurrentTSTest.Params.ParamValue("Project")
   Dim TestID
   TestID = CurrentTSTest.Params.ParamValue("TestID")

   files = Array("C:\Temp\PC.Plugins.Automation.Logs\Reports.zip","C:\Temp\PC.Plugins.Automation.Logs\PC.Plugins.Automation.Logs.log")
   for each x in files
	If FileExists(x) Then
	    Set fso = CreateObject("Scripting.FileSystemObject")
	    fso.DeleteFile x
	end if
   next

   If IsNull(TestID)  Or  IsEmpty(TestID) Then
	oExec = "1"
   Else
	cmd = "powershell -file ""c:\Program Files (x86)\Micro Focus\LoadRunner Enterprise Plugin\AlmLreIntegration.ps1"" -varDomain " & Domain & " -varProject " & Project & " -varTestID " & TestID
	oExec = WshShell.Run(cmd, 7, True)
   end if
   If Not Debug Then
	for each x in files
	    If FileExists(x) Then
		UploadAttachment CurrentRun, x
	    end if
	next

	if oExec = "0" then
	    CurrentRun.Status = "Passed"
	ElseIf oExec = "1" Then
	   CurrentRun.Status = "Failed"
	else
	    CurrentRun.Status = "Not Completed"
	end if
   End If
   ' handle run-time errors
   If Err.Number <> 0 Then
	TDOutput.Print "Run-time error [" & Err.Number & "] : " & Err.Description
	' update execution status in "Test" mode
	If Not Debug Then
	End If
   End If
End Sub

Back to top