1

When I run the protractor test case, I got the below JSON response for the test case result, which get stored in a file as combined.json.

Case 1: For passed test case:

{"description":"tests the case when the login was successful|E2E test Login and search users with different search criteria",
"passed":true,
"os":"XP",
"browser": chrome
}

Case 2: For Failed test case:

{"description":"tests the case when the login was successful|E2E test Login and search users with different search criteria",
"passed":false,
"os":"XP",
"browser": chrome
}

In above cases test result is stored in the passed JSON object.

I am writing a VAPI test case in HPALM and for that I need to pass the test case status. I would like to get the value of passed to a variable.

Ansgar Wiechers
  • 184,186
  • 23
  • 230
  • 299
Durgesh
  • 555
  • 3
  • 10
  • 30

1 Answers1

2

I don't think there's a JSON parser for VBScript, so you'll have to parse the file yourself. Since you have a very simple scenario (extract the value for a specific key) using a regular expression should be fine, though:

Set fso = CreateObject("Scripting.FileSystemObject")

json = fso.OpenTextFile("C:\path\to\combined.json").ReadAll

Set re = New RegExp
re.Pattern = """passed"":(true|false),"
re.IgnoreCase = True

For Each m In re.Execute(json)
  passed = CBool(m.SubMatches(0))
Next
Ansgar Wiechers
  • 184,186
  • 23
  • 230
  • 299
  • Thanks for reply. We have merged your(exact above) code and added below line after your code in VAPI test case. CurrentRun.Status = passed. Now each passed variable is giving value as failed. could you please help us to get the exact status. Thanks! – Durgesh May 28 '15 at 12:34
  • @Durgesh What value does `passed` have before you assign it to `CurrentRun.Status` (`MsgBox passed`)? What data type does `CurrentRun.Status` expect? My sample code converts the string to a boolean. – Ansgar Wiechers May 28 '15 at 13:17
  • I misunderstood this. Now I am able to apply this logic. Thanks for your help. – Durgesh May 29 '15 at 04:34