Appium Test Support Utilities

1.3.3 · active · verified Tue Apr 21

`appium-test-support` is a collection of JavaScript test utilities designed for internal use across various Appium packages. It provides common testing patterns such as environment variable stubbing (`stubEnv`), log output capturing and manipulation (`stubLog`), and advanced Sinon-based testing with sandboxes and mocks (`withSandbox`, `withMocks`, `fakeTime`). The current stable version is 1.3.3. As an internal utility library, its release cadence is tied to the broader Appium project's needs and updates, typically seeing updates in line with major Appium releases or when internal testing needs evolve. It differentiates itself by offering pre-packaged solutions for common Appium testing scenarios, including specific support for Android emulator setup on Travis CI, streamlining testing workflows within the Appium ecosystem and reducing boilerplate in Appium's own tests.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `fakeTime` with a Sinon.js sandbox to control and fast-forward time in asynchronous tests, verifying the outcome of time-dependent operations. This setup requires `sinon` and a test runner like `mocha` with `chai` for assertions.

import { fakeTime } from 'appium-test-support';
import sinon from 'sinon'; // Requires 'sinon' as a dev dependency
import { expect } from 'chai'; // Requires 'chai' for assertions

// Simplified Promise-like object for demonstration if Bluebird isn't available
class CustomPromise {
  constructor(executor) {
    this.resolve = null;
    this.reject = null;
    const promise = new Promise((res, rej) => {
      this.resolve = res;
      this.reject = rej;
    });
    executor(this.resolve, this.reject);
    return promise;
  }
}

function doSomethingThatTakesTime() {
  return new CustomPromise((resolve) => {
    let ret = '';
    function appendOneByOne () {
      if(ret.length >= 10) {
        return resolve(ret);
      }
      setTimeout(() => {
        ret = ret + ret.length;
        appendOneByOne();
      }, 1000);
    }
    appendOneByOne();
  });
}

describe('fakeTime demonstration', () => {
  let sandbox: sinon.SinonSandbox;

  beforeEach(() => {
    sandbox = sinon.createSandbox();
  });

  afterEach(() => {
    sandbox.restore();
  });

  it('should fast-forward time to test async operations', async () => {
    const timeLord = fakeTime(sandbox);
    const p = doSomethingThatTakesTime();
    // Simulate 60 intervals of 200ms each, effectively advancing 12000ms (12 seconds)
    // This allows the `doSomethingThatTakesTime` function to complete its 10 * 1000ms operations.
    timeLord.speedup(200, 60);
    expect(await p).to.equal('0123456789');
  });
});

view raw JSON →