Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Apr 23, 2020 18:56

With PerfectoActions, you can create maintenance scripts that handle the cleanup, reboot, 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 Perfecto native 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
  • Raise a Perfecto support ticket
  • Open your Perfecto cloud
  • Navigate to Perfecto documentation
  • 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.

On this 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 end-of-life (EOL) by the end of 2020, it is essential to adapt a different solution.

System configurations

We recommend 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:

    pip3 install perfectoactions -U
Note: 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.

AreaExampleSyntax to use
Device operationsList all available devices
perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>"
List all available devices with an optional feature to provide custom logo using the following syntax: -l "www.<<official website>>”
perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -l "www.perfecto.io"
List all available devices using your Perfecto username and password
perfectoactions -c "<<CLOUD NAME>>" -s "<<username/email>>:<<password>>"
List all devices irrespective of device status
perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -t all
Reboot, clean up, and get network settings for all devices, in parallel
perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -t "all" -a "reboot:true;cleanup:true;get_network_settings:true"

Limit the selection of devices by applying any/multiple Get Devices List parameters and regular expressions using the following syntax: {param1}:{value1};{param2}:{value2}

perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -d "model:Galaxy S.*;description:.*Genesis;dynamicField.ipa:Test-Android.*"
Get network settings (such as airplane mode, WiFi, and data) for available Samsung Galaxy devices only, in parallel
perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -a "get_network_settings:true" -d "model:Galaxy.*"
Repository cleanupDisplay 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 provided date"

The following example automatically displays repository media items older than 15 days.

perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -a "clean_repo|false|true|PUBLIC:John/Temp/,PRIVATE:Python,GROUP:John|15"
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 provided date"

The following example automatically deletes and displays repository media items older than 15 days.

perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -a "clean_repo|true|true|PUBLIC:John/Temp/,PRIVATE:Python,GROUP:John|15"
User list limitationLimit or filter the user list using the following syntax: -u "{param1}:{value1};{param2}:{value2}"
perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -u "roles:AUTOMATION;firstName:John"
GeneralRe-run the same execution with a specified sleep time
perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -r 1
Skip output in HTML format (for faster results in a command-line window)
perfectoactions -c "<<CLOUD NAME>>" -s "<<SECURITY TOKEN>>" -o false

Notes:

  • 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.
  • We recommend that you assign 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.
  • PerfectoActions is subject to the same restrictions and limitations as the Reboot device API, with regard to locked phones and limitations to reboot devices by certain manufacturers. For details, see Devices Restart Limitation. However, the latest version of PerfectoActions automatically skips, when trying to reboot, any manufacturers mentioned under Devices Restart Limitation.

Configure an experimental proxy

Note: This setup has not been tested yet.

To configure an experimental proxy:

  1. Configure proxies by setting the following environment variables:
    HTTP_PROXY
    HTTPS_PROXY
    For example:

    On Mac
    export HTTP_PROXY="10.10.1.10:3128"
    export HTTPS_PROXY="10.10.1.10:1080"
    
    On Windows
    set http_proxy=http://proxy.myproxy.com
    set https_proxy=https://proxy.myproxy.com
    
    
  2. To use HTTPS basic authentication with your proxy on Mac, try this: https://user:password@host:port

    On Mac
    export HTTP_PROXY="https://user:pass@10.10.1.10:3128/"
    export HTTPS_PROXY="https://user:pass@10.10.1.10:3128/"
    On Windows
    set HTTP_PROXY="https://user:pass@10.10.1.10:3128/"
    set HTTPS_PROXY="https://user:pass@10.10.1.10:3128/"
    Note: In usernames and passwords, avoid using 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.


Steps for Windows
  1. Open Task Scheduler.
  2. Create a new task and enter a descriptive name.

     Click to view image
  3. On the Triggers tab, click New.
  4. In the New Trigger dialog box, set the trigger as preferred. For example, select Daily to run the task daily.

     Click to view image
  5. On the Actions tab, click New.
  6. 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
  7. Edit the actions.bat file to supply your preferred arguments to perfectoactions on line 2.
    perfectoactions are triggered based on the trigger configuration.

     Click to view image

    Results will be displayed as shown in the following image, provided -o is not set to false in perfectoactions arguments.

     Click to view image

    Note: The report will be ready when the execution is complete.

Steps for Mac
  1. To get the physical path of perfectoactions, in a terminal window, type which perfectoactions.

     Click to view image
  2. Download a sample shell file from here: https://github.com/PerfectoMobileSA/Device_actions_reporter/blob/master/samples/actions.sh
  3. Edit the downloaded .sh file by setting the physical path of perfectoactions and applicable arguments.
  4. In a terminal window, navigate to the location to which you downloaded the sample shell file (actions.sh) and run the following command:

    chmod +x ./actions.sh
  5. 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.

     Click to view image
  6. In a terminal window, run the following command:

    crontab -e
  7. Press i and enter the following:

    {cron} /{path of actions.sh}/actions.sh >/{path of logs}/stdout.log 2>/{path of error logs}/stderr.log
    

    For example:
    30 2 * * * /Users/genesisthomas/Downloads/actions.sh >/tmp/stdout.log 2>/tmp/stderr.log

    Note: 30 2 * * * runs the cron job at 2:30 am every day.
  8. Press :wq! to save the file and click on OK in the confirmation form that opens.

     Click to view image
  9. To see whether the cron job is enabled, run the following command:

    crontab -l
  10. Verify the results.

     Click to view image

    Note: The report will be ready when the execution is complete.

Steps for Jenkins
  1. On Windows only: Start the Jenkins service logged on with a local user account.
  2. Log in to Jenkins.
  3. Go to Manage Jenkins > Manage Plugins and install the HTML Publisher plugin.
  4. Back on the Manage Jenkins page, navigate to the Script Console.
  5. In the Script Console, paste the following and click Run

    System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
     Click to view image
  6. Clear the browser history and cache, restart the browser, and log in to Jenkins.
  7. In Jenkins, create a new freestyle job.
  8. In the Build triggers section, enable the Build periodically option.
  9. In the Schedule section, enter your preferred cron schedule. For example, 30 2 * * * will run the job at 2:30 am every day.
  10. In the Build Environment section, enable the Delete workspace before build starts option.
  11. Add a build step, as follows.
    On Windows, execute a Windows batch command with the following commands included:

    pip 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 /B
    
     Click to view image

    On Mac, execute a shell with the following commands included:

    <<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 .
     Click to view image

    Notes:

    • Update the preferred values within <<>> as applicable.
    • To find the path of pip3/perfectoactions, in a terminal window, use the which command. For example, which pip3 will show the path of pip3.
  12. Add the following post-build actions:
    1. Archive artifacts with files in the results.html archive (see image above)
    2. Publish HTML reports with index page: result.html (see image above)
  13. To find the results.html being published as an HTML report, run the job.

     Click to view image

    Note: The report will be ready when the execution is complete.

  • No labels