5.1.3 • Published 8 days ago

@reportportal/client-javascript v5.1.3

Weekly downloads
13,528
License
Apache-2.0
Repository
github
Last release
8 days ago

ReportPortal js client

This Client is to communicate with the Report Portal on Node.js.

Library is used only for implementors of custom listeners for ReportPortal.

Already implemented listeners:

Examples for test framework integrations from the list above described in examples repository.

Installation

The latest version is available on npm:

npm install @reportportal/client-javascript

Usage example

const RPClient = require('@reportportal/client-javascript');

const rpClient = new RPClient({
    apiKey: 'reportportalApiKey',
    endpoint: 'http://your-instance.com:8080/api/v1',
    launch: 'LAUNCH_NAME',
    project: 'PROJECT_NAME'
});

rpClient.checkConnect().then((response) => {
    console.log('You have successfully connected to the server.');
    console.log(`You are using an account: ${response.fullName}`);
}, (error) => {
    console.log('Error connection to server');
    console.dir(error);
});

Configuration

When creating a client instance, you need to specify the following options:

OptionNecessityDefaultDescription
apiKeyRequiredUser's reportportal token from which you want to send requests. It can be found on the profile page of this user.
endpointRequiredURL of your server. For example, if you visit the page at 'https://server:8080/ui', then endpoint will be equal to 'https://server:8080/api/v1'.
launchRequiredName of the launch at creation.
projectRequiredThe name of the project in which the launches will be created.
headersOptional{}The object with custom headers for internal http client.
debugOptionalfalseThis flag allows seeing the logs of the client. Useful for debugging.
isLaunchMergeRequiredOptionalfalseAllows client to merge launches into one at the end of the run via saving their UUIDs to the temp files at filesystem . At the end of the run launches can be merged using mergeLaunches method. Temp file format: rplaunch-${launch_uuid}.tmp.
restClientConfigOptionalNot setaxios like http client config. May contain agent property for configure http(s) client, and other client options eg. timeout. For debugging and displaying logs you can set debug: true.
launchUuidPrintOptionalfalseWhether to print the current launch UUID.
launchUuidPrintOutputOptional'STDOUT'Launch UUID printing output. Possible values: 'STDOUT', 'STDERR', 'FILE', 'ENVIRONMENT'. Works only if launchUuidPrint set to true. File format: rp-launch-uuid-${launch_uuid}.tmp. Env variable: RP_LAUNCH_UUID.
tokenDeprecatedNot setUse apiKey instead.

Asynchronous reporting

The client supports an asynchronous reporting. If you want the client to work asynchronously change v1 to v2 in addresses in endpoint.

API

Each method (except checkConnect) returns an object in a specific format:

{
    tempId: '4ds43fs', // generated by the client id for further work with the created item
    promise: Promise // An object indicating the completion of an operation
}

The client works synchronously, so it is not necessary to wait for the end of the previous requests to send following ones.

Timeout (30000ms) on axios requests

There is a timeout on axios requests. If for instance the server your making a request to is taking too long to load, then axios timeout will work and you will see the error 'Error: timeout of 30000ms exceeded'.

You can simply change this timeout by adding a timeout property to restClientConfig with your desired numeric value (in ms) or 0 to disable it.

checkConnect

checkConnect - asynchronous method for verifying the correctness of the client connection

rpClient.checkConnect().then((response) => {
    console.log('You have successfully connected to the server.');
    console.log(`You are using an account: ${response.fullName}`);
}, (error) => {
    console.log('Error connection to server');
    console.dir(error);
});

startLaunch

startLaunch - starts a new launch, return temp id that you want to use for the all items within this launch.

const launchObj = rpClient.startLaunch({
    name: 'Client test',
    startTime: rpClient.helpers.now(),
    description: 'description of the launch',
    attributes: [
        {
            'key': 'yourKey',
            'value': 'yourValue'
        },
        {
            'value': 'yourValue'
        }
    ],
    //this param used only when you need client to send data into the existing launch
    id: 'id'
});
console.log(launchObj.tempId);

The method takes one argument:

  • launch data object:
OptionNecessityDefaultDescription
startTimeOptionalrpClient.helpers.now()Start time of the launch (unix time).
nameOptionalparameter 'launch' specified when creating the client instanceName of the launch.
modeOptional'DEFAULT''DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page.
descriptionOptional''Description of the launch (supports markdown syntax).
attributesOptional[]Array of launch attributes (tags).
idOptionalNot setID of the existing launch in which tests data would be sent, without this param new launch instance will be created.

To get the real launch ID (also known as launch UUID from database) wait for the returned promise to finish.

const launchObj = rpClient.startLaunch();
launchObj.promise.then((response) => {
    console.log(`Launch real id: ${response.id}`);
}, (error) => {
    console.dir(`Error at the start of launch: ${error}`);
})

As system attributes, this method sends the following data (these data are not for public use):

  • client name, version;
  • agent name, version (if given);
  • browser name, version (if given);
  • OS type, architecture;
  • RAMSize;
  • nodeJS version;

ReportPortal is supporting now integrations with more than 15 test frameworks simultaneously. In order to define the most popular agents and plan the team workload accordingly, we are using Google Analytics.

ReportPortal collects only information about agent name, version and version of Node.js. This information is sent to Google Analytics on the launch start. Please help us to make our work effective. If you still want to switch Off Google Analytics, please change env variable. 'REPORTPORTAL_CLIENT_JS_NO_ANALYTICS=true'

finishLaunch

finishLaunch - finish of the launch. After calling this method, you can not add items to the launch. The request to finish the launch will be sent only after all items within it have finished.

// launchObj - object returned by method 'startLaunch'
const launchFinishObj = rpClient.finishLaunch(launchObj.tempId, {
    endTime: rpClient.helpers.now()
});

The method takes two arguments:

  • launch tempId (returned by the method startLaunch)
  • data object:
OptionNecessityDefaultDescription
endTimeOptionalrpClient.helpers.now()End time of the launch.
statusOptional''Status of launch, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'.

getPromiseFinishAllItems

getPromiseFinishAllItems - returns promise that contains status about all data has been sent to the reportportal. This method needed when test frameworks don't wait for async methods until finished.

// jasmine example. tempLaunchId - tempId of the launch started by the current client process
agent.getPromiseFinishAllItems(agent.tempLaunchId).then(() => done());
OptionNecessityDefaultDescription
tempLaunchIdRequiredtempId of the launch started by the current client process

updateLaunch

updateLaunch - updates the launch data. Will send a request to the server only after finishing the launch.

// launchObj - object returned by method 'startLaunch'
rpClient.updateLaunch(
    launchObj.tempId,
  {
        description: 'new launch description',
        attributes: [
            {
                key: 'yourKey',
                value: 'yourValue'
            },
            {
                value: 'yourValue'
            }
        ],
        mode: 'DEBUG'
    }
);

The method takes two arguments:

  • launch tempId (returned by the method 'startLaunch')
  • data object - may contain the following fields: description, attributes, mode. These fields can be looked up in the method startLaunch.

startTestItem

startTestItem - starts a new test item.

// launchObj - object returned by method 'startLaunch'
const suiteObj = rpClient.startTestItem({
        description: makeid(),
        name: makeid(),
        startTime: rpClient.helpers.now(),
        type: 'SUITE'
    }, launchObj.tempId);
const stepObj = rpClient.startTestItem({
        description: makeid(),
        name: makeid(),
        startTime: rpClient.helpers.now(),
        attributes: [

            {
                key: 'yourKey',
                value: 'yourValue'
            },
            {
                value: 'yourValue'
            }
        ],
        type: 'STEP'
    }, launchObj.tempId, suiteObj.tempId);

The method takes three arguments:

  • test item data object:
OptionNecessityDefaultDescription
nameRequiredTest item name
typeRequiredTest item type, one of 'SUITE', 'STORY', 'TEST', 'SCENARIO', 'STEP', 'BEFORE_CLASS', 'BEFORE_GROUPS','BEFORE_METHOD', 'BEFORE_SUITE', 'BEFORE_TEST', 'AFTER_CLASS', 'AFTER_GROUPS', 'AFTER_METHOD', 'AFTER_SUITE', 'AFTER_TEST'
hasStatsOptionaltrueChanges behavior for test item of type 'STEP'. When set to true, step is treaten as a test case (entity containig statistics). When false, step becomes a nested step.
descriptionOptional''Description of the test item (supports markdown syntax).
startTimeOptionalrpClient.helpers.now()Start time of the test item (unix time).
attributesOptional[]Array of the test item attributes.
  • launch tempId (returned by the method startLaunch)
  • parent test item tempId (optional) (returned by method startTestItem)

finishTestItem

finishTestItem - finish of the test item. After calling this method, you can not add items to the test item. The request to finish the test item will be sent only after all test items within it have finished.

// itemObj - object returned by method 'startTestItem'
rpClient.finishTestItem(itemObj.tempId, {
    status: 'failed'
})

The method takes two arguments:

  • test item tempId (returned by the method startTestItem)
  • data object:
OptionNecessityDefaultDescription
issueOptionaltrueTest item issue object. issueType is required, allowable values: 'pb', 'ab', 'si', 'ti', 'nd001'. Where *** is locator id
statusOptional'PASSED'Test item status, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'.
endTimeOptionalrpClient.helpers.now()End time of the launch (unix time).

Example issue object:

{
    issueType: 'string',
    comment: 'string',
    externalSystemIssues: [
        {
            submitDate: 0,
            submitter: 'string',
            systemId: 'string',
            ticketId: 'string',
            url: 'string'
        }
    ]
}

sendLog

sendLog - adds a log to the test item.

// stepObj - object returned by method 'startTestItem'
rpClient.sendLog(stepObj.tempId, {
    level: 'INFO',
    message: 'User clicks login button',
    time: rpClient.helpers.now()
})

The method takes three arguments:

  • test item tempId (returned by method startTestItem)
  • data object:
OptionNecessityDefaultDescription
messageOptional''The log message.
levelOptional''The log level, one of 'trace', 'debug', 'info', 'warn', 'error', ''.
timeOptionalrpClient.helpers.now()The time of the log.
  • file object (optional):
OptionNecessityDefaultDescription
nameRequiredThe name of the file.
typeRequiredThe file mimeType, example 'image/png' (support types: 'image/*', application/'xml', 'javascript', 'json', 'css', 'php', other formats will be opened in reportportal in a new browser tab only).
contentRequiredbase64 encoded file content.

mergeLaunches

mergeLaunches - merges already completed runs into one (useful when running tests in multiple threads on the same machine).

Note: Works only if isLaunchMergeRequired option is set to true.

rpClient.mergeLaunches({
    description: 'Regression tests',
    attributes: [
      {
        key: 'build',
        value: '1.0.0'
      }
    ],
    endTime: rpClient.helpers.now(),
    extendSuitesDescription: false,
    launches: [1, 2, 3],
    mergeType: 'BASIC',
    mode: 'DEFAULT',
    name: 'Launch name',
})

The method takes one argument:

  • merge options object (optional):
OptionNecessityDefaultDescription
descriptionOptionalconfig.description or 'Merged launch'Description of the launch (supports markdown syntax).
attributesOptionalconfig.attributes or []Array of launch attributes (tags).
endTimeOptionalrpClient.helpers.now()End time of the launch (unix time)
extendSuitesDescriptionOptionaltrueWhether to extend suites description or not.
launchesOptionalids of the launches saved to filesystemThe array of the real launch ids, not UUIDs
mergeTypeOptional'BASIC'The type of the merge operation. Possible values are 'BASIC' or 'DEEP'.
modeOptionalconfig.mode or 'DEFAULT''DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page.
nameOptionalconfig.launch or 'Test launch name'Name of the launch after merge.

Copyright Notice

Licensed under the Apache 2.0 license (see the LICENSE.txt file).

5.1.3

8 days ago

5.1.2

2 months ago

5.1.1

3 months ago

5.1.0

3 months ago

5.0.13

8 months ago

5.0.14

7 months ago

5.0.15

5 months ago

5.0.10

12 months ago

5.0.11

11 months ago

5.0.12

10 months ago

5.0.9

12 months ago

5.0.8

1 year ago

5.0.7

1 year ago

5.0.6

2 years ago

5.0.5

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago