Open keitharobertson opened 8 years ago
@evrycollin
I'm interested too, how to pass meta information from tests
Will appreciate any examples too.
I eventually determined that you couldn't do it without making some small modifications to the webdriverio code. Specifically if you look in lib/runner.js in the wdio code, you will see the events. You can add your own events in there. Then you need to make sure the reporter knows how to handle your events. I added my event to this allure reporter- I took index.js added my own events to it and configured it as a custom reporter in wdio.
Example: In lib/runner.js in webdriverio:
global.browser.on('customimage', (payload) => {
const result = {
event: 'runner:customimage',
cid: m.cid,
specs: this.specs,
name: payload.name,
image: payload.image
}
process.send(this.addTestDetails(result))
})
Create a custom reporter (take the allure reporter and modify it slightly)- require the custom reporter in your wdio.conf.js file and then set reporters to that reporter:
const CustomReporter = require( 'custom_allure' );
...
reporters: [CustomReporter]
In that custom_allure reporter, add your own events. For example:
this.on('runner:customimage', (data) => {
const allure = this.getAllure(data.cid);
allure.startStep('Custom Image ' + data.name);
allure.addAttachment('Image', new Buffer(data.image, 'base64'));
allure.endStep('passed');
});
@krobertson92, very helpful idea! Also we can use wdio hooks to generate our own events. If we are using CucumberJS we also can use its hooks. For example we can use such hook to send data to child process from wdio.conf.js:
beforeStep: (step) => {
process.send({
event: 'step:start',
name: step.getName(),
});
},
And after we can easily follow steps described by @krobertson92 to handle those.
const CustomReporter = require( 'custom_allure' );`
...
reporters: [CustomReporter]`
and
this.on('runner:customimage', (data) => {
const allure = this.getAllure(data.cid);
allure.startStep('Custom Image ' + data.name);
allure.addAttachment('Image', new Buffer(data.image, 'base64'));
allure.endStep('passed');
});
How do you emit the events in your test. So say I have a test and I want to send an attachment to allure. Can you give an example of how I do that in a mocha test?