jasmine / jasmine-browser-runner

Serve and run your Jasmine specs in a browser
49 stars 23 forks source link

Get browser information in reporter #41

Closed bksglatz closed 1 year ago

bksglatz commented 1 year ago

I wonder if there is any interface (or maybe a dirty tunnel ;)) that would allow me to get information about the browser running the tests into my custom reporter. Any advice would be appreciated :)

sgravrock commented 1 year ago

There's nothing built in, but here's a dirty tunnel:

// jasmine-browser.json
{
   "reporters": ["./browserInfoReporter.js"],
   // ...
}

// spec/reportBrowserSpec.js
describe('Reporting browser info', function() {
    it('reports the user agent', function() {
        setSuiteProperty('browser', navigator.userAgent.toString());
    });
});

// browserInfoReporter.js
class BrowserInfoReporter {
    suiteDone(event) {
        if (event.properties?.browser) {
            console.log('Browser:', event.properties.browser);
        }
    }
};

module.exports = BrowserInfoReporter;
bksglatz commented 1 year ago

Thx. That will do it.