Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "appium-support in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'appium-support' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

// add if this is a new page
    if (!_.includes(this.contexts, contextId)) {
      newPages.push(id);
      this.contexts.push(contextId);
    }
  }

  if (!keyId) {
    // if there is no key id, pull the first id from the page array and use that
    // as a stand in
    log.debug('No key id found. Choosing first id from page array');
    keyId = newIds[0] || null;
  }

  if (!util.hasValue(this.curContext)) {
    log.debug('We do not appear to have window set yet, ignoring');
    return;
  }

  const [curAppIdKey, curPageIdKey] = this.curContext.split('.');

  if (curAppIdKey !== appIdKey) {
    log.debug('Page change not referring to currently selected app, ignoring.');
    return;
  }

  let newPage = null;
  if (newPages.length) {
    newPage = _.last(newPages);
    log.debug(`We have new pages, selecting page '${newPage}'`);
  } else if (!_.includes(newIds, curPageIdKey)) {
for (const line of (initiator.stackTrace || [])) {
      const functionName = line.functionName || '(anonymous)';

      const url = (!line.url || line.url === '[native code]')
        ? ''
        : `@${_.last((URL.parse(line.url).pathname || '').split('/'))}:${line.lineNumber}`;
      this.log.debug(`    ${_.padEnd(_.truncate(functionName, {length: 20}), 21)} ${url}`);
    }
    // get `memory-cache` or `disk-cache`, etc., right
    const sizeStr = source.includes('cache') ? ` (from ${source.replace('-', ' ')})` : `${size}B`;
    this.log.debug(`  Size: ${sizeStr}`);
    this.log.debug(`  Time: ${Math.round(time)}ms`);
    if (errorText) {
      this.log.debug(`  Error: ${errorText}`);
    }
    if (util.hasValue(cancelled)) {
      this.log.debug(`  Cancelled: ${cancelled}`);
    }
  }
it('should generate dynamic bootstrap', async () => {
    process.env.APPIUM_BOOTSTRAP_DIR = path.resolve('/', 'tmp', 'appium-uiauto', 'test', 'unit', 'bootstrap');
    if (await fs.exists(process.env.APPIUM_BOOTSTRAP_DIR)) {
      await fs.rimraf(process.env.APPIUM_BOOTSTRAP_DIR);
    }

      // first call: should create new bootstrap file
    let bootstrapFile = await uiauto.prepareBootstrap();
    bootstrapFile.should.match(/\/tmp\/appium-uiauto\/test\/unit\/bootstrap\/bootstrap\-.*\.js/);
    let code = await fs.readFile(bootstrapFile, 'utf8');
    await checkCode(code);
    log.debug.calledWithMatch(/Creating or overwriting dynamic bootstrap/).should.be.true;
    log.debug.resetHistory();

    // second call: should reuse bootstrap file
    bootstrapFile = await uiauto.prepareBootstrap();
    bootstrapFile.should.match(/\/tmp\/appium-uiauto\/test\/unit\/bootstrap\/bootstrap\-.*\.js/);
    code = await fs.readFile(bootstrapFile, 'utf8');
    await checkCode(code);
    log.debug.calledWithMatch(/Reusing dynamic bootstrap/).should.be.true;
    log.debug.resetHistory();

    // third call using custom socket path: should create different bootstrap file
    bootstrapFile = await uiauto.prepareBootstrap({sock: '/tmp/abcd/sock'});
    bootstrapFile.should.match(/\/tmp\/appium-uiauto\/test\/unit\/bootstrap\/bootstrap\-.*\.js/);
    code = await fs.readFile(bootstrapFile, 'utf8');
it('should pull a folder from filesystem as a base64 zip, extract the zip and have same contents as in filesystem', async function () {
      // Create a temporary directory with one file in it
      const tempPath = await tempDir.openDir();
      await fs.writeFile(path.resolve(tempPath, 'a.txt'), 'Hello World!');

      const getSimPathStub = sinon.stub(driver, 'getSimFileFullPath').returns(tempPath);

      // Zip the directory to base64 and write it to 'zip.zip'
      const zippedData = await driver.pullFolder('/does/not/matter');
      const zippedFilepath = path.resolve(tempPath, 'zip.zip');
      await fs.writeFile(zippedFilepath, zippedData, {encoding: 'base64'});

      // Unzip it and check it matches original file contents
      const unzippedDir = path.resolve(tempPath, 'unzipped');
      await zip.extractAllTo(zippedFilepath, unzippedDir);
      await fs.readFile(path.resolve(unzippedDir, 'a.txt'), {encoding: 'utf8'}).should.eventually.equal('Hello World!');

      getSimPathStub.restore();
    });
  });
// transpile:mocha

import B from 'bluebird';
import path from 'path';
import { exec, SubProcess } from '..';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { getFixture } from './helpers';
import { system } from 'appium-support';


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

// Windows doesn't understand SIGHUP
const stopSignal = system.isWindows() ? 'SIGTERM' : 'SIGHUP';

describe('SubProcess', function () {
  it('should throw an error if initialized without a command', function () {
    should.throw(() => {
      new SubProcess();
    });
  });
  it('should throw an error if initialized with a bad command', function () {
    should.throw(() => {
      new SubProcess({lol: true});
    });
    should.throw(() => {
      new SubProcess(1);
    });
  });
  it('should throw an error if initialized with bad args', function () {
it('should pull a folder', async function () {
    const stringData = `random string data ${Math.random()}`;
    const base64Data = Buffer.from(stringData).toString('base64');

    // send the files, then pull the whole folder
    const remoteDir = getRandomDir();
    await driver.pushFile(`${remoteDir}/remote0.txt`, base64Data);
    await driver.pushFile(`${remoteDir}/remote1.txt`, base64Data);
    const data = await driver.pullFolder(remoteDir);

    const tmpRoot = await tempDir.openDir();
    try {
      const zipPath = path.resolve(tmpRoot, 'data.zip');
      await fs.writeFile(zipPath, Buffer.from(data, 'base64'));
      const extractedDataPath = path.resolve(tmpRoot, 'extracted_data');
      await fs.mkdir(extractedDataPath);
      await zip.extractAllTo(zipPath, extractedDataPath);
      const itemsCount = (await fs.readdir(extractedDataPath)).length;
      itemsCount.should.eql(2);
    } finally {
      await fs.rimraf(tmpRoot);
    }
  });
});
it('should pull a folder from filesystem as a base64 zip, extract the zip and have same contents as in filesystem', async function () {
      // Create a temporary directory with one file in it
      const tempPath = await tempDir.openDir();
      await fs.writeFile(path.resolve(tempPath, 'a.txt'), 'Hello World!');

      const getSimPathStub = sinon.stub(driver, 'getSimFileFullPath').returns(tempPath);

      // Zip the directory to base64 and write it to 'zip.zip'
      const zippedData = await driver.pullFolder('/does/not/matter');
      const zippedFilepath = path.resolve(tempPath, 'zip.zip');
      await fs.writeFile(zippedFilepath, zippedData, {encoding: 'base64'});

      // Unzip it and check it matches original file contents
      const unzippedDir = path.resolve(tempPath, 'unzipped');
      await zip.extractAllTo(zippedFilepath, unzippedDir);
      await fs.readFile(path.resolve(unzippedDir, 'a.txt'), {encoding: 'utf8'}).should.eventually.equal('Hello World!');

      getSimPathStub.restore();
    });
it.skip('should compile and insert manifest', async function () {
    let appPackage = 'com.example.android.contactmanager',
        newServerPath = path.resolve(tmpDir, `selendroid.${appPackage}.apk`),
        newPackage = 'com.example.android.contactmanager.selendroid',
        dstDir = path.resolve(tmpDir, appPackage),
        dstManifest = path.resolve(dstDir, 'AndroidManifest.xml');
    // deleting temp directory if present
    try {
      await fs.rimraf(tmpDir);
    } catch (e) {
      console.log(`Unable to delete temp directory. It might not be present. ${e.message}`); // eslint-disable-line no-console
    }
    await fs.mkdir(tmpDir);
    await fs.mkdir(dstDir);
    await fs.writeFile(dstManifest, await fs.readFile(srcManifest, 'utf8'), 'utf8');
    await adb.compileManifest(dstManifest, newPackage, appPackage);
    (await util.fileExists(dstManifest)).should.be.true;
    await adb.insertManifest(dstManifest, serverPath, newServerPath);
    (await util.fileExists(newServerPath)).should.be.true;
    // deleting temp directory
    try {
      await fs.rimraf(tmpDir);
    } catch (e) {
      console.log(`Unable to delete temp directory. It might not be present. ${e.message}`); // eslint-disable-line no-console
    }
  });
});
it.skip('should compile and insert manifest', async function () {
    let appPackage = 'com.example.android.contactmanager',
        newServerPath = path.resolve(tmpDir, `selendroid.${appPackage}.apk`),
        newPackage = 'com.example.android.contactmanager.selendroid',
        dstDir = path.resolve(tmpDir, appPackage),
        dstManifest = path.resolve(dstDir, 'AndroidManifest.xml');
    // deleting temp directory if present
    try {
      await fs.rimraf(tmpDir);
    } catch (e) {
      console.log(`Unable to delete temp directory. It might not be present. ${e.message}`); // eslint-disable-line no-console
    }
    await fs.mkdir(tmpDir);
    await fs.mkdir(dstDir);
    await fs.writeFile(dstManifest, await fs.readFile(srcManifest, 'utf8'), 'utf8');
    await adb.compileManifest(dstManifest, newPackage, appPackage);
    (await util.fileExists(dstManifest)).should.be.true;
    await adb.insertManifest(dstManifest, serverPath, newServerPath);
    (await util.fileExists(newServerPath)).should.be.true;
    // deleting temp directory
    try {
      await fs.rimraf(tmpDir);
    } catch (e) {
      console.log(`Unable to delete temp directory. It might not be present. ${e.message}`); // eslint-disable-line no-console
    }
  });
});
async launch (sessionId) {
    if (this.webDriverAgentUrl) {
      log.info(`Using provided WebdriverAgent at '${this.webDriverAgentUrl}'`);
      this.url = this.webDriverAgentUrl;
      this.setupProxies(sessionId);
      return this.webDriverAgentUrl;
    }

    log.info('Launching WebDriverAgent on the device');

    this.setupProxies(sessionId);

    if (!await fs.exists(this.agentPath)) {
      throw new Error(`Trying to use WebDriverAgent project at '${this.agentPath}' but the ` +
                      'file does not exist');
    }

    // make sure that the WDA dependencies have been built
    await checkForDependencies(this.bootstrapPath, this.useCarthageSsl);

    // if necessary, update the bundleId to user's specification
    if (this.realDevice && this.updatedWDABundleId) {
      await updateProjectFile(this.agentPath, this.updatedWDABundleId);
    }

    //kill all hanging processes
    await this.killHangingProcesses();

    if (this.xcodeVersion.major === 7 || (this.xcodeVersion.major === 8 && this.xcodeVersion.minor === 0)) {

Is your System Free of Underlying Vulnerabilities?
Find Out Now