Get Started with Appium for C++ Apps

You.i Engine C++ includes a Gemfile and a Brewfile to install all necessary components to your machine. Prior to running either file, ensure you have the following tools installed:

  • Ruby (version 2.2 or above)
  • Brew dependencies (run brew bundle)
  • Bundler (run gem install bundler)
  • Gem dependencies (run bundle install)

Download and Install Appium

Downloading Appium Desktop

Download Appium Desktop from the Appium website.

Downloading the Appium Server

Download Appium from the Appium website and enter the following command:

npm install -g appium

Install Dependencies

Brewfile Dependencies

The brewfile installs the following dependencies:

Tool or Component Role
carthage Required for Facebook’s WebDriverAgent used in appium-xcuitest-driver
libimobiledevice Captures device logs
ideviceinstaller Installs the target app on an iOS real device (for iOS 9 and earlier)
ios-deploy Installs the target app on iOS real devices running on iOS 10
node The Appium server runs on top of the node.js server.

Gemfile Dependencies

The gemfile installs the following components:

Tool/component Role
ruby Checks that you have the right Ruby version installed.
rspec Provides behavioral-driven development for Ruby. Used in the execution of tests.
appium_console Sends Appium commands interactively using the Appium Ruby Console (ARC)
ipaddress Gem used by the getiOSIP app to read the iOS IP address of an iOS app
toml Gem used by the yi_appium_caps_util utility to automatically update the caps in the appium.txt file
yi_appium_caps_util Gem that automatically updates the caps in the appium.txt file

Dev Dependencies

The gemfile installs the following components:

Tool/component Role
Appium Checks if the correct version of Appium is installed or not.
babel-jest Checks if the correct version of babel-jest is installed or not.
babel-preset-env Checks if the correct version of babel-preset-env is installed or not.
babel-preset-react-native Checks if the correct version of babel-preset-react-native is installed or not.
babel-register Checks if the correct version of babel-register is installed or not.
chai Checks if the correct version of chai is installed or not.
node-fetch Checks if the correct version of node-fetch is installed or not.
react-test-renderer Checks if the correct version of react-test-renderer is installed or not.
wdio-appium-service Checks if the correct version of wdio-appium-service is installed or not.
wdio-mocha-framework Checks if the correct version of wdio-mocha-framework is installed or not.
wdio-spec-reporter Checks if the correct version of wdio-spec-reporter is installed or not.
webdriverio Checks if the correct version of webdriverio is installed or not.

Running the Test Scripts

Do the following steps:

  1. Connect your target device to the machine with Appium installed.
  2. Run the Appium server and tests in your Terminal window using: yarn appiumtest
  3. Open another Terminal window and run the scripts by executing ./runTests.sh -a <appname>

  4. Type ./runTests.sh -h for more options.

Working With the Configuration File

The wdio.conf.js file holds all of the important information regarding your test session. This is where all your capabilities are defined that configures the Appium server session.

You must create the wdio.conf.js file and configure the capabilities as you require. Store it in the same directory as all other Appium files.

Capabilities

For more information on capabilities, see Desired Capabilities.

Enabling an Application for Appium Use

Now that you have your environment set up, you must ensure that each application you want to test with Appium is able to communicate with the Appium server.

To enable an application for Appium use, open a socket for server communication.

Opening a Socket in the Target App

Do the following steps:

  1. Open the {appname].cpp file for the target app. The following example is based on the VideoPlayer sample.
  2. Add a start method to the CYIWebDriver object:

    #include <automation/YiWebDriverLocator.h> 
    bool VideoPlayerApp::UserInit()
    {
    CYIWebDriver *pWebDriver = CYIWebDriverLocator::GetWebDriver();
    if (pWebDriver)
    {
        pWebDriver->Start();
    }
      // other (normal) application specific initialization code
    }
    

Linking the Appium library to your application

The Appium CYIWebDriver code is not included in the default C++ libraries linked to a You.i application. This ensures that this code can be removed in production builds.

To link the Appium library to your application:

  1. Open the CMakeLists.txt or TargetList.cmake file in your application.
  2. In CMakeLists.txt after the call to yi_add_executable, or anywhere in TargetList.cmake add:

    find_package(YouiEngine
       ${YI_YOUI_ENGINE_VERSION}
       COMPONENTS appium_server
       HINTS ${YouiEngine_DIR}
       REQUIRED
     )
    target_link_libraries(${YI_PROJECT_NAME}
       PRIVATE youi::appium_server
    )
    

Testing With Appium

Shared scripts can be found within your engine package: <package>/Test/appium

Supported Commands

A complete list of supported commands is on the appium-youi-driver GitHub page.