Skip to content

Debugging TestServer.apk

Owen Niblock edited this page Jul 12, 2017 · 4 revisions

Get the code

Clone calabash-android and calabash-android-server within the same parent directory, for example:

mkdir ~/calabash
cd ~/calabash
git clone https://github.com/calabash/calabash-android-server
git clone https://github.com/calabash/calabash-android

Configure Android Studio

  1. Launch Android Studio and choose Import project (Eclipse ADT, Gradle, etc.).
  2. Select the calabash-android-server, for example ~/calabash/calabash-android-server/server.
  3. Click Next a whole bunch of times until the project is opened.
  4. From the Run menu, select Edit Configurations.
  5. Click the + button and select Android Application.
  6. Set Name to TestServer.
  7. Select instrumentation-backend as the Module.
  8. Set Deploy to Nothing.
  9. Set Launch to Nothing.
  10. Remove Gradle-aware Make from Before launch:
  11. Click OK.

Build the TestServer

  1. Navigate to the ruby-gem folder in the calabash-android repo, for example:

    cd ~/calabash/calabash-android/ruby-gem
    
  2. Install the dependencies:

    bundle install
    
  3. Build the TestServer:

    bundle exec rake build
    

TestServer.apk will be generated in calabash-android/ruby-gem/lib/calabash-android/lib.

If you later make any modifications to the source code then you just need to run bundle exec rake build to generate a new TestServer.apk.

Deploy the apps

  1. Create a new directory to contain your apps/tests and copy the application to be tested into it, for example:

    mkdir ~/calabash/myapp
    cp myapp.apk ~/calabash/myapp
    cd ~/calabash/myapp
    
  2. Add a Gemfile which points at the calabash-android ruby gem source, for example:

    gem ‘calabash-android’, path:’~/calabash/calabash-android/ruby-gem’
    source ‘https://rubygems.org’
    
  3. Launch the calabash-android console for your test app, for example:

    bundle exec calabash-android console myapp.apk
    
  4. Install the app to test and the TestServer

    reinstall_apps
    

Configure the Android device / simulator

  1. Enable developer mode.
  2. Open Settings -> Developer options.
  3. Enable USB debugging.
  4. Tap Select debug app and select your test app.
  5. If you need to debug loading processes: Enable Wait for debugger.

Debugging

  1. Force an update of the TestServer if you’ve modified the source code and rebuilt it:

    bundle exec calabash-android build myapp.apk
    
  2. Launch the calabash-android console for your test app, for example:

    bundle exec calabash-android console myapp.apk
    
  3. Shut down any running instances if required:

    shutdown_test_server
    
  4. Reinstall TestServer.apk

    reinstall_test_server
    
  5. In the calabash-android console, launch the apps:

    start_test_server_in_background
    
  6. In Android Studio, select Run -> Attach debugger to Android process.

  7. Tick Show all processes, select the app and click OK.

  8. Set a breakpoint in Android Studio. For example, on the first line of the executeQuery method in sh.calaba.instrumentationbackend.query.Query which can be found in the file ~/calabash/calabash-android-server/server/instrumentation-backend/src/sh.calaba/instrumentationbackend/query/Query.java.

  9. In the calabash-android console, execute calabash commands to cause the breakpoint to be hit, for example:

    query('button')