Integration testing

There are several full application frameworks out there, but we will show you how to use Appium (http://appium.io). Appium is an awesome open source application testing framework. Appium supports both iOS and Android, which makes it a perfect fit for doing all our on-device testing. You want to start creating tests to test your basic flow through your application, and even create more complicated tests that test alternate flows through your app.

Let's get it installed first; run the following command:

npm install appium wd nativescript-dev-appium --save-dev

The preceding command installs Appium, the Appium communication driver WD (http://admc.io/wd/), and the NativeScript driver (https://github.com/NativeScript/nativescript-dev-appium). The WD driver is what communicates with Appium and the NativeScript driver. The nativescript-dev-appium is the driver that interacts with WD and your test code. In reality, the NativeScript driver is a very thin wrapper around the WD driver and just facilitates some configuration and then exposes the WD driver to your application. So interaction commands will be found in the WD documentation.

Application/Integration testing takes a bit more work, as you have to programmatically run it as a normal user would interact with your app. So, you have to do things, such as find the button element, then perform button.tap(). So, your tests might be a bit verbose, but this allows you to test any, and all, functionalities. The down side is that this is a lot more time-consuming to run and takes more maintenance work when you change screens. However, the payoff is that when you add code, it verifies that your app still runs properly on each screen automatically, and you can test it on multiple devices and resolutions, once again automatically.

After installation, you will have a brand new e2e-tests folder in your root folder of your application. This folder is where all your end-to-end test files will live. Now, one thing that you need to know is that the Appium NativeScript driver uses the MochaJS test framework (https://mochajs.org/). The Mocha testing framework is similar to the Jasmine framework, which we discussed in the preceding chapter. It uses the same describe and it functions for the start of the tests, just like Jasmine. In addition, it uses the Chai (http://chaijs.com/) and ShouldJS (https://github.com/shouldjs/should.js) testing frameworks that work hand in hand with the Mocha test framework and the WD driver.

Another thing to note is that all these are designed around pure JavaScript. You can get typings for Mocha, Should, and Chai, but for the NativeScript Appium driver or WD driver, typings don't exist. You can use TypeScript, but it is awkward, as commands are not just WD-based commands but chained through mocha. TypeScript gets easily confused as to what context you are in. So, mostly the Appium tests are created in pure JavaScript rather than in TypeScript. However, feel free to use TypeScript if you want; just make sure that you run tsc to build the JS files before you run the tests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.105.227