Prepare Android test automation

To perform Android test automation with the Mobile Engine 3.0, you have to first prepare the device or emulator, the computer, and the mobile application.

Follow the instructions in this chapter to perform these actions:

Prerequisites for Android test automation

Test automation on an Android device or emulator requires the following components:

Additionally, for local Android devices, you need the following components:

  • Android SDK Tools on your Windows computer or a Mac.

  • Java 8 installation.

  • Environment variables: ANDROID_HOME, JAVA_HOME, and Path

  • USB cable and a USB driver to connect the device to a computer with Tricentis Tosca or a Mac.

    For detailed information on installing drivers for Samsung devices, refer to the Tricentis Knowledge Base.

For detailed information regarding software versions and hardware requirements for Android test automation with the Mobile Engine 3.0, refer to the System Requirements.

Prepare operating system for Android test automation

Follow the instructions below to perform these actions:

Prepare Windows for Android test automation

If you connect your device to a PC that has Tricentis Tosca installed, follow the steps below:

  1. Ensure that you've installed the Mobile Engine 3.0 components.

  2. Install and configure Android SDK Tools.

  3. Ensure that you've specified the environment variables ANDROID_HOME, JAVA_HOME, and Path .

  4. Connect your Android device to your PC via a USB.

If you connect your device to a PC that doesn't have Tricentis Tosca installed, follow the steps below:

  1. Manually install Android Debug Bridge.

  2. Install and start the Appium Server version 1.20.2.

    If you upgrade an older Appium Server version to 1.20.2, you might have to uninstall the Appium application Appium Settings from your device first.

  3. Install and configure Android SDK Tools.

  4. Ensure that you've specified the environment variables ANDROID_HOME, JAVA_HOME, and Path.

  5. Connect your Android device to your PC via a USB.

Install and configure Android SDK Tools

To install and configure Android SDK Tools, follow the steps below:

  1. Go to the official Android Studio web page and install Android Studio.

  2. Run Android Studio. The installation of additional components, including Android SDK, starts automatically when you run Android Studio for the first time.

    Tricentis doesn't recommend that you install Android SDK in a Tricentis Tosca folder. You can install Android SDK, for example, in the folder C:\Users\UserName\AppData\Local.

  3. Launch Android Studio and open SDK Manager in one of the following ways:

    • On the Android Studio welcome screen, select Configure->SDK Manager.

    • In the Android Studio main menu, go to Tools->SDK Manager.

    • In the Android Studio main menu, go to File->Settings->SDK Manager.

    • In the Android Studio toolbar, click the SDK Manager icon.

  4. In SDK Manager, go to the SDK Tools tab and ensure that the Android SDK Tools check box is selected.

    If you don't see the Android SDK Tools check box, proceed with step 5.

  5. In the latest versions of Android Studio, in the SDK Tools tab, deselect the Hide Obsolete Packages check box.

  6. In the Name column, ensure that the Android SDK Tools (Obsolete) check box is selected.

Android SDK Tools (Obsolete) check box in SDK Manager

  1. Click OK or Apply. If you have selected new components, SDK Manager installs them at this point.

Define the ANDROID_HOME Environment Variable

To ensure the correct execution of Mobile Engine 3.0 tests, you must define the ANDROID_HOME Environment Variable.

To do so, follow the steps below:

  1. Go to Windows Control Panel and search Edit environment variables for your account.

    Alternatively, if you have administrator rights, you can search Edit the system environment variables and click Environment Variables....

  2. Under User variables, click New....

  3. In the Variable name field, enter ANDROID_HOME.

  4. In the Variable value field, enter the path to Android SDK Tools, for example C:\Users\UserName\AppData\Local\Android\Sdk.

  5. Click OK to add the variable and exit.

Define the JAVA_HOME Environment Variable

To ensure the correct execution of Mobile Engine 3.0 tests, you must define the JAVA_HOME Environment Variable.

To do so, follow the steps below:

  1. Ensure that Java 8 is installed on your computer. If not, go to Java download page to download and install it.

  2. Go to Windows Control Panel and search Edit environment variables for your account.

    Alternatively, if you have administrator rights, you can search Edit the system environment variables and click Environment Variables....

  3. Under User variables, click New....

  4. In the Variable name field, enter JAVA_HOME.

  5. In the Variable value field, enter the path where you have installed Java, for example C:\Program Files\Java\jre1.8.0_241.

  6. Click OK to add the variable and exit.

Define the Path environment variable

To ensure the correct execution of Mobile Engine 3.0 tests, you must define the Path environment variable.

To do so, follow the steps below:

  1. Go to Windows Control Panel and search Edit environment variables for your account.

    Alternatively, if you have administrator rights, you can search Edit the system environment variables and click Environment Variables....

  2. Under User variables, click New....

  3. In the Variable name field, enter Path.

  4. In the Variable value field, enter the path to your platform-tools folder, for example C:\Users\User\Android\platform-tools.

  5. Click OK to add the variable and exit.

Prepare Android devices or emulators for test automation

Follow the instructions below to perform these actions:

The specific location of settings and options may vary depending on your device.

Prepare Android devices for test automation

To prepare an Android device for test automation, follow the steps below:

  1. Connect your Android device to your computer via a USB.

  2. On the Android device, allow access to phone data.

  3. Go to Settings->Developer options and select USB debugging.

  4. Optionally, select Stay awake to keep the screen on while you run your tests.

  5. Ensure that the USB Driver for the device is installed on the computer.

    For detailed information on installing the USB Driver, refer to the Tricentis Knowledge Base.

  6. Open Tosca Commander and prepare your TestCases:

Prepare Android emulators for test automation

To prepare an Android emulator for test automation, follow the steps below:

  1. Install and set up a valid Android emulator on the computer where you want to run your TestCases in Tosca Commander.

    For detailed information on how to set up an Android emulator, refer to the Android Developer website.

  1. Open the Android emulator.

  2. Open Tosca Commander and prepare your TestCases:

For Genymotion test automation, you have to set the Android SDK path to the same one that Appium uses.

Prepare Android hybrid applications for test automation

To prepare Android hybrid applications for test automation, you have to modify them in your IDE (Android Studio/IDEA). To do so, add the following settings:

The mobile application under test has to be signed with a developer certificate.

Add WebView settings

To steer hybrid applications, you have to enable the communication between Tricentis Tosca and the application's web-based elements. To do so, go to the fragment or activity used to set up your WebView and add the following settings:

Copy
myWebView = (WebView) findViewById(R.id.webview)
myWebView.getSettings().setJavaScriptEnabled(true)
myWebView.setWebViewClient(new WebViewClient())
myWebView.setWebChromeClient(new WebChromeClient())

Add WebView settings

These settings perform the following actions:

  • They find the webview.

  • They enable JavaScript, which makes it possible to communicate with the webview.

  • They create webview clients used for communication with Tricentis Tosca.

Enable web content debugging

To steer hybrid applications, you have to enable web content debugging. To do so, go to the onCreate method and add:

Copy
WebView.setWebContentsDebuggingEnabled(true)

onCreate method

Automate Android hybrid applications in Perfecto

To run tests of hybrid applications in Perfecto, you must set additional Desired Capabilities.

To do so, follow the steps below:

  1. As a first TestStep, add the Set Desired Capabilities Module.

  2. Add the Desired Capability useAppiumForHybrid and set its Value to True.

  3. Add the Desired Capability autoInstrument and set its Value to True.

Desired Capabilities for test automation of hybrid applications in Perfecto

Prepare test automation on Android 10

Tricentis Tosca uses Appium 1.20.2, which allows you to test applications on mobile devices with Android 10. Most applications don't require special preparation for test automation on Android 10.

However, if your mobile application has a target SDK version 23 (Android 6.0) or lower, an additional Permissions pop-up window appears before your application starts. This affects your tests.

Proceed with one of the following actions:

  • Update the targetSdkVersion and apply the Desired Capability autoGrantPermissions with the value True.

  • Automate the Continue button on the Permissions pop-up window with a separate TestStep.

Tricentis recommends that you use the first option.

Recommendations for Xamarin applications

With the Mobile Engine 3.0, you can steer applications created with the Xamarin framework. You can use all standard mobile web controls and native controls. This chapter provides information on optimizing Xamarin applications for testing with the Mobile Engine 3.0.

ID Handling of controls

To improve the preciseness of testing, consider the following:

  • On Xamarin Forms: ensure to fill the optional AutomationId parameter. Tricentis Tosca recognizes this parameter as Content Description during scanning, and can use it as the unique ID required for steering the control.

  • On Xamarin Android: ensure to set the ContentDescription parameter. Tosca recognizes this parameter as Content Description during scanning, and can use it as the unique ID for steering the control.