---
tags: Rapi Document English
---
# Rapi API Document (NodeJS)
## Requirment
1. Selenium Server (Grid) (Version recommend >= 4.8)
2. [Rapi-runner](https://github.com/RapiTest/rapi-runner/releases)
3. Install Rapi API
```bash
$ npm install @rapitest/rapi-api
```
## Rapi Config Document
* Before using the Rapi API, you need to know our Rapi runner config file schema. You can learn more about it [here](https://hackmd.io/@Rapi/rapi-runner-config-file).
## Quick Start
```javascript
import { ConfigBuilder, Browser, createRapi } from "rapi";
const config = new ConfigBuilder()
.setTestSuites(["path/to/testSuites"])
.addBrowser("http://url.to.selenium.server", { browserName: "firefox" })
.build();
const rapi = createRapi(
"path/to/rapi/runner",
config
);
const report = rapi.run();
console.log(report.json.reports[0].failureCaseNum);
```
---
# API
## Rapi
### `createRapi(runnerPath, config)`
#### Description
Create a rapi object by giving the executable rapi-runner path and config
#### Parameters
* runnerPath: The executable rapi-runner path
* config: Config create by ConfigBuilder or config file.
#### Example
```javascript=
const config = createConfig("path/to/config.json");
const rapi = createRapi(
"path/to/rapi/runner",
config
);
```
### `run()`
#### Description
The function will run the test depend on the config you set, after finish the test it will pass the report back.
#### Example
```javascript
const config = createConfig("path/to/config.json");
const rapi = createRapi(
"path/to/rapi/runner",
config
);
const report = rapi.run();
```
---
## Config
### `createConfig(filePath)`
#### Description
It will create a Config object base on the input file
#### Example
```javascript=
// generate the config base on the config file
const config1 = createConfigFromFile("/path/to/config.json")
```
---
## ConfigBuilder
The config format is define in [Rapi Config File Format](https://hackmd.io/@sideex/book/%2F%40sideex%2Frunner#Appendix-A---SideeX-Runner-Config-File-Format)
### `setPlay(options)`
#### Description
Set Config object's play config
#### Example
```javascript
config.setPlay({noLog:true})
```
### `setTestSuites(string[])`
#### Example
```javascript
config.setTestSuites(["path/to/test1.json","path/to/test2.json"]);
```
### `setReport(options)`
#### Example
```javascript=
config.setReport({snapshotQuality:100})
```
### `setWebdriveri18n(i18n)`
#### Example
```javascript=
config.setWebdriveri18n({"ja": "./ja.json"})
```
### `setVariables(variables)`
#### Example
```javascript
config.setVariables(["path/to/variables1.json","path/to/variables2.json"]);
```
### `setDataDriven(dataDriven)`
#### Example
```javascript
config.setDataDriven(["path/to/dataDriven1.json","path/to/dataDriven2.json"]);
### `setWebdriverConfig(webdriverConfig)`
#### Example
```javascript=
config.setWebdriverConfig([{
serverUrl: "http://localhost:4444",
type: "selenium",
browsers: [Browser.CHROME],
}])
```
### `addBrowser(serverUrl, capability)`
#### Example
```javascript
config.addBrowser("http://url.to.selenium.server", { browserName: "firefox" })
```
## Report Format
```json=
{
version: {
"sideex": [
3,
7,
3
],
"format": [
1,
0,
1
]
},
"Reports":[
{
title: "20221006 12-46-49",
sessionId: "",
type: "chrome",
browser: "chrome 103.0.5060.134",
platform: "linux",
deviceName: "unknown",
lang: null,
inputFile: "/home/fourcolor/Documents/sideex/sideex-2021/modules/main/dist/test-jobs/214e8cd6-94db-4b32-993a-8cf9af0aa04f/inputs/suites/test1.json",
startTime: "20221006 12:46:49",
endTime: "20221006 12:47:02",
failureCaseNum: 0,
failureSuiteNum: 0,
successCaseNum: 1,
successSuiteNum: 1,
logs: [
{
type: "info",
message: "Playing test suite Untitled Test Suite 2"
},
],
status: "completed",
suites: [
{
title: "Untitled Test Suite 2",
idText: "suite-20",
status: "success",
cases: [
0
]
}
],
cases: [
{
title: "Untitled Test Case 2",
idText: "case-20",
suiteIdText": "suite-20",
status: "success",
localVars: [],
globalVars: [],
records: [
{
"name": "open",
"target": "https://sideex.io/",
"value": "",
"status": "success",
"time": 4175,
"valData": []
},
{
"name": "setViewportSize",
"target": "",
"value": "1848,948",
"status": "warn",
"time": 744,
"valData": []
},
...
]
}
],
snapshot: {
"image-162": {
//base64 image
}
}
},
{
...
}
]
}
```
<!-- > deprecate
> ### `getState()`
> ### `downloadReport()`
> ### `deleteJob()`
> ### `runTestSuite(file)` -->