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
  • 193,178
  • 25
  • 254
  • 328
Durgesh
  • 585
  • 4
  • 12
  • 33

2 Answers2

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
  • 193,178
  • 25
  • 254
  • 328
  • 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
-2

$data = Get-ChildItem -Path / -Filter 'param.json' -Recurse | ForEach-Object { Get-Content $_.FullName } $param = $data | ConvertFrom-Json

$param.parameters.Name.value

Name is the key value in json file

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 02 '22 at 08:34