Skip to content

How to get the launch id programatically #78

@ASaiAnudeep

Description

@ASaiAnudeep

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions