finastra-reportportal-jasmine
v1.0.0
Published
Agent for integration Jasmine with ReportPortal.
Downloads
2
Readme
agent-js-jasmine
Agent for integration Jasmine with ReportPortal.
ReportPortal
ReportPortal on GitHub
How to use
- Install the agent in your project:
npm i agent-js-jasmine --save-dev
- Create an agent instance:
var ReportportalAgent = require('agent-js-jasmine');
var agent = new ReportportalAgent({
// client settings
token: "00000000-0000-0000-0000-000000000000",
endpoint: "http://your.reportportal.server/api/v1",
launch: "LAUNCH_NAME",
project: "PROJECT_NAME",
// agent settings
attachPicturesToLogs: true,
attributes: [
{
"key": "YourKey",
"value": "YourValue"
},
{
"value": "YourValue"
},
]
});
- Add a reporter to Jasmine:
jasmine.addReporter(agent.getJasmineReporter());
- After Jasmine has completed its work, wait until the end of the agent's work:
agent.getExitPromise().then(() => {
console.log('finish work');
})
Settings
Agent settings consist of two parts:
- Client settings can be viewed here
- Agent settings are described below
Parameter | Description --------- | ----------- attachPicturesToLogs | It is 'true' or 'false', if set 'true' then attempts will be made to attach screenshots to the logs. Default: 'true'.
Integrations
Protractor integration
Launch agent in single thread mode.
If you launch protractor in single tread mode , just add agent initialization to the onPrepare function. Add agent.getJasmineReporter to the jasmine.getEnv().addReporter() as an argument. You can see this in the example bellow. Update your configuration file as follows:
const ReportportalAgent = require('agent-js-jasmine');
...
const agent = new ReportportalAgent({
token: "00000000-0000-0000-0000-000000000000",
endpoint: "http://your.reportportal.server/api/v1",
launch: "LAUNCH_NAME",
project: "PROJECT_NAME",
attachPicturesToLogs: false,
attributes: [
{
"key": "YourKey",
"value": "YourValue"
},
{
"value": "YourValue"
},
]
});
exports.config = {
...
onPrepare: ()=> {
...
jasmine.getEnv().addReporter(agent.getJasmineReporter());
},
afterLaunch:() => {
return agent.getExitPromise();
}
};
Launch agents in multi thread mode.
For launching agents in multi thread mode firstly parent launch must be created and it ID must be sent to the child launches , so they would send data to the right place, and wouldn't create new launch instances at the Report Portal.
The main problem is that node.js is a single threaded platform. And for providing multi treading launch with browsers protractor generate new processes of node, which can't interact with each other, so Singelton objects or functions can't be created for synchronizing it work. Only primitive types could be sent as args to the new processes before launch. The way of resolving this problem is to create launch file that would generate a Parent Launch and send launch's ID to protractor as argument. Then protractor would launch jasmine-agents with parent ID. Look through example of the Launch File with protractor-flake module at the 'Settings fot the multi threaded launch' section or at the examples folder. Any node runner could be used!
- Install 'protractor-flake':
npm install protractor-flake --save-dev
- Create a config file as in example below:
reportportalConf.js
module.exports = {
token: "00000000-0000-0000-0000-000000000000",
endpoint: "http://your.reportportal.server/api/v1",
launch: "LAUNCH_NAME",
project: "PROJECT_NAME",
attachPicturesToLogs: false,
attributes: [
{
"key": "YourKey",
"value": "YourValue"
},
{
"value": "YourValue"
},
]
}
- Create a main launch file as in example below:
protractorLaunchFile.js
const protractorFlake = require('protractor-flake');
const AgentJasmine = require('agent-js-jasmine');
const reportportalConfig = require('./reportportalConf');
const agent = new AgentJasmine(reportportalConfig);
agent.getLaunchStartPromise().then((launchData) =>{
protractorFlake({
maxAttempts: 1,
protractorArgs: [
'./multiThreadConf.js',
'--params.id',
launchData.id
]
}, (status) => {
agent.getExitPromise().then(() =>{
process.exit(status);
});
});
});
- Then create protractor's spec file as in example below:
multiThreadConf.js file
const ReportportalAgent = require('agent-js-jasmine');
const reportportalConfig = require('./reportportalConf');
exports.config = {
multiCapabilities: [
{
name: 'normal',
browserName: 'chrome',
maxInstances: 2,
shardTestFiles: true,
chromeOptions: {
args: ['--window-size=1024,768', '--disable-infobars']
}
}
],
specs: ['testAngularPage.js', 'testGithubPage.js'],
onPrepare() {
const config = Object.assign({
id: browser.params.id
}, reportportalConfig);
const agent = new ReportportalAgent(config);
/*Its a hack. There is an issue since 2015. That Jasmine doesn't wait for report's async functions.
links to the issues https://github.com/jasmine/jasmine/issues/842
https://github.com/angular/protractor/issues/1938
So it needed to wait until requests would be sent to the Report Portal.
*/
afterAll((done) => agent.getPromiseFinishAllItems(agent.tempLaunchId).then(()=> done()));
jasmine.getEnv().addReporter(agent.getJasmineReporter());
}
};
- Update script section for your package.json:
"scripts": {
"protractor-multi": "node protractorLaunchFile.js"
}
- Run your protractor:
npm run protractor-multi
Link to the jasmine issue , that it doesn't work well with async functions jasmine issue, protractor's community
Copyright Notice
Licensed under the Apache 2.0 license (see the LICENSE.txt file).