Sahi Pro - Testing Native and Hybrid Android apps

abstract This section details how to test native and hybrid apps on an Android device or emulator.

License

SahiProPlus versions now support testing of native and hybrid content on Android devices. In future, they will support testing of iOS devices as well.

Native and hybrid Android apps testing is not supported on SahiPro versions. However Android browsers can be tested from SahiPro versions as well as from SahiProPlus versions.

SahiProPlus software requires a different license file than the one SahiPro uses. Add the new license to userdata/config folder.

Features


Limitations


Pre-requisites


Installation


Android Viewer

Android Viewer allows an end user to view the Android screen on a Desktop browser. The user can launch the Controller and then identify Android elements by
pressing the Ctrl key and hovering the mouse over the element. One can identify native as well as web elements inside a WebView.

This section details how to use the Android Viewer.
  1. Launch a Chrome or Firefox browser from the Dashboard.
  2. Click on the Android Viewer link. This brings up a page with a single button Connect Session
  3. Make sure that the device is connected through a USB cable. Click on Connect Session. If the connection is successful, you will see 3 buttons Disconnect Session, Controller and Refresh.
    You will see the device screenshot in a short while.
  4. The screen does not get refreshed automatically. When some action is performed from the Controller, the screenshot will be refreshed a few times, to display the latest device state.
    However, if actions are performed on the device manually, the screenshot will not get refreshed. Click on the Refresh button manually to refresh the screenshot.
  5. One can interact with the device from the Android Viewer itself without launching the Controller. Please refer to the Recording section for details on how to do this.
  6. Launch the Android Controller by clicking on the Controller button. This will bring up the Controller. This looks exactly the same as a normal Browser controller.
  7. You can now start identifying elements by pressing the Ctrl key and hovering the mouse over elements on the Desktop screenshot. You will notice the Accessor textbox on the Controller, showing the accessor for the element. The Alternatives dropdown displays alternatives for the accessor.
  8. One can identify both native elements and web elements in a hybrid app. When web elements are identified, you will notice the Prefix textbox populated with content prefixed with _webcontext.
    For example: _webcontext("in.co.sahi.android.testwebview"). The _webcontext prefix indicates that the accessor is for a Web element. For a native element, the prefix is blank.

Native element:

Hybrid element:
info A few things to note...
  • Currently, Android Viewer is supported only on Chrome and Firefox. This does NOT work on IE.
  • If the app orientation changes from portrait to landscape or vice versa, do a manual refresh by clicking on the Refresh button, to view the screenshot correctly.
  • If you resize the Android Viewer page, do a manual refresh by clicking on the Refresh button, to view the screenshot correctly.
    IMPORTANT NOTE: Please ensure that the page does NOT display a vertical scrollbar. The page should always be a single page. If you resize the page such that a vertical scrollbar is seen, element identification will not happen properly.
  • Android Viewer and Controller, support identification of native elements and web elements inside a native app. They do NOT support identification of web elements inside an Android browser.
    Hence use this only for a native or hybrid app. Do not use it for an Android browser.
  • Please do not yank the device before disconnecting the session. Incase you do so and on reconnecting you find that Connect Session does not seem to connect the device, please have a look at the Sahi console.
    If the Sahi console indicates that you should reconnect the device, please do so.
  • Closing the Android Viewer browser does NOT disconnect the session. So please always disconnect the session before closing the browser. If you fail to do so, and open the Android Viewer again, it will show the session to be in a connected state. The elements will still get identified.
  • As of now, Android Viewer supports only one device at a time. Device has to be connected to the desktop that runs Sahi.

Recording a script

This is similar to recording a Sahi script for normal browser testing.
  1. To record a script, launch the Controller from the Android Viewer page, choose a script to record and press Record.
  2. Actions done from the Android Viewer page are recorded automatically.

    Press the Ctrl key and hover your mouse over an element on the screen.

    • Native elements
      • Hovering the mouse over an EditText will overlay a textbox where you can type in text. After typing the text, press Enter or click outside the textbox. This will cause the text content to be sent to the device. The _setValue step will get recorded automatically.
      • Hovering the mouse over other controls will display a pointer cursor. The user can then click on the pointed element. This will cause the element on the device to be clicked. The _click step will get recorded automatically.
    • Web elements
      • Hovering the mouse over an input text or input password control will overlay a textbox where you can type in text. After typing the text, press Enter or click outside the textbox. This will cause the text content to be sent to the device. The _setValue step will get recorded automatically.
      • Hovering the mouse over other controls will display a pointer cursor. The user can then click on the pointed element. This will cause the element on the device to be clicked. The _click step will get recorded automatically.
  3. Steps can also be recorded from the Controller. You can use Click, Set, Assert, choose Other Actions, Test an expression from Evaluate Expression to perform an action on the Device.
    But you will need to record these steps explicitly by clicking on Append to Script.
  4. Whenever a native step is followed by a web step or vice versa, _aStartWebContext or _aStopWebContext get recorded automatically. The user does not need to explicitly write code for this.
  5. Since the device screenshot gets refreshed a few times after a Controller action is performed, the user can continue to interact with the changing screen from the Desktop itself. If the device screenshot is not refreshed correctly, click on the Refresh button manually to reflect the current screenshot.
  6. For web elements, recording can also be done from the Device itself. Actions performed on the Device during a Recording session will automatically get recorded.
    info This is useful in recording actions inside an iframe with a different domain to the main domain. Actions cannot be recorded from the Android Viewer inside an iframe with a different domain.
    info For native elements, recording CANNOT be done from the Device. Android Viewer and Controller have to be used for recording native elements.
  7. Accessor Repository is not supported for Android elements as of now.

Using the controller

The Controller can be used to interact with the device in a non Record mode as well. You can use Click, Set, Assert, choose Other Actions, Test an expression from Evaluate Expression to perform an action on the Device.

Playback from the Controller

Once a script is recorded, it can be played back from the Controller Playback tab itself.
  1. Choose the script.
  2. You can leave the Start url blank. This is not used.
  3. Click on Play to playback the script.
  4. Click on Logs to view the logs of the played back script.
  5. NOTE: When the script is being played back from the Controller, you cannot see the playback happening on the Android Viewer. The AndroidViewer does not get refreshed during playback.

Playback from the Editor

You can playback the script from the Editor as well.

info IMPORTANT:
A script cannot be played back on an Android device if a session is open from the Android Viewer. Disconnect the session from the Android Viewer and then playback the script.

If the session is open and you play back a script from the Editor, the script will not run till you close the open session.

  1. Choose the script from the Editor and click on the Playback button.
  2. Choose any Browser.
  3. Enter the default mobile device to connect to. If left blank, the value "default" is used.
  4. Choose the Start Mode as Mobile Device
  5. Choose any Start URL. This is not used.
  6. Choose the Run in parallel option.
  7. Press Run to playback the script.

Playing back a suite

  1. Choose the suite from the Editor and click on the Playback button.
  2. Choose any Browser.
  3. Enter the default mobile device to connect to. If left blank, the value "default" is used.
  4. Choose the Start Mode as Mobile Device
  5. Choose any Start URL. This is not used.
  6. Choose the Run in parallel option.
    info IMPORTANT: Choose Threads as 1. Do NOT leave this as 5.
  7. Press Run to playback the script.

Notes on Hybrid content


Notes on SSL content

Additional configuration is required to test SSL content inside a WebView.

Accept Certificate

  1. On the Android device, open a browser and access http://sahi.example.com:9999. You should see a page like this

    If you do not see the page, you need to set the network proxy settings to point to the Sahi Desktop machine at port 9999.
  2. Click on the crt link. Give a certificate name, say Sahi.

    Click OK to install the certificate.
  3. Clear the Application cache as explained in section Notes on Hybrid content.
  4. Now you should be able to automate the SSL content in your application's WebView.

Effect of proxy on some apps

You may notice that after you configure Sahi's proxy, some apps that require internet connection do not work. This happens because they are using an SSL connection and configuring the proxy causes the connection to fail.
To fix the problem, accept the SSL certificate as stated above in the Accept Certificate section.