Zarkonnen / se-interpreter

Interpreter for Selenium Builder JSON scripts based on node.js and wd.
34 stars 31 forks source link

Junit report? #36

Closed billieblaze closed 9 years ago

billieblaze commented 9 years ago

Running this local and experimenting w/ sauce + sauce onDemand jenkins plugin. Not REALLY seeing a way to grab a junit report from this. Am i missing something?

davidlinse commented 9 years ago

You'll have to write your own..

billieblaze commented 9 years ago

thats kind of what i figured. I'm looking over listeners now and got most of it hashed out. kind of wishing there was an extra event exposed which would expose the absolute end of ALL runs. but I'll keep you posted on what i come up with

davidlinse commented 9 years ago

You might want to have a look at either the junit branch or integration in my fork of se-interpreter.

regards ~david

billieblaze commented 9 years ago

Heres what i came up with..

// Se-Interpreter JUnit listener
// Author: Bill Berzinkas (bberzinskas@stanleygibbons.com)
//
// Convert se-interpreter steps to a Junit report for jenkins
//
// NOTE: requires js2xmlparser to be installed
/*
  SAMPLE JUNIT FORMAT

  <testsuite tests="3">
    <testcase classname="foo" name="ASuccessfulTest"/>
    <testcase classname="foo" name="AnotherSuccessfulTest"/>
    <testcase classname="foo" name="AFailingTest">
        <failure type="NotEnoughFoo"> details about failure </failure>
    </testcase>
  </testsuite>

*/

var util = require('util'),
    js2xmlparser = require("js2xmlparser"),
    fs = require("fs");

 var junitData =  {
                    "@": {
                      "tests": 0
                    },
                    "testcase": []
                  };

exports.getInterpreterListener = function(testRun) {

  return {
    'startTestRun': function(testRun, info) {},
    'endTestRun': function(testRun, info) {

      junitData['@'].tests++;
      var stepData = { 
        '@': { 
          classname: testRun.browserOptions.browserName + ' -- ' + testRun.name
          }
        };

      if (info.error){ 
        stepData.failure = util.inspect(info.error);
      }
      junitData.testcase.push( stepData);

      // todo: theres no definitive "all tests done" event, so just overwrite the file til the last test is run
      fs.writeFile('report.xml', js2xmlparser("testsuite", junitData));
    },
    'startStep': function(testRun, step) { },

    'endStep': function(testRun, step, info) {
      console.log("step: " + JSON.stringify(step) + " : " + info.success + ' : ' + util.inspect(info.error));
    }
  };
};
Zarkonnen commented 9 years ago

Noted about the "end of all runs" event. Good point.

billieblaze commented 9 years ago

doing a little reshuffling this morning to get a slightly better reporting output. working pretty well so far :-)

Zarkonnen commented 9 years ago

Going to close this as not an issue, OK?

DylanLacey commented 9 years ago

Would it be possible to merge the junit-listener into the base project's utils, given the usefulness for CI?

gregmoser commented 8 years ago

It would be really great if this got added to the se-interpreter. We use CircleCI instead of travis because it allows you to actually read and parse jUnit xml as part of the notification. If someone were to issue a formal PR, would it be accepted into the core?

Zarkonnen commented 8 years ago

Sure! Does it have to be built into interpreter.js or could it just live in utils/?

gregmoser commented 8 years ago

I'm not exactly sure where it should go, because I don't know how a lot of this works. I guess I'm just hoping that I can take something like this: https://github.com/davidlinse/se-interpreter/blob/integration/listener/junit-listener.js from @davidlinse could be added to the core and documented so that I can figure out how to have these xml style reports be saved to a local file so that circleCI can pick it up :)

gregmoser commented 8 years ago

NVMD, I just figured out how to use listeners (I read the README docs again, duh!) which I think will allow me to do the JUnit reporting that I want. I guess it would just be nice if the 'out-of-the-box' version of this automatically had that JUnit listener that @davidlinse created as part of the utils folder.