Features

Getting started with CodeceptJS

CodeceptJS is an end-to-end testing framework which supports Appium for automated mobile testing.
It offers scenario driven testing, PageObjects support, beautiful reports and much more.

Let's start with installing everything we need:

Copy code
npm i --save-dev codeceptjs

Now we need to set up CodeceptJS. Please use the command below to initialize a new project:

Copy code
npx codeceptjs init

This will ask a bunch of questions, and will create a sample test at the end of the process.

Example test

Now that you have everything set up, you can create a very simple test:

Copy code
Feature('My First Mobile App Test');

Scenario('test sample calculator', (I) => {
  I.seeAppIsInstalled("com.testingbot.sample");
  I.click('~inputA');
  I.fillField('~inputA', '10');
  I.click('~inputB');
  I.fillField('~inputB', '5');
  I.see('15', '~sum');
});

This simple test will test a calculator mobile app, it will fill in two numbers in two input fields and check the sum.

Before we can run this test, we need to configure CodeceptJS to connect to TestingBot.

Configuration

You can configure CodeceptJS with a codecept.conf.js file:

Copy code
exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Appium: {
      app: 'tb://...',
      host: "hub.testingbot.com",
      port: 4444,
      platform: "Android",
      user: "api_key",
      key: "api_secret",
      desiredCapabilities: {
        deviceName: "Pixel 3",
        platformVersion: "10.0",
      },
    },
  },
  include: {
    I: './steps_file.js'
  },
  bootstrap: null,
  mocha: {},
  name: 'codeceptjs-example',
  plugins: {
    retryFailedStep: {
      enabled: true
    },
    screenshotOnFail: {
      enabled: true
    },
  }
}

To run the test, you can do:

Copy code
npx codeceptjs run --steps

This will start the a Pixel 3 Emulator and run the test on our grid.
You will see a test appear in your member dashboard on TestingBot, together with a video, log files and other assets generated by the test.

Configuring capabilities

To run your existing tests on TestingBot, your tests will need to be configured to use the TestingBot remote machines. If the test was running on your local machine or network, you can simply change your existing test like this:

Before
Copy code
// codecept.conf.js
exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Appium : {}
  }
};
After
Copy code
// codecept.conf.js
helpers: {
    Appium: {
      app: 'tb://...',
      host: "hub.testingbot.com",
      port: 4444,
      platform: "Android",
      user: "...",
      key: "...",
      desiredCapabilities: {
        deviceName: "Pixel 3",
        platformVersion: "10.0",
      },
    },
  },
}

Specifying the device

To let TestingBot know on which device you want to run your test on, you need to specify the deviceName and platformName.

To see how to do this, please select a combination of deviceName and platformName in the drop-down menus below.

1. Select a Device Type
2. Select a Device Name
Copy code

Parallel Testing

Please see CodeceptJS parallel testing on how to run your tests in parallel.

You can specify the concurrency by specifying a number of workers:

Copy code
npx codeceptjs run-workers 2

or run multiple different browsers with:

Copy code
npx codeceptjs run-multiple --all

Queuing

Every plan we provide comes with a limit of parallel tests.
If you exceed the number of parallel tests assigned to your account, TestingBot will queue the additional tests (for up to 6 minutes) and run the tests as soon as slots become available.

Preparing your App

You do not need to install any code or plugin to run a test.
Below are some things that are necessary to successfully run a mobile test:

For Android:
  • Please supply the URL to your .apk or .aab file.
    Important: the .apk file needs to be a x86 build (x86 ABI) for Android emulators.
For iOS Real Device:
  • Please supply the URL to an .ipa file.
For iOS Simulator:
  • Please supply the URL to a .zip file that contains your .app
  • The .app needs to be an iOS Simulator build:
    • Create a Simulator build:
      Copy code
      xcodebuild -sdk iphonesimulator -configuration Debug
    • Zip the .app bundle:
      Copy code
      zip -r MyApp.zip MyApp.app

Additional Options

Appium provides a lot of options to configure your test.

Some important options that might help:

For Android:
  • appActivity and appPackage: by default, Appium will try to extract the main Activity from your apk. If this fails, you can supply your own with these options.
  • chromeOptions: additional chromedriver options you can supply.
  • otherApps: a JSON array of other apps that need to be installed, in URL format.
For Android & iOS:
  • locale: the language of the simulator/device (ex: fr_CA)
  • newCommandTimeout: How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session