How to use the appium-test-support.withMocks function in appium-test-support

To help you get started, we’ve selected a few appium-test-support examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github appium / appium-ios-driver / test / unit / instruments / instruments-specs.js View on Github external
// transpile:mocha

import { Instruments, instrumentsUtils } from '../../..';
import * as tp from 'teen_process';
import chai from 'chai';
import xcode from 'appium-xcode';
import { withMocks } from 'appium-test-support';
import { fs } from 'appium-support';
import B from 'bluebird';
import { getXcodeVersion } from './helpers';


chai.should();

describe('instruments', withMocks({fs, tp, xcode, instrumentsUtils}, (mocks) => {
  afterEach(function () {
    mocks.verify();
  });

  function getInstruments (opts = {}) {
    let instruments = new Instruments(opts);
    instruments.xcodeVersion = getXcodeVersion();
    instruments.template = '/a/b/c/d/tracetemplate';
    instruments.instrumentsPath = '/a/b/c/instrumentspath';
    return instruments;
  }
  describe('quickInstrument', function () {
    it('should create instruments', async function () {
      mocks.xcode
        .expects('getVersion')
        .once()
github appium / appium-ios-driver / test / unit / instruments / utils-specs.js View on Github external
// transpile:mocha

import { instrumentsUtils, Instruments } from '../../..';
import * as tp from 'teen_process';
import xcode from 'appium-xcode';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { withMocks, stubEnv } from 'appium-test-support';
import { fs } from 'appium-support';
import B from 'bluebird';


chai.should();
chai.use(chaiAsPromised);

describe('utils', withMocks({tp, fs, xcode, instrumentsUtils}, function (mocks) {
  beforeEach(function () {
    mocks.verify();
  });
  describe('getInstrumentsPath', function () {
    it('should retrieve path', async function () {
      mocks.tp
        .expects('exec')
        .once()
        .returns(B.resolve({stdout: '/a/b/c/d\n', stderr: ''}));
      (await instrumentsUtils.getInstrumentsPath()).should.equal('/a/b/c/d');
    });
    it('should throw an error if cannnot find Instruments', async function () {
      mocks.tp
        .expects('exec')
        .once()
        .throws(new Error('Instruments not found'));
github appium / appium-uiautomator2-driver / test / unit / installer-specs.js View on Github external
describe('appium-uiautomator2-installer', () => {
  describe.skip('setupUiAutomator2', withMocks({log}, (mocks) => {
    // TODO: this is NOT a UNIT TEST. Figure out if we need it, and if so,
    // how to fix it so it doesn't actually download the apks
    it('should download the server APKs', async () => {
      mocks.log.expects("error").never();
      await setupUiAutomator2();
      mocks.log.verify();
    });
  }));

  describe('serverExists', withMocks({fs}, (mocks) => {
    it('should return true if both server apk and test apk exist', async () => {
      mocks.fs.expects("exists").once()
        .withExactArgs(UI2_SERVER_APK_PATH)
        .returns(B.resolve(true));
      mocks.fs.expects("exists").once()
        .withExactArgs(UI2_TEST_APK_PATH)
github appium / appium-ios-driver / test / unit / utils-specs.js View on Github external
import * as utils from '../../lib/utils';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { withMocks } from 'appium-test-support';
import xcode from 'appium-xcode';


chai.should();
chai.use(chaiAsPromised);

describe('prepareIosOpts', withMocks({xcode}, (mocks) => {
  beforeEach(function () {
    mocks.xcode.expects('getMaxIOSSDK')
      .once().returns('9.3');
  });
  afterEach(function () {
    mocks.verify();
  });
  it('should use instruments without delay by default', async function () {
    const opts = {};
    await utils.prepareIosOpts(opts);
    opts.withoutDelay.should.be.true;
  });
  it('should use instruments without delay if explicitly not using native instruments', async function () {
    const opts = {nativeInstrumentsLib: false};
    await utils.prepareIosOpts(opts);
    opts.withoutDelay.should.be.true;
github appium / appium-ios-driver / test / unit / driver-specs.js View on Github external
await driver.asyncScriptTimeout(to);
        driver.asyncWaitMs.should.equal(to);
      });
    });
    describe('script, page load and implicit', function () {
      it('should be settable through `timeouts` for W3C', async function () {
        await driver.timeouts(undefined, undefined, 10, 20, 30);
        driver.implicitWaitMs.should.equal(30);
        driver.pageLoadMs.should.equal(20);
        driver.asyncWaitMs.should.equal(10);
      });
    });
  });
});

describe('getDeviceTime', withMocks({fs, teen_process}, (mocks) => {
  afterEach(function () {
    mocks.verify();
  });
  describe('real device', function () {
    const setup = function (mocks, opts = {}) {
      let udid = 'some-udid';
      let idevicedatePath = '/path/to/idevicedate';
      mocks.fs.expects('which')
        .once().returns(idevicedatePath);
      if (opts.date) {
        mocks.teen_process.expects('exec')
          .once().withExactArgs(idevicedatePath, ['-u', udid])
          .returns({stdout: opts.date});
      } else {
        mocks.teen_process.expects('exec')
          .once().withExactArgs(idevicedatePath, ['-u', udid])
github appium / appium-uiautomator2-driver / test / unit / uiautomator2-helper-specs.js View on Github external
describe('UiAutomator2 Driver Helpers', function () {
  const adb = new ADB();

  describe('ensureInternetPermissionForApp', withMocks({adb}, (mocks) => {
    const app = '/path/to/app.apk';
    afterEach(function () {
      mocks.verify();
    });
    it('should do nothing if app has internet perms', async function () {
      mocks.adb.expects('hasInternetPermissionFromManifest')
        .once()
        .withExactArgs(app)
        .returns(true);
      await helpers.ensureInternetPermissionForApp(adb, app);
    });
    it('should throw an error if app does not have internet perms', async function () {
      mocks.adb.expects('hasInternetPermissionFromManifest')
        .once()
        .withExactArgs(app)
        .returns(false);

appium-test-support

A collection of test utilities used across Appium packages

Apache-2.0
Latest version published 4 years ago

Package Health Score

39 / 100
Full package analysis

Popular appium-test-support functions