concept WebDriver in category ionic

appears as: WebDriver
Ionic in Action: Hybrid Mobile Apps with Ionic and AngularJS

This is an excerpt from Manning's book Ionic in Action: Hybrid Mobile Apps with Ionic and AngularJS.

9.5.2. Integration tests with Protractor and WebDriver

Some parts of your app are best tested with an integration test that can simulate user behaviors such as tapping or typing values into a form input. Protractor (www.protractortest.org) is a testing framework built specifically for Angular (in fact, by the Angular team), and therefore works for Ionic apps. Protractor is built on top of an API called WebDriver (http://w3c.github.io/webdriver/webdriver-spec.html), which allows you to programmatically interact with an application just like the user would. WebDriver is really just the specification for how programs can programmatically interact with a browser. Selenium (http://docs.seleniumhq.org/projects/webdriver/) was the project that inspired the WebDriver API spec. See figure 9.10 for an example of how tests are executed using these APIs.

Figure 9.10. How integration tests are executed using WebDriver/Selenium, Protractor, and Jasmine

Protractor extends the features of WebDriver and adds better support for Angular apps. By default WebDriver runs as soon as the page is ready, but due to the Angular digest loop, your tests need to run only after Angular is ready. Protractor aids your tests by waiting for Angular to finish rendering the view before running the tests, as well as providing a few unique API calls to target parts of an Angular template. You’ll see a few of these in action in the sample test.

Set up and run Protractor and WebDriver

First you need to do a one-time setup for Protractor and WebDriver. Start by installing Protractor as a global Node module, just like you did when you installed Ionic and Cordova:

$ npm install -g protractor

This command will download Protractor and also create a helper tool to easily manage WebDriver. You’ll use the tool to download all of the tools for WebDriver to run. The tool will download the Selenium server and Chrome driver, and set them up: