Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the launch id programatically #78

Open
ASaiAnudeep opened this issue Mar 10, 2022 · 0 comments
Open

How to get the launch id programatically #78

ASaiAnudeep opened this issue Mar 10, 2022 · 0 comments

Comments

@ASaiAnudeep
Copy link

ASaiAnudeep commented Mar 10, 2022

One way to get the launch id is through adding a custom reporter on top of this package.

const ReporPortalAgent = require('@reportportal/agent-js-mocha');
const fs = require('fs');

class ReporPortal extends ReporPortalAgent {
    constructor(runner, options) {
        super(runner, options);
    }
    onLaunchStart() {
        const systemAttributes = this.getSystemAttributes();
        const launchAttributes = (this.options.reporterOptions.attributes || []).concat(
            systemAttributes,
        );
        const { tempId, promise } = this.rpClient.startLaunch({
            token: this.options.reporterOptions.token,
            name: this.options.reporterOptions.launch,
            startTime: this.rpClient.helpers.now(),
            description: this.options.reporterOptions.description,
            rerun: this.options.reporterOptions.rerun,
            rerunOf: this.options.reporterOptions.rerunOf,
            attributes: launchAttributes,
        });
        promise
            .then(res => fs.writeFileSync('.env', `RP_LAUNCH_ID=${res.id}`))
            .catch(err => console.error('Failed to launch run.', err));
        this.launchId = tempId;
    }
}
module.exports = ReporPortal;

Is there a better way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant