10

We're building a Hybrid Native Application (Cordova/Phonegap/Angular/Ionic).

I'm writing end-to-end tests in Protractor. When run locally, they execute against the application served by the Ionic simulator (ionic serve). This works fine.

I also want to run the same tests against the 'packaged/built' application on a platform simulator, hosted by Sauce Labs (Appium). This almost works.

The trouble I'm having right now is navigating to the application. When run locally, at the beginning of the test I'll navigate to the application hosted by ionic:

browser.get('http://localhost:8100')

This obviously doesn't work in a simulator running a hybrid native app. I inspected the current Url of the browser when the test starts up and it is:

file:///android_asset/www/index.html#/login

This makes sense and is correct. But if I try to:

browser.get('file:///android_asset/www/index.html#/login')

bad things happen.

I'm looking for one of two solutions:

1) understand how to navigate to Urls for a hybrid native app run in a simulator

OR

2) somehow have the test know that it's running within the hybrid native cordova container and skip navigating to the starting page (since the application is loaded automatically by the appium).

Thanks.

Joel Skrepnek
  • 1,651
  • 1
  • 13
  • 21
  • 3
    If you want to navigate with a `file://` protocol, take a look a this Q/A - [Opening a file with protractor](http://stackoverflow.com/questions/24824491/opening-a-file-with-protractor). Also there is a Protractor guide for [Mobile Setup](https://github.com/angular/protractor/blob/master/docs/mobile-setup.md), which has a lot of info about setting up Protractor with Appium. To identify emulator you could implement a method `isCordova`, which would check User Agent or use [cordova-plugin-device](https://github.com/apache/cordova-plugin-device) to tell if current env is "mobile" env. – Michael Radionov Sep 17 '15 at 07:48
  • 1
    If you are trying to run the same tests on two pretty different environments, maybe it's worth having two Protractor configs with different setups. – Michael Radionov Sep 17 '15 at 07:50
  • Thanks @MichaelRadionov. I am already using separate protractor configurations - it was needed of course to set credential and capabilities for Sauce / Appium vs served locally via ionic simulator. From what I understand, the Mobile Setup is geared toward driving an application in a 'normal' mobile browser - i.e.: Chrome - as opposed to testing a hybrid native app. The links you have pointed me to look very helpful. I'll see if they help later. – Joel Skrepnek Sep 17 '15 at 17:17

1 Answers1

0

A little late getting into this, but if I understand the problem correctly, you just need to distinguish between running locally and running through Sauce. Since you already have two protractor files, why not just avoid calling browser.get in the Sauce config? Or is there something obvious that I'm missing?

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • Yeah, this is essentially what I've done Andrew. It's a slight work around, I think, because at some point I will want to write a new suite a tests that start at a known location. Typically I think this is accomplished by just navigating the browser to the 'start' - wherever that particular suite will start driving the site. For the mobile app, I have no way to set a 'start' page'. For now I've adopted a convention that the login tests come first and then every other test (that assumes an authenticated user) must begin and end at the 'home' view. – Joel Skrepnek Nov 29 '15 at 01:55
  • Hmmm...well, there's the `baseUrl` property and `browser.getUrl('/')` should navigate you to the start. As long as you keep using relative paths, there shouldn't be a problem navigating with your application. – Andrew Eisenberg Nov 29 '15 at 06:10