Automatic Testing for Cordova/Phonegap Webview on Android

前端 未结 3 1962
野趣味
野趣味 2021-02-02 03:34

I\'m currently looking for a solution to test Android Apps automatically, native Android apps as well as hybrid Cordova/Phonegap apps.

The UI Automator from Google looks

3条回答
  •  后悔当初
    2021-02-02 04:12

    I faced this challenge with our own Cordova app ( sourceforge.net/p/ustadmobil/codehtml5cordova/ci/master/tree/ ) ; and I needed a way to integrate this with Jenkins CI. We have Cordova specific code (e.g. filesystem access) so just using PhantomJS and Grunt is not an option.

    Essentially what I did was to launch the app with the test page as index.html in the emulator, run an http server, and then have the test page pass the results back using AJAX.

    1. Script launches an emulator with the package
      $ /opt/adt/sdk/tools/emulator-x86 -avd $AVDNAME -qemu -m 2047 &
      $ EMULATEPID=$!
      $ adb wait-for-device #wait for device to start $ adb shell input keyevent 82 #unlock screen

    2. Make a test page using qunit, which when finished will communicate the test results with an AJAX call.

    3. Make a basic nodejs server script that will listen for that ajax call and save the results to a file. A bash script can then read that file and determine if the tests passed or failed : see http://sourceforge.net/p/ustadmobil/codehtml5cordova/ci/master/tree/setup/node-qunit-server/node-qunit-server.js
    4. In the build script wait for the result file to come, then kill the emulator and the NodeJS server - see http://sourceforge.net/p/ustadmobil/codehtml5cordova/ci/master/tree/setup/android/unit-test-setup-android.sh

    Also worth noting: this approach works for the cross platform nature of Cordova: it should be possible to take the same approach running iOS, Windows Phone emulators etc (I also use this test method against our NodeWebKit desktop version which shares most of the code).

    Hope this helps,

    -Mike

提交回复
热议问题