This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

A script to run tests against saucelabs (w/ contributions from Leah […

…:klrmn] Klearman and Zach [:zcarter] Carter)
  • Loading branch information...
1 parent 5cf2bc0 commit 45bf72866450deb666ad1551d6ba63c567c015ca @lloyd lloyd committed Aug 17, 2012
Showing with 443 additions and 1 deletion.
  1. +75 −0 automation-tests/lib/convert_results.js
  2. +364 −0 automation-tests/run_saucelabs
  3. +4 −1 package.json
@@ -0,0 +1,75 @@
+#!/usr/bin/env node
+/*
+ * Converts html reports into nice, machine readable JSON
+ * Run: $ ./convert_result.js result/index.html
+ */
+
+const fs = require('fs'),
+ path = require('path'),
+ jsonselect = require('JSONSelect'),
+ htmlparser = require('htmlparser');
+
+
+function main (args) {
+ var file = fs.readFile(path.resolve(args[2]), "utf8", function (err, html) {
+ if (err) throw err;
+ parseReport(html);
+ });
+}
+
+function parseReport (html) {
+ var report = {};
+ var handler = new htmlparser.DefaultHandler(function(err, dom) {
+ if (err) {
+ console.error("Error: " + err);
+ } else {
+ var results = jsonselect.match(':has(:root > .attribs > .id:val("results")) .children :has(:root > .name:val("tr"))', dom);
+
+ // remove header row
+ results.shift();
+
+ results.forEach(function (node, i, array) {
+ var url;
+ var result = node.children[1].attribs.class;
+
+ // skip traceback rows
+ if (!result) return;
+
+ try {
+ url = result === 'error' ?
+ findJobUrl(array[i+1].children[1].children[1].children) :
+ node.children[9].children[0].attribs.href;
+ } catch (e) {
+ url = '';
+ }
+
+ var name = node.children[5].children[0].data;
+
+ report[name] = {
+ success: result === 'passed',
+ class: node.children[3].children[0].data,
+ duration: node.children[7].children[0].data,
+ url: url
+ };
+ });
+ }
+ });
+
+ var parser = new htmlparser.Parser(handler);
+ parser.parseComplete(html);
+ return report;
+}
+
+// extract saucelab url from error report
+function findJobUrl (children) {
+ var result;
+ children.forEach(function (node) {
+ var match = node.raw.match(/https:\/\/saucelabs.com\/jobs\/[a-f0-9]+/);
+ if (match) result = match[0];
+ });
+ return result;
+}
+
+exports.parseReport = parseReport;
+
+if (process.argv[1] === __filename) main(process.argv);
Oops, something went wrong.

0 comments on commit 45bf728

Please sign in to comment.