Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated testing of PhoneGap/Cordova apps

If I want to perform automated testing of a PhoneGap app (for now, only on iOS), what options do I have (if any)?

Selenium would have been my first call, but Can you use Selenium with a phonegap application? suggests that's not possible. It looks like there's an iPhone driver to run Selenium on iOS, but no indication how to make that interact with PhoneGap. The old PhoneGap wiki seems to imply that it's possible but doesn't really say how.

I had also looked at using Jasmine with the Jasmine-jQuery plugin for much the same thing but it requires duplicating the app HTML (and the overhead of keeping the two in sync etc).

like image 837
tolien Avatar asked Aug 13 '12 12:08

tolien


5 Answers

As of recently we've added an example on how to test PhoneGap/Cordova apps using the Open Source testing framework Appium.

Please refer to https://github.com/appium/appium/blob/master/test/functional/webview/gappium.js

Appium basically treats PhoneGap/Cordova apps as hybrid apps (embedded webview). You'll be able to automate your tests using the Selenium Webdriver JSON Wire Protocol which has language specific bindings for all popular platforms (Python, Ruby, Java, C#, Obj-c, etc.). It's even possible to switch contexts from native app to webview at any given time (e.g. if you'd like to change the orientation of the device).

like image 183
sourishkrout Avatar answered Nov 15 '22 18:11

sourishkrout


Using Selenium/WebDriver with PhoneGap/Cordova Android is currently not possible. We did have this working at one point with a certain version of WebDriver, but I have been having trouble getting the current version of the WebDriver client working with custom WebViews such as the CordovaWebView, which Cordova/PhoneGap Android is based on. We are still trying to figure out how to get the new code to work nicely with custom web views, since there's no documentation for this so far.

So, sadly, the answer for this one is "not yet, but we're trying".

like image 29
Joe B Avatar answered Nov 15 '22 18:11

Joe B


My solution is QUnit. I've created a 'tests' folder inside my 'js' folder, and I've extracted all QUnit files there. To run my tests, I launch the html page used by QUnit.

like image 32
F.Ricceri Avatar answered Nov 15 '22 19:11

F.Ricceri


I have modified the current iPhone webdrive code to use it to test phonegap like application. I have put my code here: https://code.google.com/p/selenium-uiwebview/ The reason I am saying phonegap LIKE application cause Phonegap is just acting as a bridge. Wht I have done in my implementation is created my own simpler bridge. But you can simply use the same code with phonegap, as I have helped one of my friend do that. Just use the latest version, cause we had some trouble with older XCode versions. I have given detailed description on project home page. Let me know how it works.

like image 1
Saurabh Avatar answered Nov 15 '22 18:11

Saurabh


You may get some hints from this continuous integration setup for phonegap itself

https://github.com/filmaj/medic

These are the test executed by the previous project. Just put the whole project in a phonegap project www folder

https://github.com/apache/incubator-cordova-mobile-spec

like image 1
xverges Avatar answered Nov 15 '22 18:11

xverges