This package has been deprecated

Author message:

The package is out of date and will no longer supported by reportportal.io. Please use https://www.npmjs.com/package/@reportportal/agent-js-jasmine with RP 5.0 full compatibility

agent-js-jasmine

3.0.0 • Public • Published

agent-js-jasmine

Build StatusCode Coveragenpm version

Agent for integration Jasmine with ReportPortal.
ReportPortal
ReportPortal on GitHub

How to use

  1. Install the agent in your project:
npm i agent-js-jasmine --save-dev
  1. 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-instance.com:8080/api/v1",
    launch: "LAUNCH_NAME",
    project: "PROJECT_NAME",
    // agent settings
    attachPicturesToLogs: true,
});
  1. Add a reporter to Jasmine:
jasmine.addReporter(agent.getJasmineReporter());
  1. 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-instance.com:8080/api/v1",
        launch: "LAUNCH_NAME",
        project: "PROJECT_NAME",
        attachPicturesToLogs: false
    });
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!

  1. Install 'protractor-flake':
npm install protractor-flake --save-dev
  1. Create a config file as in example below:

reportportalConf.js

module.exports = {
    token: "00000000-0000-0000-0000-000000000000",
    endpoint: "http://your-instance.com:8080/api/v1",
    launch: "LAUNCH_NAME",
    project: "PROJECT_NAME",
    attachPicturesToLogs: false
}
  1. 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);
        });
    });
});
  1. 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());
     }
 
 };
  1. Update script section for your package.json:
"scripts": {
    "protractor-multi": "node protractorLaunchFile.js"
 }
  1. 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 GPLv3 license (see the LICENSE.txt file).

Readme

Keywords

none

Package Sidebar

Install

npm i agent-js-jasmine

Weekly Downloads

224

Version

3.0.0

License

ISC

Last publish

Collaborators

  • amsterget
  • davert
  • fizik2009
  • reportportal-admin