@abhijoseph/reportportal-client 中文文档教程

发布于 5年前 浏览 19 项目主页 更新于 3年前

构建状态代码覆盖率npm version

ReportPortal js client

此客户端用于与节点 js 上的报告门户通信。

库仅用于 ReportPortal 的自定义侦听器的实现者。

Already implemented listeners:

  • EMPTY

Installation

最新版本在 npm 上可用:

npm install reportportal-client

Example

let RPClient = require('reportportal-client');

let rpClient = new RPClient({
    token: "00000000-0000-0000-0000-000000000000",
    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.full_name}`);
}, (error) => {
    console.log('Error connection to server');
    console.dir(error);
});

Settings

创建客户端实例时,需要指定以下参数:

ParameterDescription
tokenuser's token Report Portal from which you want to send requests. It can be found on the profile page of this user.
endpointURL 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'.
launchName of launch at creation.
projectThe name of the project in which the launches will be created.

Api

每个方法(checkConnect 除外)返回一个特定格式的对象:

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

客户端同步工作,因此无需等待发送后续请求的先前请求结束。

checkConnect

checkConnect - 用于验证客户端连接正确性的异步方法

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

startLaunch

startLaunch - 开始新的启动,返回要用于此启动中所有项目的临时 ID。

let launchObj = rpClient.startLaunch({
    name: "Client test",
    start_time: rpClient.helpers.now(),
    description: "description of the launch",
    tags: ["tag1", "tag2"],
    //this param used only when you need client to send data into the existing launch
    id: 'id'
});
console.log(launchObj.tempId);

该方法采用一个参数:

  • launch data object:
ParameterDescription
start_time(optional) start time launch(unix time). Default: rpClient.helpers.now()
name(optional) launch name. Default: parameter 'launch' specified when creating the client instance
mode(optional) "DEFAULT" or "DEBUG". Default: "DEFAULT"
description(optional) description of the launch (supports markdown syntax)
tags(optional) array of launch tags
idid of the existing launch in which tests data would be sent, without this param new launch instance would be created

要知道真正的启动 ID 等待方法完成(客户端不使用真实 ID)

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

finishLaunch

finishLaunch - 启动完成。 调用该方法后,不能再向launch中添加items。 只有在其中的所有项目都完成后,才会发送完成启动的请求。

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

该方法有两个参数:

  • id launch (returned by method 'startLaunch')
  • data object:
ParameterDescription
end_time(optional) end time of launch. Default: rpClient.helpers.now()
status(optional) status of launch, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "RESTED", "CANCELLED". Default: "".

getPromiseFinishAllItems

getPromiseFinishAllItems - 返回包含所有数据状态的承诺,这些数据已发送到 Report Protal。 当测试框架不等待异步方法并停止处理时需要此方法。

// jasmine example. tempLaunchId - id of the client's process
agent.getPromiseFinishAllItems(agent.tempLaunchId).then(()=> done());
ParameterDescription
tempLaunchIdid of the client's process

updateLaunch

updateLaunch - 更新启动数据。 启动完成后才会向服务器发送请求。

// launchObj - object returned by method 'startLaunch'
rpClient.updateLaunch(
    launchObj.tempId, {
        description: 'new launch description',
        tags: ['new_tag1', 'new_tag2'],
        mode: 'DEBUG'
    }
);

该方法有两个参数:

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

startTestItem

startTestItem - 启动一个新的测试项目。

// launchObj - object returned by method 'startLaunch'
let suiteObj = rpClient.startTestItem({
        description: makeid(),
        name: makeid(),
        start_time: rpClient.helpers.now(),
        type: "SUITE"
    }, launchObj.tempId);
let stepObj = rpClient.startTestItem({
        description: makeid(),
        name: makeid(),
        start_time: rpClient.helpers.now(),
        tags: ['step_tag', 'step_tag2', 'step_tag3'],
        type: "STEP"
    }, launchObj.tempId, suiteObj.tempId);

该方法采用三个参数:

  • test item data object:
ParameterDescription
nameitem name
typeItem type, one of 'SUITE', 'STORY', 'TEST', 'SCENARIO', 'STEP', 'BEFORECLASS', 'BEFOREGROUPS','BEFOREMETHOD', 'BEFORESUITE', 'BEFORETEST', 'AFTERCLASS', 'AFTERGROUPS', 'AFTERMETHOD', 'AFTERSUITE', 'AFTERTEST'
description(optional) description of the launch (supports markdown syntax)
start_time(optional) start time item(unix time). Default: rpClient.helpers.now()
tags(optional) array of item tags
  • id launch (returned by method 'startLaunch')
  • id parent item (optional) (returned by method 'startTestItem')

finishTestItem

finishTestItem - 项目的完成。 调用该方法后,不能向项目中添加项目。 完成该项目的请求将仅在其中的所有项目都完成后发送。

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

该方法采用两个参数:

  • id item (returned by method 'startTestItem')
  • data object:
ParameterDescription
end_time(optional) end time of launch. Default: rpClient.helpers.now()
status(optional) item status, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "RESTED", "CANCELLED". Default: "PASSED".
issue(optional) object issue

示例问题对象:

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

sendLog

sendLog - 向项目添加日志

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

该方法采用三个参数:

  • id item (returned by method 'startTestItem')
  • data object:
ParameterDescription
time(optional) time of log. Default: rpClient.helpers.now()
message(optional) log message. Default: ''.
status(optional) log status, one of 'trace', 'debug', 'info', 'warn', 'error', ''. Default "".
  • file object (optional):
ParameterDescription
namefile name
typefile mimeType, example "image/png" (support types: 'image/*', application/ ['xml', 'javascript', 'json', 'css', 'php'] , another format will be opened in a new browser tab ),
contentfile

Copyright Notice

GPLv3 许可证(请参阅 LICENSE.txt 文件)。

Build StatusCode Coveragenpm version

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:

  • EMPTY

Installation

The latest version is available on npm:

npm install reportportal-client

Example

let RPClient = require('reportportal-client');

let rpClient = new RPClient({
    token: "00000000-0000-0000-0000-000000000000",
    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.full_name}`);
}, (error) => {
    console.log('Error connection to server');
    console.dir(error);
});

Settings

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

ParameterDescription
tokenuser's token Report Portal from which you want to send requests. It can be found on the profile page of this user.
endpointURL 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'.
launchName of launch at creation.
projectThe name of the project in which the launches will be created.

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.

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.full_name}`);
}, (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 all of the items within this launch.

let launchObj = rpClient.startLaunch({
    name: "Client test",
    start_time: rpClient.helpers.now(),
    description: "description of the launch",
    tags: ["tag1", "tag2"],
    //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:
ParameterDescription
start_time(optional) start time launch(unix time). Default: rpClient.helpers.now()
name(optional) launch name. Default: parameter 'launch' specified when creating the client instance
mode(optional) "DEFAULT" or "DEBUG". Default: "DEFAULT"
description(optional) description of the launch (supports markdown syntax)
tags(optional) array of launch tags
idid of the existing launch in which tests data would be sent, without this param new launch instance would be created

To know the real launch id wait for the method to finish (the real id is not used by the client)

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

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'
let launchFinishObj = rpClient.finishLaunch(launchObj.tempId, {
    end_time: rpClient.helpers.now()
});

The method takes two arguments:

  • id launch (returned by method 'startLaunch')
  • data object:
ParameterDescription
end_time(optional) end time of launch. Default: rpClient.helpers.now()
status(optional) status of launch, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "RESTED", "CANCELLED". Default: "".

getPromiseFinishAllItems

getPromiseFinishAllItems - returns promise that contains status about all data has been sent to the Report Protal. This method needed when test frameworks don't wait for async methods and stop processed.

// jasmine example. tempLaunchId - id of the client's process
agent.getPromiseFinishAllItems(agent.tempLaunchId).then(()=> done());
ParameterDescription
tempLaunchIdid of the client's process

updateLaunch

updateLaunch - updates 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',
        tags: ['new_tag1', 'new_tag2'],
        mode: 'DEBUG'
    }
);

The method takes two arguments:

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

startTestItem

startTestItem - starts a new test item.

// launchObj - object returned by method 'startLaunch'
let suiteObj = rpClient.startTestItem({
        description: makeid(),
        name: makeid(),
        start_time: rpClient.helpers.now(),
        type: "SUITE"
    }, launchObj.tempId);
let stepObj = rpClient.startTestItem({
        description: makeid(),
        name: makeid(),
        start_time: rpClient.helpers.now(),
        tags: ['step_tag', 'step_tag2', 'step_tag3'],
        type: "STEP"
    }, launchObj.tempId, suiteObj.tempId);

The method takes three arguments:

  • test item data object:
ParameterDescription
nameitem name
typeItem type, one of 'SUITE', 'STORY', 'TEST', 'SCENARIO', 'STEP', 'BEFORECLASS', 'BEFOREGROUPS','BEFOREMETHOD', 'BEFORESUITE', 'BEFORETEST', 'AFTERCLASS', 'AFTERGROUPS', 'AFTERMETHOD', 'AFTERSUITE', 'AFTERTEST'
description(optional) description of the launch (supports markdown syntax)
start_time(optional) start time item(unix time). Default: rpClient.helpers.now()
tags(optional) array of item tags
  • id launch (returned by method 'startLaunch')
  • id parent item (optional) (returned by method 'startTestItem')

finishTestItem

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

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

The method takes two arguments:

  • id item (returned by method 'startTestItem')
  • data object:
ParameterDescription
end_time(optional) end time of launch. Default: rpClient.helpers.now()
status(optional) item status, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "RESTED", "CANCELLED". Default: "PASSED".
issue(optional) object issue

Example issue object:

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

sendLog

sendLog - adds a log to the item

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

The method takes three arguments:

  • id item (returned by method 'startTestItem')
  • data object:
ParameterDescription
time(optional) time of log. Default: rpClient.helpers.now()
message(optional) log message. Default: ''.
status(optional) log status, one of 'trace', 'debug', 'info', 'warn', 'error', ''. Default "".
  • file object (optional):
ParameterDescription
namefile name
typefile mimeType, example "image/png" (support types: 'image/*', application/ ['xml', 'javascript', 'json', 'css', 'php'] , another format will be opened in a new browser tab ),
contentfile

Copyright Notice

Licensed under the GPLv3 license (see the LICENSE.txt file).

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文