Skip to content

Deploy a test agent service

Nathan Bu edited this page Feb 21, 2023 · 38 revisions

If you are a Microsoft FTE and want to onboard to the internal Hydra Lab testing service, please visit our SharePoint site to learn more about the internal service instance.

Set Up Your PC Environment

For Android Agent

You can try the installer-Android.ps1 script to set up a new Windows agent for Android if the PC is brand new or its environment is clean enough. Hydra_Agent_Installer_Windows.zip. We are leveraging the winsw to wrap and manage the Spring Boot agent Jar application as a Windows service.

For iOS-Windows agent, the following 2 tools need to be installed

  1. Install iTunes on Microsoft store (The iOS devices need to connected to iTunes and set as a trusted device).
  2. Install tidevice: pip3 install -U "tidevice[openssl]"
  3. We also provide a script named as installer-iOS.ps1 for iOS-Windows agent. installer.zip

iOS-Mac agent

  1. Install: You can run the installer.sh script in this zip Hydra_Agent_Installer_Mac.zip to setup the environment.
  2. Restart: Install: You can run the restartAgent.sh script in zip of first step.

You can also set up manually.

1. Install dev kits:

The following are fundamental:

  1. Install JDK/JRE (at least JDK 11)
  2. Install Android SDK
  3. Install FFmpeg: Download ffmpeg-release-essentials.7z, unzip and add bin folder into PATH

The following are required for the Appium test runner:

  1. Install Node.js
  2. Install Appium execute npm install -g appium
  3. Install WinAppdriver 1.2.1

And the below is for smart test runner: Required for smart test: Install Python 3.7+ link

2. Config Environment Variables - System variables

Below is a table of configuration samples:

Type Variable Name Value
Java JAVA_HOME C:\Program Files\Java\jdk-11.0.14
Java Path %JAVA_HOME%\bin
Python Path C:\Python38|
Python Path C:\Python38\Scripts|
FFmpeg Path C:\Program Files\ffmpeg-4.4.1-essentials_build\bin
Android ANDROID_HOME C:\Users\demo\AppData\Local\Android\Sdk
Android ANDROID_PLATFORM_TOOLS C:\Users\demo\AppData\Local\Android\Sdk\platform-tools
Android Path %ANDROID_HOME%\platform-tools
Node NODE_PATH C:\Users\demo\AppData\Roaming\npm\node_modules
Node Path C:\Users\demo\AppData\Roaming\npm;C:\Program Files\nodejs
Appium APPIUM_BINARY_PATH C:\Users\demo\AppData\Roaming\npm\node_modules\appium\build\lib\main.js

Setup Hydra Lab Agent on Windows

  1. Register an agent in Hydra Lab Center WebSite. (Please contact hydra_lab_support@microsoft.com if you are Microsoft FTE and want to use the MS internal network)

image

  1. Create a new folder in you PC.
  2. Download the latest agent.jar or build the agent project as agent.jar. Then, copy the file to the folder. To build the agent, run the following command in the project root dir:
gradlew :agent:bootJar
  1. Unzip Hydra_Agent_Installer_Windows.zip to the folder, the folder shows like this picture.

image

  1. Download application.yml from portal (a sample configuration is available here: sample YAML config)

image

  • app.registry.server
    • The hostname + port of the center server. For instance, if it's running on a machine with the hostname of testagent.hydralab.com and servicing on port 9886, then this value should be "testagent.hydralab.com:9886".
  • app.registry.id
  • app.registry.secret
  • app.registry.name
  • app.registry.agent-type (An int value to indicate the type of test devices for Testing)
    • Value 1 represents WINDOWS PC + n * ANDROID devices -> For Android test agent.
    • Value 2 represents WINDOWS PC + 1 * ANDROID device, support running Appium Test case on Windows -> For Windows-Android cross-platform agent.
    • Value 3 represents WINDOWS/MAC PC + n * iOS devices -> For iOS test agent.
  • management.metrics.export.prometheus.pushgateway.enabled (Optional; If true, will send metrics to our stability monitor. When an exception happens, we will receive emails.)

Start/Stop Hydra Lab Agent

1. Android or iOS agent

  1. Setup log file location: modify AgentService.xml and replace {LOG_FILE_LOCATION}

  2. Install it as a Windows Service: open cmd/powershell (admin), execute command : .\AgentService.exe install

image

  1. Open Windows Services and find a service named Hydra Lab Agent Service.

image

  1. You can start/stop the service.

image

  1. If it starts successfully, the agent will show up in HydraLab center portal. BTW, only the agent connected with devices will be displayed on the page.

image

2. Cross-platform agent (Windows + Android)

PS. The WinAppDriver can't work normally if started by Windows Service.Issue link

  1. Update restartAgent.bat: comment line18,31 and uncomment line 20,29.

image

  1. Start agent directly: open cmd/powershell (admin); cd to the install folder; execute restartAgent.bat script

If you want to keep your Windows test agent awake without locking itself over time, so as to run UI tests for Windows apps, consider leveraging the PowerToy toolset - awake feature | Awake Utility to keep the Windows device active.

Test Device Onboarding

Android Phone

To ensure your Android Test Phone can be stably connected to the agent/center service, please follow the below 2 steps as onboarding guides:

  1. Turn on the Android Debug mode on your phone and connect the phone to the PC with cable or ADB wireless mode (Another guideline for wireless setup).
  2. Set the phone lock mode as 'None' in the Phone lock screen setting page: Settings > Security > Screen Lock, and if prompted, enter your current lock screen code > None > Delete.

After a successful test run, you will find that a new app is installed on the phone called "HydraLab Client", which chiefly helps record test run videos on the phone. For some phones with customized rom (e.g.: Xiaomi), you may need to manually allow the HydarLab Client app display over other apps:

image

You can also add the app to the battery save mode whitelist to secure the recording service running consistently. We have pragmatically enabled it with this relevant code and this, but on some phones with customized rom you may need to configure it manually in the Setting, e.g.: Settings > Battery > Battery Optimization.

iPhone

After connecting the iPhone and PC with a USB wire, you need to Choose "trust the computer" on the phone. And then you need to install the WebDriverAgent(WDA) on the phone, which is the same one used in Appium iOS testing. We offer internal support for this integration within Microsoft. Please contact Nathan or Millard to get the internal integration wiki.

Clone this wiki locally