I am using protractor-cucumber framework(protractor 5.2.2 and cucumber 3.2.0).I am running my protractor script as distributed test execution in multiple browsers.So after each browser execution, i will get an array in AfterAll function.I need to get these data to afterLaunch. So that i can mail these data from afterLaunch, only once, after the execution of all browsers.If i am trying to mail these data from AfterAll function, No.of mails are more.So i need to consolidate data from each AfterAll function to afterLaunch.How can i do this?Can anyone help me.Thanks in advance.
Asked
Active
Viewed 179 times
1 Answers
0
This works fine for me
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const page = require('../Test_pages')
let Page = new page.Pom();
const helpers = require('../helpers');
let help = new helpers.helpers();
global.before(function () {
chai.should();
chai.use(chaiAsPromised);
var sf = '{}'
this.fail = JSON.parse(sf);
this.pass = JSON.parse(sf);
this._pass = JSON.parse(sf);
});
afterEach(function () {
});
after(function () {
console.log(this.fail);
// will display all property you have added
return Page.fail(this.fail);
// call the fail method in pages file
});
In your step definition file
this.fail[`${testsuite}_${envcode}`] = [{ "pass": false, "testcode": `${testcode}`, "global": `${globalsrc}`, "env": `${envcode}`, "testsuite": `${testsuite}`, "ext3": `${type}` }];
Now you can use this JSON object to hold the state of execution by creating a property for each test. I have created a property for each execution with combination of testsuite and envcode names.
You use this.fail in all hooks function or even write this data to a file by converting it to a String. Later you can read it again.
var jsonStr = JSON.stringify(this.fail);
var fs = require('fs');
fs.writeFile("test_input.json", jsonStr, function (err) {
if (err) {
console.log(err);
}
});

Bharath Kumar S
- 1,410
- 2
- 10
- 29