Skip to content

Latest commit

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

PerfectoRestClientDemo

NodeJS Demo Client for Perfecto REST API.

Get started with Perfecto RESTful API, read more at our Community.

Install & dependencies:

  • Run npm install command within the project's directory.

Running tests:

  • The tests example here uses Jasmine testing framework.
  • Configure your Perfecto lab User, password and host at ClientConf.js.
  • Run the tests using npm test command.

Useage:

  • Require Perfecto library:
varPerfecto=require('../lib/Perfecto').Perfecto;
  • Creating a new client:
varclient=newPerfecto.PerfectoClient('https','MyHost.perfectomobile.com',MyUser,MyPassword);
varclient=newPerfecto.PerfectoClient(Conf.protocol,Conf.host,Conf.user,Conf.pass);
  • Starting a new execution, open device and browser navigation example:
client.startNewExecution().then((execution_Id)=>{returnclient.openDevice(deviceId);}).then((ans)=>{// ans = REST API response, JSON formatreturnclient.browserOpen();}).then((ans)=>{returnclient.browserGoTo('https://google.com');}).then((ans)=>{returnclient.browserClose();}).then((ans)=>{returnclient.closeDevice();}).then((ans)=>{returnclient.endExecution();}).catch((err)=>{logger.log(err);});
  • .then(ans) .... , the ans object contains the previous block response (JSON format).
.then((ans)=>{console.log(ans);// print the respone's body.//... do something}

More Functionalities:

  • Devices and Cradle Commands: The following devices and cradles commands are supported:
    Device info, device list, cradle info and cradle list.
    For example - getting devices list:
    After starting a new execution:
.then((ans)=>{returnclient.getDevicesList();}).then((ans)=>{console.log(ans);// Print list of the device in your cloud.});

Implementing a new command:

Consider the following function in the file PerfectoClient.js:

/** * Execute http get command *  * ### args ### * command = command name * subcommand = subcommand name * params = array with the following form ['param=ParamValue','param1=ParamValue' ....] *  * ### return ### * Promise */this.executeCommand=(command,subcommand,params)=>{letreq_url=this.base_url+'/'+this.executionId+'?'+'operation=command'+'&user='+this.user+'&password='+this.password+'&command='+command+'&subcommand='+subcommand;...// JavaScript code ...}

Use the executeCommand method to add your new command, for example:

this.myNewCommand=(Param)=>{letparams=['ParamName='+Param];returnthis.executeCommand('MyNewCommandName','MyNewCommandSubCommand',params);}

Make sure you add the command within the PerfectoClient object scope.

About

NodeJS Demo Client for Perfecto REST API

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages