Skip to content

Test Task Customization

OliverShen edited this page Jun 25, 2023 · 11 revisions

Add Attachments in a Test Task

On the Runner page, you can add attachments in a package set.

Supported File Type

Name Desc
Windows App Will be installed by the command like Add-AppxPackage -ForceApplicationShutdown -forceupdatefromanyversion before testing.
Common file Will be loaded to the Load Dir by the chosen Load Type
T2C Json Only work for T2C test.

Load Type

Only work when the File Type is Common file. Copy or unzip the attachment to Load Dir. image

Load Dir

Only work when the File Type is Common file and can't be empty. The format should be like firstLevelFolder/secondLevelFolder, and the firstLevelFolder will be generate under AgentInstallFolder.

image

Pre-install App

Put the packages of app to AgentInstallFolder/storage/preApp. When the devices plugin in, the packages would be installed. If install failed, the agent main process will be shutdown.

Grant permission

When trigger a test task, you can set up the permissions needed to be grant before testing.

["android.permission.FOREGROUND_SERVICE", "android.permission.FOREGROUND_SERVICE"]

image

Test Lifecycle Action Customization

Hydra Lab now allows for 2 levels of test lifecycle action customization: task-level customization through RESTful API JSON, and agent-level customization through an agent configuration file (change requires agent service restart to take effect). The task level has limited capabilities according to the current design.

Task-level customization

In the RESTful API, a test task is described as the TestTaskSpec object, where you can specify the device actions for each test run in the following structure: TestSpecDesign

When triggering a test task, you can customize some actions to set up the devices at different lifecycle stages. image For Example:

{
    "setUp": [{
            "method": "setProperty",
            "args": ["log.tag.WelcomeScreen", "Verbose"]
        }, {
            "method": "setProperty",
            "args": ["log.tag.ConsentDialog", "Verbose"]
        }, {
            "method": "backToHome",
            "args": []
        }
    ],
    "tearDown": [{
            "method": "setProperty",
            "args": ["log.tag.WelcomeScreen", " "]
        }, {
            "method": "setProperty",
            "args": ["log.tag.ConsentDialog", " "]
        }
    ]
}

Push File to Device

{
	"method": "pushFileToDevice",
	"args": ["filePathOnAgent","filePathOnDevice"]
}
  1. filePathOnAgent: It can be an absolute path like D:\file\Copy.ps1, also be a relative path under AgentInstallFolder like temp/111.txt
  2. filePathOnDevice: The file path on device. For example, /sdcard/Movies/testfile/

Pull File from Device

{
	"method": "pullFileFromDevice",
	"args": ["filePathOnDevice"]
}
  1. filePathOnDevice: It can be the path of folder like /sdcard/Movies/testfile/, also can be the path of file like /sdcard/Movies/testfile/aa.log

Agent-level customization: shell command support

The commands can be configured in application.yml.

  1. type: command type.
  • ADBShell: Running ADB shell command on the Android test device.
  • AgentShell: Running Powershell command on Windows agent and sh command on the Mac agent (not implemented yet).
  1. when: setUp or tearDown. Used to specify the execute timing.
  2. suite-class-matcher: Regular expression. Used to match the suite class of test task.
  3. inline: Command script. Will be executed line-by-line on target device.

For example,

#  Available Hydra Lab Variables In Script:
#  $HydraLab_TestResultFolderPath: The full path of the test result folder
#  $HydraLab_deviceUdid: The UDID of mobile device. (For Android, it will be equal to the serial number)
app:
  device-script:
    commands:
      - type: ADBShell
        when: setUp
        suite-class-matcher: '.*'
        inline: |
          rm -rf /sdcard/Movies/testfile2
          mkdir /sdcard/Movies/testfile2
          cp /sdcard/Movies/testfile/*  /sdcard/Movies/testfile2
      - type: ADBShell
        when: tearDown
        suite-class-matcher: '.*'
        inline: |
          rm -rf /sdcard/Movies/testfile2
      - type: AgentShell
        when: setUp
        suite-class-matcher: '.*test.*'
        inline: |
          python save_data_to_file.py "$HydraLab_TestResultFolderPath/$HydraLab_deviceUdid"
      - type: AgentShell
        when: tearDown
        suite-class-matcher: 'com.microsoft.test'
        inline: |
          rm -rf "$HydraLab_TestResultFolderPath/$HydraLab_deviceUdid"
Clone this wiki locally