Created
July 30, 2014 18:57
-
-
Save kodiyan/89fedaa4412946baa8ef to your computer and use it in GitHub Desktop.
HP ALM Update VB Script that Run from Java Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################CallVBS.java########################################## | |
package com.resp.util; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.Properties; | |
public class CallVBS { | |
static InputStream almInput = null; | |
static String confName = null; | |
public static void updateALM( | |
String scenarioName, | |
String osVersion, | |
int imageWidth, | |
String browser, | |
String testStatus) | |
throws IOException { | |
String almPropPath = ".\\src\\test\\resources\\props\\almData.properties"; | |
almInput = new FileInputStream(almPropPath); | |
Properties almData = new Properties(); | |
almData.load(almInput); | |
if (imageWidth == 0) { | |
confName = osVersion + "_" + browser; | |
} else { | |
confName = osVersion + "_" + browser + "_" + imageWidth; | |
} | |
String testResult = ("passed".equalsIgnoreCase(testStatus) ? "Passed" : "Failed"); | |
// passing arguments to VBS File | |
System.out.println("ALM Data:- ConfName: " + confName + ", TestName: " + scenarioName + ", TestResult: " + testResult); | |
String[] parms = { | |
"C:\\Windows\\SysWOW64\\wscript.exe", | |
".\\src\\test\\resources\\AlmUpdate.vbs", | |
almData.getProperty("ALM_URL"), | |
almData.getProperty("ALM_USERNAME"), | |
almData.getProperty("ALM_PASSWORD"), | |
almData.getProperty("ALM_DOMAIN"), | |
almData.getProperty("ALM_PROJECT"), | |
almData.getProperty("Test_Set_Folder_Path"), scenarioName, | |
confName, testResult }; | |
// calling VBS with params above | |
Runtime.getRuntime().exec(parms); | |
} | |
} | |
'############################################AlmUpdate.vbs########################################## | |
Dim tdc | |
Dim runName | |
almUrl = WScript.Arguments.Item(0) | |
userName = WScript.Arguments.Item(1) | |
password = WScript.Arguments.Item(2) | |
almDoamin = WScript.Arguments.Item(3) | |
almProject = WScript.Arguments.Item(4) | |
strPath = WScript.Arguments.Item(5) | |
strSceName = WScript.Arguments.Item(6) | |
'"DummyTest_CloseLastBrowser" | |
strConName = WScript.Arguments.Item(7) | |
'"DummyTest_CloseLastBrowser_IE9" | |
strStatus = WScript.Arguments.Item(8) | |
'strStatus = "Failed" | |
Set tdc = CreateObject("TDApiOle80.TDConnection") | |
'############################################################################################################### | |
tdc.InitConnectionEx almUrl | |
tdc.Login username, password | |
tdc.Connect almDoamin, almProject | |
If (tdc.connected <> True) Then | |
'MsgBox "qc project failed to connect to " &"Project" | |
WScript.Quit | |
End If | |
Set tfact = tdc.TestSetFactory | |
Set tsTreeMgr = tdc.TestSetTreeManager | |
Set tcTreeMgr = tdc.TreeManager | |
nPath = "Root\" & Trim(strPath) | |
Set TestSetFolder = tsTreeMgr.NodeByPath(npath) | |
Set TestSetF = TestSetFolder.TestSetFactory 'Retreive test from given folder in test lab | |
Set aTestSetArray = TestSetF.NewList("") | |
tsSet_cnt=aTestSetArray.Count | |
For i=1 to tsSet_cnt ' Loop through the Test Sets to pick the desired test Set | |
Set tstests=aTestSetArray.Item(i) | |
Flag=1 | |
Set TestCaseF = tstests.TSTestFactory 'Retreive Test Cases from the test set | |
Set aTestCaseArray = TestCaseF.NewList("") | |
test_qc_cnt=aTestCaseArray.count | |
For n=1 to test_qc_cnt 'Loop through the Test cases in QC to find the same test case as in Excel | |
Set ts_obj=aTestCaseArray.item(n) | |
tname_QC=ts_obj.Test.Name | |
configname_QC = ts_obj.TestConfiguration.Name | |
If (tname_QC=strSceName) AND (configname_QC=strConName) Then | |
runName =ts_obj.RunFactory.UniqueRunName | |
Set RunF = ts_obj.RunFactory ' for managing test runs. | |
Set theRun = RunF.AddItem(runName) | |
theRun.Name =runName 'assign a run name | |
theRun.Status =strStatus 'you can parametrize this value as per your need | |
theRun.Post | |
Flag=0 | |
Exit for | |
End If | |
Next | |
If Flag=0 Then | |
Exit For | |
End if | |
Next | |
Set theRun = nothing | |
Set RunF = nothing | |
Set ts_obj= nothing | |
Set aTestCaseArray = nothing | |
Set TestCaseF = nothing | |
Set tstests= nothing | |
Set aTestSetArray = nothing | |
Set TestSetF = nothing | |
Set TestSetFolder = nothing | |
Set tcTreeMgr = nothing | |
Set tsTreeMgr = nothing | |
Set tfact = nothing | |
Set tdc = nothing | |
####################################almData.properties################################## | |
ALM_URL=http://ALMURL | |
ALM_USERNAME=USERNAME | |
ALM_PASSWORD=PASSWORD | |
ALM_DOMAIN=DOMAINANME | |
ALM_PROJECT=PROJECTNAME | |
Test_Set_Folder_Path=TEST\\SET\\FOLDER\\PATH | |
Test_Set_Name=TEST SET NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment