NodeJS Demo Client for Perfecto REST API.
Get started with Perfecto RESTful API, read more at our Community.
- Run
npm installcommand within the project's directory.
- The tests example here uses Jasmine testing framework.
- Configure your Perfecto lab User, password and host at ClientConf.js.
- Run the tests using
npm testcommand.
- Require Perfecto library:
varPerfecto=require('../lib/Perfecto').Perfecto;- Creating a new client:
varclient=newPerfecto.PerfectoClient('https','MyHost.perfectomobile.com',MyUser,MyPassword);- Use the ClientConf.js file to setup the test configuration.
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}- 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.});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.