Search code examples
node.jsselenium-webdriverautomated-testsmocha.jswebdriver-io

How/What is the best way to auto create/save text file version of automated test reporter logs


It's my first time building proper selenium tests (I've touched on IDE before). I'm using Selenium with NodeJS, WebdriverIO, Mocha framework, wdio-spec-reporter and wdio-browserstack-service. I have managed to create my tests, suites specified in conf.js , hooked into browserstack (so when i run in command line, it creates a text log and video in browserstack). Now I've been asked to do something so that when a test/suite is run it will automatically save the text logs as a text file.

My thoughts are either building an additional function and hooking into the spec reporter or retrieving them from browserstack. I've spent a bit of time googling it, but apart from using the allure reporter (looks like it can do this?), I am struggling to find any information. Is this possible? If so, how & which way?

Thanks for your help


Solution

  • Worked it out. The reporter was using the globally built reporter.js file (in AppData folder), not the one inside the plugin folder. All I needed was to print the results just before the "return output;" statement. Looking something like;

    var d = new Date();
    var fileDate = (d.getMonth()+1)+'-'+d.getDate()+'-'+d.getFullYear()+'_'+(d.getHours()+1)+'-'+d.getMinutes()+'-'+d.getSeconds();
    var fileName = 'test-log_'+fileDate+'.txt';
    var fs = require('fs');
    fs.writeFile(fileName, output, function (err) {
    });