Commit b9d6897c authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg

Completed a custom reporter that reports back to Browserstack the success of a test run.

parent 0fda89ee
const moment = require('moment');
const moment = require('moment')
var CustomReporter = require('../lib/CustomReporter.js')
var ts = moment().format('YYYY-MM-DD HH:mm')
......@@ -21,11 +21,11 @@ exports.config = {
},
capabilities: [
{
os: "WINDOWS", os_version: "10",
browser: "chrome",
browser_version: "62"
},
// {
// os: "WINDOWS", os_version: "10",
// browser: "chrome",
// browser_version: "62"
// },
// {
// os: "WINDOWS", os_version: "10",
// browser: "firefox",
......@@ -41,11 +41,11 @@ exports.config = {
// browser: "IE",
// browser_version: "9"
// },
// {
// os: "WINDOWS", os_version: "7",
// browser: "IE",
// browser_version: "8"
// }, // PROBLEMS
{
os: "WINDOWS", os_version: "7",
browser: "IE",
browser_version: "8"
}, // PROBLEMS
// {
// os: "WINDOWS", os_version: "7",
// browser: "firefox",
......@@ -80,7 +80,8 @@ exports.config = {
mochaOpts: {
ui: 'bdd',
timeout: 35000
}
},
reporters: [CustomReporter]
}
// Code to support common capabilities
......
......@@ -5,8 +5,9 @@ const opts = {
}
var wdio = new Launcher(opts.configFile, opts)
wdio.run().then(function (code) {
console.log("Completed with code", code)
process.exit(code)
setTimeout(() => {
process.exit(code)
}, 2000)
}, function (error) {
console.error('Launcher failed to start the test', error.stacktrace)
process.exit(1)
......
......@@ -4,22 +4,26 @@ var request = require('request')
class BrowserStack {
static reportStatus(sessionID, status, reason) {
let options = {
url: 'https://www.browserstack.com/automate/sessions/' + sessionID + '.json',
method: 'PUT',
json: {
"status": status,
"status": (status ? 'completed' : 'failed'),
"reason": reason
}
}
// options.url = 'https://bfc.httpjs.net/automate/sessions/' + sessionID + '.json'
console.log("Config", options)
// console.log("Reporting status to " + sessionID)
// console.log(options)
// console.log("====")
// // options.url = 'https://bfc.httpjs.net/automate/sessions/' + sessionID + '.json'
// console.log("Config", options)
if (!process.env.BROWSERSTACK_USERNAME || !process.env.BROWSERSTACK_ACCESS_KEY) {
throw new Error("Missing credential to post status to Browserstack")
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log("Successfully posted status to browserstack for session ID " + sessionID)
console.log("Successfully posted status to browserstack for session ID " + sessionID + " " + (status ? 'completed' : 'failed'))
} else {
console.error("Error posting status to browserstack status code [" + response.statusCode + "]", error)
console.error("Body ")
......
var util = require('util'),
events = require('events');
var BrowserStack = require('./BrowserStack').BrowserStack
var CustomReporter = function(options) {
// you can access reporter options via
// `options.reporterOptions`
// ...
this.on('runner:result', function(event) {
if (options.stats.counts.suites < 1) {
return
}
let success = options.stats.counts.failures === 0;
let res = event.requestOptions.uri.path.match(/^\/wd\/hub\/session\/([a-z0-9]+)$/)
if (!res) {
return;
}
let sessionID = res[1]
let reason = 'Success'
// console.log("RES IS ", res[1])
// console.log(options.stats.failures[0].err.message)
// console.log('Count failures ' + options.stats.counts.failures)
// console.log((success ? 'SUCCESS' : 'FAIL'))
// console.log('path is ' + event.requestOptions.uri.path)
if (!success) {
reason = 'Failures ' + options.stats.counts.failures
if (options.stats.failures[0].err && options.stats.failures[0].err.message) {
reason += ' Fail:' + options.stats.failures[0].err.message
}
}
BrowserStack.reportStatus(sessionID, success, reason)
// console.log(options)
})
};
CustomReporter.reporterName = 'DataportenBrowserStackReporter';
/**
* Inherit from EventEmitter
*/
util.inherits(CustomReporter, events.EventEmitter);
/**
* Expose Custom Reporter
*/
exports = module.exports = CustomReporter;
......@@ -92,7 +92,7 @@ class DiscoveryPage extends Page {
select(term) {
// browser.click('p=Feide testbrukere')
assert(this.browser.isExisting('p=' + term), "Can find term " + term + " on discovery page")
console.log(" EXISTS " + (this.browser.isExisting('p=' + term) ? 'YES ' : 'NO'))
// console.log(" EXISTS " + (this.browser.isExisting('p=' + term) ? 'YES ' : 'NO'))
console.log("About to click on " + term + " on url " + browser.getUrl())
this.browser.click('p=' + term)
this.session.waitForURL('://authengine.paas2.uninett.no/', false)
......@@ -125,6 +125,9 @@ class Session {
// if (this.browser.getUrl().indexOf(term) > -1) {
// console.log("MATCH ON " + term + " " + this.browser.getUrl())
// }
if (!this.browser.getUrl()) {
return false
}
return (this.browser.getUrl().indexOf(term) > -1)
}
......
var assert = require('assert');
var Dataporten = require('../../lib/Dataporten')
var BrowserStack = require('../../lib/BrowserStack').BrowserStack
var settings = {
oauthserver: {
......@@ -30,7 +29,6 @@ describe('Login for the first time', function() {
it('initiate authentication', function () {
page = dp.auth()
assert(page instanceof Dataporten.DiscoveryPage, 'Expected the discovery page first time when authenticating')
});
it('set language', function () {
page = page.setLang()
......@@ -91,10 +89,5 @@ describe('Login for the first time', function() {
});
});
BrowserStack.reportStatus(browser.requestHandler.sessionID, "error", "Problems yay")
console.log("---- sessionid")
console.log(browser.requestHandler.sessionID)
console.log("----- -----")
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment