Deploy device maintenance scripts (Perfecto IDE alternative)
With PerfectoActions, you can create device maintenance scripts that handle the cleanup, reboot, reservation, and retrieval of network settings in parallel and across all or specific devices in the Perfecto lab. In addition, you can set up scheduling for these scripts to run at the desired interval, depending on the devices involved. You can also view or delete old media repository items and list all or specific users automatically. Device manufacturers that do not support auto-connect on reboot are skipped automatically.
This non-flash, non-native, multi-threaded solution replaces the following Perfectonative automation commands: clean device
, reboot device
, and get network settings
. For more details and samples, see this GitHub project: https://github.com/PerfectoMobileSA/Device_actions_reporter
The results appear in a fully responsive, dark-mode themed, accessible HTML report with direct access to available devices and the option to:
- Search for devices and users in the displayed HTML table
- View direct API results for clean and restart commands
- Open your Perfecto cloud
- Get information on device status, model, OS version, SIM operator graphs, and users.
- View a complete device status and user list summary
- View accurate, expandable graphs, also available in full-screen view
- Download a full Get Devices List API response as well as a User API response based on your own requirements as a Microsoft Excel file
The following image shows a sample results page.
Why maintenance is important
Devices that form part of the individual clouds are real devices and as such not built for 24/7 usage under full load. Maintenance of these devices should therefore contain a reboot, among other checks, and be either run by a schedule (for example daily or weekly) or triggered by an action (for example before each main regression suite). The frequency depends on the amount of tests run and the model of devices. Generally, the more tests we execute against a specific device, and the older (or less reliable) the device is, the more often we should reboot the device.
A maintenance script or suite, which would consist of a number of maintenance actions to be performed, can be set up to run in parallel on specified devices.
Actions could include rebooting the device, recovering, resetting WiFi (switching off-on), verifying internet connectivity, verifying if the mobile network or WiFi is connected, installing and uninstalling required apps, and so on.
You can implement maintenance scripts in Appium/Selenium with a programming language of your choice, by using pure REST API calls, or by using PerfectoActions. Previously, it was also possible to use the Perfecto IDE, but with Flash being deprecated by the end of 2020, it is essential to adapt a different solution.
System configurations
Consider the following configuration settings:
- At least 8 GB RAM
- At least 2.20 GHz multicore processors
Prerequisites
Using PerfectoActions for your maintenance script requires that you:
- Install Python version 3+ and set it as default.
- Install pip. If you experience proxy issues when installing pip, see Configure an experimental proxy.
-
Run the following command from a command-line window:
Copypip3 install perfectoactions -U
Google Chrome and Apple Safari are the preferred browsers. If using Microsoft Internet Explorer, make sure to enable active scripting.
Usage
perfectoactions [-h] [-c cloud_name] [-s security_token]
[-d [device_list_parameters]]
[-u [user_list_parameters]]
[-t [Different types of Device Connection status]]
[-a [actions]] [-r [refresh]] [-o [output in html]]
[-l [shows customer logo]]
optional arguments:
-h, --help show this help message and exit
-c cloud_name, --cloud_name cloud_name
Perfecto cloud name. (E.g. demo)
-s security_token, --security_token security_token
Perfecto Security Token/ Pass your Perfecto's username and password in user:password format
-d [device_list_parameters], --device_list_parameters [device_list_parameters]
Perfecto get device list API parameters to limit device list. Support all API capabilities which selects devices based on reg ex/strings, Leave it empty to select all devices
-u [user_list_parameters], --user_list_parameters [user_list_parameters]
Perfecto get user list API parameters to limit user list. Support all API capabilities which selects users based on applicable parameters, Leave it empty to select all users
-t [Different types of Device Connection status], --device_status [Different types of Device Connection status]
Different types of Device Connection status. Values: all. This will showcase all the device status like Available, Disconnected, un-available & Busy. Note: Only Available devices will be shown by default
-a [actions], --actions [actions]
Perfecto actions seperated by semi-colon. E.g. reboot:true;cleanup:true;get_network_settings:true
-r [refresh], --refresh [refresh]
Refreshes the page with latest device status as per provided interval in seconds
-o [output in html], --output [output in html]
output in html. Values: true/false. Default is true
-l [shows customer logo], --logo [shows customer logo]
shows client logo if valid official client website url is specified in this sample format: www.perfecto.io
Examples
Following is a list of usage examples.
Area | Example | Syntax to use |
---|---|---|
Device operations | List all available devices |
Copy
|
Device operations | List all available devices with an optional feature to provide custom logo using the following syntax: -l "www.<<official website>>” |
Copy
|
Device operations | List all available devices using your Perfecto username and password |
Copy
|
Device operations | List all devices irrespective of device status |
Copy
|
Device operations | Reboot, clean up, and get network settings for all devices, in parallel |
Copy
|
Device operations |
Limit the selection of devices by applying any/multiple Get Devices List parameters and regular expressions using the following syntax: |
Copy
|
Device operations | Get network settings (such as airplane mode, WiFi, and data) for available Samsung Galaxy devices only, in parallel |
Copy
|
Device operations | Reboot devices that are reserved by a specific user |
Copy
|
Reservation |
Reserve device time, in minutes (minimum: 15). Can be combined with other device operations, such as cleanup. |
Copy
|
Repository cleanup | Display older repository items using the following syntax: -a "clean_repo|false|do you have admin role? - true(false)|media repository locations|number of days to select items older than the current date" |
The following example automatically displays repository media items older than 15 days. Copy
|
Repository cleanup | Automatically delete older repository items using the following syntax:-a "clean_repo|true|do you have admin role? - true(false) |media repository locations|number of days to select items older than the current date" |
The following example automatically deletes and displays repository media items older than 15 days. Copy
|
User list limitation | Limit or filter the user list using the following syntax: -u "{param1}:{value1};{param2}:{value2}" |
Copy
|
General | Re-run the same execution with a specified sleep time |
Copy
|
General | Skip output in HTML format (for faster results in a command-line window) |
Copy
|
General | Override the count of parallel threads in case of limited CPU cores. In the code example, 2 parallel threads are defined. |
Copy
|
If you want to enable non-admin users to delete media repository files for users who have access to the same group folder, contact Perfecto Support.
Consider assigning a unique description or dynamicField
for devices that are applicable for reboot and utilize the -d
parameter for reboot. See the Limit the selection of the devices example.
Configure an experimental proxy
To configure an experimental proxy:
-
Configure proxies by setting the following environment variables:
HTTP_PROXY
HTTPS_PROXY
For example:
-
To use HTTPS basic authentication with your proxy on Mac, try this: https://user:password@host:port
CopyOn Macexport HTTP_PROXY="https://user:pass@10.10.1.10:3128/"
export HTTPS_PROXY="https://user:pass@10.10.1.10:3128/"CopyOn Windows
set HTTP_PROXY="https://user:pass@10.10.1.10:3128/"
set HTTPS_PROXY="https://user:pass@10.10.1.10:3128/"Restriction: Usernames and passwords cannot contain special characters such as :,@.
Set up scheduling
This section walks you through the steps for setting up the automatic scheduler on Windows, on Mac, or in Jenkins. Expand the steps that apply to you.
- Open Task Scheduler.
-
Create a new task and enter a descriptive name.
- On the Triggers tab, click New.
-
In the New Trigger dialog box, set the trigger as preferred. For example, select Daily to run the task daily.
- On the Actions tab, click New.
-
Browse to the
actions.bat
file. A sample.bat
file is available here:https://github.com/PerfectoMobileSA/Device_actions_reporter/blob/master/samples/actions.bat
-
Edit the
actions.bat
file to supply your preferred arguments toperfectoactions
on line 2.perfectoactions
are triggered based on the trigger configuration.Results will be displayed as shown in the following image, provided
-o
is not set tofalse
inperfectoactions
arguments.The report will be ready when the execution is complete.
-
To get the physical path of
perfectoactions
, in a terminal window, typewhich perfectoactions
. -
Download a sample shell file from here:
https://github.com/PerfectoMobileSA/Device_actions_reporter/blob/master/samples/actions.sh
- Edit the downloaded
.sh
file by setting the physical path ofperfectoactions
and applicable arguments. -
In a terminal window, navigate to the location to which you downloaded the sample shell file (
actions.sh
) and run the following command:Copychmod +x ./actions.sh
-
To grant
cron
full disk access, in System Preferences > Security & Privacy, on the Privacy tab, drag/usr/sbin/cron
into the Full Disk Access area. -
In a terminal window, run the following command:
Copycrontab -e
-
Press
i
and enter the following:Copy{cron} /{path of actions.sh}/actions.sh >/{path of logs}/stdout.log 2>/{path of error logs}/stderr.log
For example:
30 2 * * * /Users/<name>/Downloads/actions.sh >/tmp/stdout.log 2>/tmp/stderr.log
30 2 * * *
runs thecron
job at 2:30 am every day. -
Press
:wq!
to save the file and click on OK in the confirmation dialog box that opens. -
To see whether the
cron
job is enabled, run the following command:Copycrontab -l
-
Verify the results.
The report will be ready when the execution is complete.
- On Windows only: Start the Jenkins service logged on with a local user account.
- Log in to Jenkins.
- Go to Manage Jenkins > Manage Plugins and install the HTML Publisher plugin.
- Back on the Manage Jenkins page, navigate to the Script Console.
-
In the Script Console, paste the following and click Run:
CopySystem.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
- Clear the browser history and cache, restart the browser, and log in to Jenkins.
- In Jenkins, create a new freestyle job.
- In the Build triggers section, enable the Build periodically option.
- In the Schedule section, enter your preferred
cron
schedule. For example,30 2 * * *
will run the job at 2:30 am every day. - In the Build Environment section, enable the Delete workspace before build starts option.
-
Add a build step, as follows.
On WindowsExecute a Windows batch command with the following commands included. Update the preferred values within
<<>>
as applicable.Copypip install -U perfectoactions
del /s /q "C:\Users\<<Windows user name>>\AppData\Local\Temp\output\*.*"
perfectoactions -c <<CLOUD NAME, e.g. demo>> -s "<<SECURITY TOKEN>>" <<ADDITIONAL ARGUMENTS AS APPLICABLE>>
xcopy /s "C:\Users\<<Windows user name>>\AppData\Local\Temp\output" .
EXIT /BOn MacExecute a shell with the following commands included:
Copy<<PATH TO PIP>>/pip3 install -U perfectoactions
rm -rf "/tmp/output/*.*"
perfectoactions -c <<CLOUD NAME, e.g. demo>> -s "<<SECURITY TOKEN>>" <<ADDITIONAL ARGUMENTS AS APPLICABLE>>
cp /tmp/output/result.html .Important: To find the path ofpip3/perfectoactions
, in a terminal window, use thewhich
command. For example,which pip3
will show the path ofpip3
. - Add the following post-build actions:
- Archive artifacts with files in the
results.html
archive (see image above) - Publish HTML reports with index page: result.html (see image above)
- Archive artifacts with files in the
-
To find the
results.html
being published as an HTML report, run the job.The report will be ready when the execution is complete.
-
In TeamCity, create a new project.
-
Provide the repository URL https://github.com/PerfectoMobileSA/Device_actions_reporter and your GitHub credentials. Then click Proceed twice.
TeamCity autodetects the sample shell and bat scripts.
-
Select the required script (
.bat
on Windows and.sh
on Mac) and click Use selected. -
Click Edit.
-
In the Custom script field, edit the code with trailing sample for Mac (sample) by updating your cloud name, the Perfecto security token, and additional arguments, as applicable. Then click Save.
Copy#!/bin/sh
pip3 install -U perfectoactions
rm -rf "/tmp/output/*.*"
perfectoactions -c <<CLOUDNAME>> -s <<SECURITY TOKEN>> <<ADDITIONAL ARGUMENTS AS PER DOCUMENTATION>>
cp /tmp/output/result.html . -
Under General settings, in the Artifact paths field, enter
result.html
. Then click Save. -
To configure the build schedule, follow the instructions at https://www.jetbrains.com/help/teamcity/configuring-schedule-triggers.html.
-
To execute PerfectoActions in TeamCity, click Run. Then view the results on the Artifacts tab.
-
Clone this project to your preferred Git.
-
Log in to your Azure dev environment at https://azure.microsoft.com/en-us/products/devops/.
-
If needed, create a new project.
-
Create a new pipeline and select the previously cloned project.
-
Apply the Python package template.
-
Click Build and Test and select Parallelism as None.
-
Update the Python version with version spec 3.7.
-
Update Install dependencies with the following script:
Copypython -m pip install --upgrade pip && pip install -I perfectoactions
-
To the right of Build and Test, click the + (plus) symbol and select to add a command line script. Then include the following script, replacing
<<cloud name>>
with your cloud name. For example,demo
is the cloud name ofdemo.perfectomobile.com
.Copyperfectoactions -a "cleanup:true;reboot:true;get_network_settings:true;" -c <<cloud name>> -s $(securityToken) -l www.perfecto.io
-
On the Variables tab, do the following:
-
Create a variable called securityToken and assign your Perfecto security token as the value.
-
Click the lock symbol to encrypt the security token.
-
-
Add Publish Pipeline Artifact with the directory path
/tmp/output/
and the artifact nameresult
. -
Remove any other unnecessary build steps that are not part of the screenshot in the previous step.
-
Schedule this pipeline according to your needs. For more information, see https://docs.microsoft.com/en-gb/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=classic.
-
Run tests on Linux machines. Results will be published within the result artifact.