How to use the asyncbox.sleep function in asyncbox

To help you get started, we’ve selected a few asyncbox 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 / node-adb-client / test / functional / adb-e2e-specs.js View on Github external
it('should (the device) be available for commands after reboot', async function () {
      // override default timeout since we need to wait for the device to reboot
      this.timeout(30000);
      let command = {
        type:   "reboot"
      };
      await device.runCommand(command);
      // sleep then connect to the device again
      await sleep(20000); // time required before an S4 running Android 5 is available
      availableDevices = await ADB.findAdbDevices();
      // just select the first device
      device = new ADB(CONNECTION_TYPES.USB, availableDevices[0]);
      await device.connect();
      // run a very basic command to confirm device is okay
      let commandString = "cd sdcard/ ; pwd";
      let expectedReturnString = "/sdcard";
      let checkCommand = { // set print to false so we get the data back as a string
        type: "shell"
      , string: commandString
      , print: false
      };
      let output = await device.runCommand(checkCommand);
      output.trim().should.equal(expectedReturnString);
    });
  });
github appium / appium-android-driver / test / functional / settings-e2e-specs.js View on Github external
it('should toggle wifi on real devices', async function () {
      await driver.createSession(defaultCaps);
      let isWifiOn = await driver.isWifiOn();
      if (isWifiOn) {
        await driver.setWifiState(0, false);
        await sleep(500);
        isWifiOn = await driver.isWifiOn();
        isWifiOn.should.be.false;
      } else {
        await driver.setWifiState(1, false);
        // enabling wifi takes time
        await sleep(2500);
        isWifiOn = await driver.isWifiOn();
        isWifiOn.should.be.true;
      }
    });
  });
github appium / appium / test / driver-specs.js View on Github external
it('should remove session if inner driver unexpectedly exits with no error', async function () {
        let [sessionId,] = (await appium.createSession(_.clone(BASE_CAPS))).value; // eslint-disable-line comma-spacing
        _.keys(appium.sessions).should.contain(sessionId);
        appium.sessions[sessionId].eventEmitter.emit('onUnexpectedShutdown');
        // let event loop spin so rejection is handled
        await sleep(1);
        _.keys(appium.sessions).should.not.contain(sessionId);
      });
    });
github appium / appium-adb / lib / tools / system-calls.js View on Github external
try {
      const args = [...this.executable.defaultArgs, ...cmd];
      log.debug(`Running '${this.executable.path} ${quote(args)}'`);
      let {stdout} = await exec(this.executable.path, args, opts);
      // sometimes ADB prints out weird stdout warnings that we don't want
      // to include in any of the response data, so let's strip it out
      stdout = stdout.replace(LINKER_WARNING_REGEXP, '').trim();
      return stdout;
    } catch (e) {
      const errText = `${e.message}, ${e.stdout}, ${e.stderr}`;
      const protocolFaultError = PROTOCOL_FAULT_ERROR_REGEXP.test(errText);
      const deviceNotFoundError = DEVICE_NOT_FOUND_ERROR_REGEXP.test(errText);
      const deviceConnectingError = DEVICE_CONNECTING_ERROR_REGEXP.test(errText);
      if (protocolFaultError || deviceNotFoundError || deviceConnectingError) {
        log.info(`Error sending command, reconnecting device and retrying: ${cmd}`);
        await sleep(1000);
        await this.getDevicesWithRetry();

        // try again one time
        if (adbRetried) {
          adbRetried = true;
          return await execFunc();
        }
      }

      if (e.code === 0 && e.stdout) {
        return e.stdout.replace(LINKER_WARNING_REGEXP, '').trim();
      }

      if (_.isNull(e.code)) {
        e.message = `Error executing adbExec. Original error: '${e.message}'. ` +
          `Try to increase the ${opts.timeout}ms adb execution timeout represented by '${opts.timeoutCapName}' capability`;
github appium / appium-android-driver / lib / unlock-helpers.js View on Github external
included inside a FrameLayout, so we are going to try clicking on the buttons
  using the parent view bounds and math.
  */
  let apiLevel = await adb.getApiLevel();
  let el = await driver.findElOrEls('id',
    `com.android.${apiLevel >= 21 ? 'systemui' : 'keyguard'}:id/lockPatternView`,
    false
  );
  let initPos = await driver.getLocation(util.unwrapElement(el));
  let size = await driver.getSize(util.unwrapElement(el));
  // Get actions to perform
  let actions = helpers.getPatternActions(keys, initPos, size.width / 3);
  // Perform gesture
  await driver.performTouch(actions);
  // Waits a bit for the device to be unlocked
  await sleep(UNLOCK_WAIT_TIME);
};
github appium / appium-adb / test / functional / adb-emu-commands-e2e-specs.js View on Github external
it('fingerprint should open the secret activity on emitted valid finger touch event', async function () {
    if (await adb.isAppInstalled(pkg)) {
      await adb.forceStop(pkg);
      await adb.uninstallApk(pkg);
    }
    await adb.install(fingerprintPath);
    await adb.startApp({pkg, activity});
    await sleep(500);

    let app = await adb.getFocusedPackageAndActivity();
    app.appActivity.should.equal(activity);
    await adb.fingerprint(1111);
    await sleep(2500);

    app = await adb.getFocusedPackageAndActivity();
    app.appActivity.should.equal(secretActivity);
  });
});
github Samsung / appium-tizen-driver / lib / commands / element.js View on Github external
commands.touchLongClick = async function (elementId, x, y, duration) {
  await this.touchDown(x, y, elementId);
  await sleep(duration);
  return await this.touchUp(x, y, elementId);
};
github Samsung / appium-tizen-driver / lib / tizen-bootstrap.js View on Github external
async sendCommand (type, extra = {}) {
    if (this.appPackage && type !== COMMAND_TYPES.SHUTDOWN) {
      if (this.isRestart) {
        await sleep(5000);
        await this.restartUIAutomator();
        this.isRestart = false;
      }
      let isStartedApp = await this.sdb.isStartedApp(this.appPackage);
      if (!isStartedApp) {
        await this.sdb.startApp(this.appPackage);
        await sleep(10000);
        this.isRestart = false;
      }
    }

    if (!this.socketClient) {
      await this.connectSocket();
    }

    return await new B((resolve, reject) => {
      let cmd = Object.assign({ cmd: type }, extra);
      let cmdJson = `${JSON.stringify(cmd)} \n`;
      log.debug(`Sending command to tizen: ${_.truncate(cmdJson, { length: 1000 }).trim()}`);

      try {
        this.socketClient.removeAllListeners('timeout');
        this.socketClient.removeAllListeners('end');
github Samsung / appium-tizen-driver / lib / tizen-bootstrap.js View on Github external
async sendCommand (type, extra = {}) {
    if (this.appPackage && type !== COMMAND_TYPES.SHUTDOWN) {
      if (this.isRestart) {
        await sleep(5000);
        await this.restartUIAutomator();
        this.isRestart = false;
      }
      let isStartedApp = await this.sdb.isStartedApp(this.appPackage);
      if (!isStartedApp) {
        await this.sdb.startApp(this.appPackage);
        await sleep(10000);
        this.isRestart = false;
      }
    }

    if (!this.socketClient) {
      await this.connectSocket();
    }

    return await new B((resolve, reject) => {

asyncbox

A collection of small async/await utilities

Apache-2.0
Latest version published 12 months ago

Package Health Score

64 / 100
Full package analysis