0

I have installed jsonjunit package of npm.I want to convert json file to junit xml - so that jenkins can read that file . My json file is like this :-

{"results":[ {"id":1136168, "startTime":"2017-05-12T15:11:07.834Z", "endTime":"2017-05-12T15:11:17.834Z", "status":0, "comment":"Test has run to completion", "logFile":"ftp://stormtest:stormtest@blr-strmtst-01:21/public/NET_TEST/Tools/flashUI_20170511_124701", "user":{"id":1032295,"name":"BLRTEST"}, "script":{"path":"public/NET_TEST//Tools//flashUI.py"}, "schedule":{"id":1136164}, "job":{"id":1136167}, "duts":[{"id":98113,"name":"7430_NET_II_1"}], "slots":[{"id":59,"number":2,"server":{"id":52,"name":"BLR-STRMTST-01"}}]}]}


I used the following command to convert the json to junit xml , as per instruction mentioned in https://www.npmjs.com/package/json-junit.But it throws error:

var dateFormatted = new Date(jsonData.stats.start), TypeError: Cannot read property 'start' of undefined at Object.convertJson (C:\Program Files\nodejs\node_modules\npm\node_modules

Please help.

Anupam Dutta
  • 13
  • 1
  • 5
  • Nothing but simply write special custom program which will convert Json to XML... – Vadim May 12 '17 at 09:42
  • I was able to install npm and use the json junit library but i ran into the following error :- var dateFormatted = new Date(jsonData.stats.start), TypeError: Cannot read property 'start' of undefined at Object.convertJson (C:\Program Files\nodejs\node_modules\npm\node_modules – Anupam Dutta May 15 '17 at 04:36
  • My json file is like this : – Anupam Dutta May 15 '17 at 04:37

1 Answers1

0

I was able to convert XML into Junit xml format which can be read by jenkins. To start with I made the following XLST file which acts as the parser:-

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<testsuites>
<testsuite tests="{count(exported_results/test_result)}" passed="{count(exported_results/test_result[test_status='111'])}" failed=" {count(exported_results/test_result[test_status='100'])}">          
<xsl:for-each select="exported_results/test_result[test_status='111']">
<testcase name="{test_script}" classname="{schedule_name}" result="{test_status}" comments = "{result_comments}"></testcase><passed />
</xsl:for-each>
<xsl:for-each select="exported_results/test_result[test_status='100']">
<testcase name="{test_script}" classname="{schedule_name}" result="{test_status}" comments = "{result_comments}"></testcase><failed />
</xsl:for-each>
</testsuite>
</testsuites>
</xsl:template>
</xsl:stylesheet>

Then I used the python script provided in article :-How to transform an XML file using XSLT in Python?

With the help of script - I was able to generate a junit xml supported by jenkins. Output is like this:-

    <?xml version="1.0"?>
-<testsuites>
-<testsuite failed=" 1" passed="1" tests="2">
<testcase comments="Test has run to completion" result="111" classname="FAV" name="public/Test_ATL_1/Framework/ATS_UI/Guide_test/zapper/favorite_list/TM_2291_add_fav_chn_from_epg.py"/>
<passed/>
<testcase comments="Test has run to completion" result="100" classname="FAV" name="public/Test_ATL_1/Framework/ATS_UI/Guide_test/zapper/favorite_list/TM_2287_add_fav_chn_from_live.py"/>
<failed/>
</testsuite>
</testsuites>
Community
  • 1
  • 1
Anupam Dutta
  • 13
  • 1
  • 5