问题
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
回答1:
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) {
});
回答2:
I don't think that previous solution was a good practice because of changing the webdriverio itself. Now I'm using json-reporter which makes parsing information very easy and logs everything needed
来源:https://stackoverflow.com/questions/39871667/how-what-is-the-best-way-to-auto-create-save-text-file-version-of-automated-test