Appium Tip #6: Jazzing JavaScript with Node.js

  October 20, 2015

This is the sixth blog in our Things You Should Know About Appium and this time our focus will be on JavaScript, with some additional flavors on Node.js stuff. Furthermore, I have great news regarding getting all these tips and tricks delivered to you: everyone who has signed up to our Appium Weekly will have these blog posts automatically delivered and also get some additional info within those emails (some extra tips and tricks).

JavaScript has become a de-facto programming language in web-based applications and it is widely and commonly used in other software domains, such as in-game development and naturally server-side network programming, as well. Appium can be run with JavaScript through Node.js – thanks to different testing frameworks such as Mocha and Nightwatch. We truly encourage you guys to take a look at these – IF you consider using JavaScript and/or Node.js for your mobile app testing. Meanwhile, we recommend downloading our free beginner’s guide and get started with Appium mobile testing with JavaScript today.

Getting Started with Writing Appium Tests in JavaScript

There is one awesome example (with some source code) by Aaron Colby using Nightwatch framework and this example provides an insight on how to launch Safari browser and use your tests on navigating to a specific website. Nightwatch is the framework for browsers and web apps specifically. Take a look at the example first – it’s available at

To recap some of the essential things from Aaron’s example and some further things to consider:

Add Dependencies

1.) npm dependencies

    $ npm install

2.) install mocha globally

    $ npm install -g mocha

Add Credentials to ./.creds.json

You will need to add an object testdroid to the file ./.creds.json, as it is .gitignored:

        "testdroid": {
            "username": "TESTDROID_USERNAME",
            "password": "TESTDROID_PASSWORD"

Run the test

    $ mocha ios_safari.js

All dependencies MUST be installed as instructed in the readme file. Then, create a new file called .creds.json and add your Bitbar credentials as illustrated and exampled above.

You also have to create a directory named as "temp" for all screenshots that will be taken during the test session. Explore the ios_safari.js file to see how the test itself is built. In order to make the device finder look for freemium devices, add the creditsPrice value as 0 (or 1 for premium devices) to the criteria, as follows:

    if([i].locked === false &&[i].creditsPrice === 0)
      device =[i];
      i =;

Example of Appium for Mocha based Node.js tests

Let’s use the earlier sample as a base to create a native iOS app test next! The difference here is that we won’t be needing the Nightwatch framework at all.

Desired capabilities

Edit the desired capabilities, namely the testdroid_target, testdroid_app and bundleId. Also, make sure to remove the ‘browser’ capability.

    desired.testdroid_username = creds.testdroid.username;
    desired.testdroid_password = creds.testdroid.password;
    desired.testdroid_target = 'ios';
    desired.testdroid_project = 'Test iOS Mocha';
    desired.testdroid_testrun = 'TestRun A';
    desired.testdroid_device = device.displayName;
    desired.platformName = 'iOS';
    desired.deviceName = 'iOS Device';
    desired.testdroid_app = 'sample/BitbarIOSSample.ipa';
    desired.bundleId = 'com.bitbar.testdroid.BitbarIOSSample';

Using testdroid_app = 'sample/BitbarIOSSample.ipa' you can default to the pre-existing sample app which is always available in the cloud! For Android, the same would be 'sample/BitbarSampleApp.apk'.

Test case

Let’s edit the test case to do something with the native sample app, instead of the safari targeted commands:

    it("should set text to 'Tester'", function() {
    return driver
    .saveScreenshot(SCREEN_SHOT_PATH + '/test.png')
    .saveScreenshot(SCREEN_SHOT_PATH + '/test2.png')
    .saveScreenshot(SCREEN_SHOT_PATH + '/test3.png')

You may, of course, change the name of the ios_safari.js file to something that makes more sense, like ios_native.js or so. The test case function describe("ios safari", function() { should probably be renamed at this point too.


For the Selenium-based driver commands, the best place to refer would be the Selenium Webdriver’s Node.js documentation’s full jsonwire mapping.

Running Tests in Cloud – with REAL Devices

Missing some hot Android or iOS device in your testing roster? Or maybe all of them? That’s why Bitbar Testing was originally created: to serve all Android and iOS developers and testers to access any device, any time, and from anywhere.

First, set up your environment properly.

Secondly, select the suitable programming language that you use regular basis and build your tests around it.

Finally, follow up with our best practices – and you’ll be good.

See you again next week and keep up the great work on your testing!