How to use killLogSubProcess method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

ios-log-specs.js

Source:ios-log-specs.js Github

copy

Full Screen

1// transpile:mocha2import { IOSLog } from '../..';3import { DEVICE_CONSOLE_PATH } from '../../lib/device-log/ios-log';4import sinon from 'sinon';5import { fs } from 'appium-support';6import path from 'path';7import logger from '../../lib/device-log/logger';8import chai from 'chai';9import chaiAsPromised from 'chai-as-promised';10import B from 'bluebird';11const should = chai.should();12chai.use(chaiAsPromised);13const LOG_DIR = path.resolve('test', 'assets', 'logs');14describe('system logs', function () {15  let tmpSystemLog;16  let sim;17  beforeEach(async function () {18    // get the simulator, and stub what will be called19    sim = {20      udid: 'fake-udid',21      getLogDir: () => {},22      getPlatformVersion: () => {}23    };24    sinon.stub(sim, 'getLogDir').returns(LOG_DIR);25    sinon.stub(sim, 'getPlatformVersion').returns('8.4');26    // copy the file into a temporary location, so we can muck with it27    let fixSystemLog = path.resolve(LOG_DIR, 'system.log.fixture');28    tmpSystemLog = path.resolve(LOG_DIR, 'system.log');29    await fs.copyFile(fixSystemLog, tmpSystemLog);30  });31  afterEach(async function () {32    if (await fs.exists(tmpSystemLog)) {33      await fs.unlink(tmpSystemLog);34    }35  });36  it('should begin log capture', async function () {37    let log = new IOSLog({38      sim,39      showLogs: true,40      xcodeVersion: {41        major: 742      },43    });44    let spy = sinon.spy(logger, 'info');45    await log.startCapture();46    let message = 'This is a test log line';47    await fs.writeFile(tmpSystemLog, `${message}\n`, {flag: 'a'});48    // on some slow system (e.g., Travis) need a moment49    await B.delay(500);50    spy.calledWith(`[IOS_SYSLOG_ROW] ${message}`).should.be.true;51    await log.stopCapture();52  });53  it('should rotate log buffer', async function () {54    const maxBufferSize = 10;55    const sliceSizeLimit = maxBufferSize / 2;56    sliceSizeLimit.should.be.below(maxBufferSize);57    const logRecordsCount = maxBufferSize * 2;58    logRecordsCount.should.be.above(maxBufferSize);59    let log = new IOSLog({60      sim,61      showLogs: false,62      xcodeVersion: {63        major: 764      },65    });66    log.maxBufferSize = maxBufferSize;67    log.logIdxSinceLastRequest.should.be.below(0);68    let recentLogs = await log.getLogs();69    recentLogs.should.have.lengthOf(0);70    log.logIdxSinceLastRequest.should.be.below(0);71    for (let i = 1; i <= logRecordsCount; ++i) {72      log.logRow = `${i}\n`;73      log.onOutput();74      if (i >= sliceSizeLimit && i % sliceSizeLimit === 0) {75        let previousRecentLogs = recentLogs;76        recentLogs = await log.getLogs();77        if (previousRecentLogs.length && recentLogs.length) {78          previousRecentLogs[0].message.should.not.be.equal(recentLogs[0].message);79        }80        recentLogs.should.have.lengthOf(sliceSizeLimit);81        let reminder = log.logIdxSinceLastRequest % sliceSizeLimit;82        reminder.should.equal(0);83      }84      log.logs.should.have.lengthOf(i < maxBufferSize ? i : maxBufferSize);85    }86    const firstBufferMessage = parseInt(log.logs[0].message, 10);87    firstBufferMessage.should.be.equal(logRecordsCount - log.logs.length + 1);88    const lastBufferMessage = parseInt(log.logs[log.logs.length - 1].message, 10);89    lastBufferMessage.should.be.equal(logRecordsCount);90  });91  describe('real device logging', function () {92    function getLogger (realDeviceLogger, udid = '1234') {93      let log = new IOSLog({sim, udid, realDeviceLogger});94      log.finishStartingLogCapture = async function () {};95      return log;96    }97    describe('idevicesyslog', function () {98      describe('system version', function () {99        let whichStub;100        afterEach(function () {101          whichStub.restore();102        });103        it('should use system idevicesyslog if no path specified', async function () {104          whichStub = sinon.stub(fs, 'which').returns('/path/to/idevicesyslog');105          let log = getLogger('idevicesyslog');106          await log.startCapture();107          log.proc.cmd.should.eql('idevicesyslog');108        });109        it('should fail if no system idevicesyslog found', async function () {110          whichStub = sinon.stub(fs, 'which').throws(new Error('ENOENT'));111          let log = getLogger('idevicesyslog');112          await log.startCapture().should.eventually.be.rejectedWith(/Unable to find system idevicesyslog/);113        });114      });115      describe('specific path', function () {116        let existstub;117        afterEach(function () {118          existstub.restore();119        });120        it('should use specified idevicesyslog if given', async function () {121          existstub = sinon.stub(fs, 'exists').returns(true);122          let log = getLogger('/path/to/my/idevicesyslog');123          await log.startCapture();124          log.proc.cmd.should.eql('/path/to/my/idevicesyslog');125        });126        it('should fail if specified idevicesyslog is not found', async function () {127          existstub = sinon.stub(fs, 'exists').returns(false);128          let log = getLogger('/path/to/my/idevicesyslog');129          await log.startCapture().should.eventually.be.rejectedWith(/Unable to find idevicesyslog from 'realDeviceLogger' capability/);130        });131      });132      describe('cache idevicesyslog instances', function () {133        let log, logForSameDevice, logForOtherDevice;134        let whichStub;135        before (function () {136          whichStub = sinon.stub(fs, 'which').returns(true);137          IOSLog.cachedIDeviceSysLogs = {};138        });139        after (function () {140          whichStub.restore();141        });142        beforeEach(async function () {143          // Create two loggers for udid 1234 and one for udid 4567144          log = getLogger('idevicesyslog');145          logForSameDevice = getLogger('idevicesyslog');146          logForOtherDevice = getLogger('idevicesyslog', '4567');147          // Start capturing148          await log.startCapture();149          await logForSameDevice.startCapture();150          await logForOtherDevice.startCapture();151        });152        afterEach(async function () {153          await log.stopCapture();154          await logForSameDevice.stopCapture();155          await logForOtherDevice.stopCapture();156        });157        it('should use same subprocess for same device', function () {158          logForSameDevice.proc.should.equal(log.proc);159          logForOtherDevice.proc.should.not.equal(log.proc);160        });161        it('should cache idevicesyslog subprocesses per device', function () {162          IOSLog.cachedIDeviceSysLogs[log.subprocessId].proc.should.equal(log.proc);163          IOSLog.cachedIDeviceSysLogs[log.subprocessId].proc.should.equal(logForSameDevice.proc);164          IOSLog.cachedIDeviceSysLogs[log.subprocessId].count.should.equal(2);165          IOSLog.cachedIDeviceSysLogs[logForOtherDevice.subprocessId].proc.should.equal(logForOtherDevice.proc);166          IOSLog.cachedIDeviceSysLogs[logForOtherDevice.subprocessId].count.should.equal(1);167        });168        it('should delete cached subprocess for a device when its only logger has stopped', async function () {169          IOSLog.cachedIDeviceSysLogs[logForOtherDevice.subprocessId].should.exist;170          await logForOtherDevice.stopCapture();171          should.not.exist(IOSLog.cachedIDeviceSysLogs[logForOtherDevice.subprocessId]);172        });173        it('should delete cached subprocesses for a device when all loggers per stopped', async function () {174          IOSLog.cachedIDeviceSysLogs[log.subprocessId].should.exist;175          await log.stopCapture();176          IOSLog.cachedIDeviceSysLogs[log.subprocessId].should.exist;177          await logForSameDevice.stopCapture();178          should.not.exist(IOSLog.cachedIDeviceSysLogs[log.subprocessId]);179          await logForOtherDevice.stopCapture();180          IOSLog.cachedIDeviceSysLogs.should.eql({});181        });182        it('should not stop idevicesyslog if another one is open for the same device', async function () {183          const killSubProcSpy = sinon.spy(log, 'killLogSubProcess');184          const otherKillSubProcSpy = sinon.spy(logForSameDevice, 'killLogSubProcess');185          await log.stopCapture();186          await logForSameDevice.stopCapture();187          killSubProcSpy.notCalled.should.be.true;188          otherKillSubProcSpy.calledOnce.should.be.true;189        });190        it('should kill the cache if "exit" event was called on the process', async function () {191          IOSLog.cachedIDeviceSysLogs[log.subprocessId].proc.should.equal(log.proc);192          log.proc.emit('exit');193          should.not.exist(IOSLog.cachedIDeviceSysLogs[log.subprocessId]);194          await log.startCapture();195          await logForSameDevice.startCapture();196          IOSLog.cachedIDeviceSysLogs[log.subprocessId].proc.should.equal(log.proc);197        });198      });199    });200    describe('deviceconsole', function () {201      let dcPath = '/path/to/deviceconsole/install/directory';202      let statStub;203      afterEach(function () {204        statStub.restore();205      });206      function initStatStub (directory = true, throws = false) {207        statStub = sinon.stub(fs, 'stat');208        if (throws) {209          statStub.throws(new Error('ENOENT'));210        } else {211          statStub.returns({212            isDirectory () {213              return directory;214            }215          });216        }217      }218      it('should correctly parse the install directory from executable path', async function () {219        initStatStub(false);220        let log = getLogger(`${dcPath}/deviceconsole`);221        await log.startCapture();222        log.proc.cmd.should.eql(`${dcPath}/deviceconsole`);223        log.proc.opts.env.DYLD_LIBRARY_PATH.indexOf(dcPath).should.eql(0);224      });225      it('should correctly use the install directory when given directly', async function () {226        initStatStub();227        let log = getLogger(dcPath);228        await log.startCapture();229        log.proc.cmd.should.eql(`${dcPath}/deviceconsole`);230        log.proc.opts.env.DYLD_LIBRARY_PATH.indexOf(dcPath).should.eql(0);231      });232      it('should use default deviceconsole if path not passed in', async function () {233        initStatStub();234        let log = getLogger(`deviceconsole`);235        await log.startCapture();236        log.proc.cmd.should.eql(`${DEVICE_CONSOLE_PATH}/deviceconsole`);237        log.proc.opts.env.DYLD_LIBRARY_PATH.indexOf(DEVICE_CONSOLE_PATH).should.eql(0);238      });239      it('should fail if an executable other than deviceconsole is passed in', async function () {240        initStatStub(false);241        let log = getLogger(`${dcPath}/someotherlogger`);242        await log.startCapture().should.eventually.be.rejectedWith(/Unable to parse 'deviceconsole' installation directory/);243      });244      it('should fail if path passed in is not stat-able', async function () {245        initStatStub(false, true);246        let log = getLogger(`/path/to/something/that/does/not/exist`);247        await log.startCapture().should.eventually.be.rejectedWith(/Unknown 'realDeviceLogger'/);248      });249    });250    describe('anything else', function () {251      it('should fail if something other than idevicesyslog or deviceconsole are specified', async function () {252        let log = getLogger('mysupadupalogga');253        await log.startCapture().should.eventually.be.rejectedWith(/Unable to capture device log. Unknown 'realDeviceLogger'/);254      });255    });256  });...

Full Screen

Full Screen

ios-log.js

Source:ios-log.js Github

copy

Full Screen

...191        const cachedSysLog = IOSLog.cachedIDeviceSysLogs[this.subprocessId];192        if (cachedSysLog) {193          cachedSysLog.count--;194          if (cachedSysLog.count === 0) {195            await this.killLogSubProcess();196            delete IOSLog.cachedIDeviceSysLogs[this.subprocessId];197          }198        }199      } else {200        await this.killLogSubProcess();201      }202    }203    this.proc = null;204  }205  async killLogSubProcess () {206    if (this.proc.isRunning) {207      logger.debug('Stopping iOS log capture');208      try {209        await this.proc.stop('SIGTERM', 1000);210      } catch (e) {211        logger.error('Cannot stop log capture process. Sending SIGKILL...');212        await this.proc.stop('SIGKILL');213      }214    }...

Full Screen

Full Screen

ios-simulator-log.js

Source:ios-simulator-log.js Github

copy

Full Screen

...70  async stopCapture () {71    if (!this.proc) {72      return;73    }74    await this.killLogSubProcess();75    this.proc = null;76  }77  async killLogSubProcess () {78    if (!this.proc.isRunning) {79      return;80    }81    log.debug('Stopping iOS log capture');82    try {83      await this.proc.stop('SIGTERM', 1000);84    } catch (e) {85      if (!this.proc.isRunning) {86        return;87      }88      logger.warn('Cannot stop log capture process. Sending SIGKILL...');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { killLogSubProcess } = require('appium-xcuitest-driver');2killLogSubProcess();3const { killLogSubProcess } = require('appium-xcuitest-driver');4killLogSubProcess();5const { killLogSubProcess } = require('appium-xcuitest-driver');6killLogSubProcess();7const { killLogSubProcess } = require('appium-xcuitest-driver');8killLogSubProcess();9const { killLogSubProcess } = require('appium-xcuitest-driver');10killLogSubProcess();11const { killLogSubProcess } = require('appium-xcuitest-driver');12killLogSubProcess();13const { killLogSubProcess } = require('appium-xcuitest-driver');14killLogSubProcess();15const { killLogSubProcess } = require('appium-xcuitest-driver');16killLogSubProcess();17const { killLogSubProcess } = require('appium-xcuitest-driver');18killLogSubProcess();19const { killLogSubProcess } = require('appium-xcuitest-driver');20killLogSubProcess();21const { killLogSubProcess } = require('appium-xcuitest-driver');22killLogSubProcess();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { XCUITestDriver } = require('appium-xcuitest-driver');2const { AppiumXCUITestDriver } = require('appium-xcuitest-driver');3const driver = new AppiumXCUITestDriver();4driver.createSession({});5driver.killLogSubProcess();6const { XCUITestDriver } = require('appium-xcuitest-driver');7const { AppiumXCUITestDriver } = require('appium-xcuitest-driver');8const driver = new AppiumXCUITestDriver();9driver.createSession({});10driver.killLogSubProcess();11const { XCUITestDriver } = require('appium-xcuitest-driver');12const { AppiumXCUITestDriver } = require('appium-xcuitest-driver');13const driver = new AppiumXCUITestDriver();14driver.createSession({});15driver.killLogSubProcess();16const { XCUITestDriver } = require('appium-xcuitest-driver');17const { AppiumXCUITestDriver } = require('appium-xcuitest-driver');18const driver = new AppiumXCUITestDriver();19driver.createSession({});20driver.killLogSubProcess();21const { XCUITestDriver } = require('appium-xcuitest-driver');

Full Screen

Using AI Code Generation

copy

Full Screen

1commands.startLogSubProcess = async function (opts = {}) {2  const {logType, pid} = opts;3  if (logType === LOG_TYPES.syslog) {4    return await startSyslogCapture(pid);5  }6  log.warn(`Unsupported log type '${logType}'`);7  return null;8};9commands.stopLogSubProcess = async function (opts = {}) {10  const {logType, logSubProcess} = opts;11  if (logType === LOG_TYPES.syslog) {12    return await stopSyslogCapture(logSubProcess);13  }14  log.warn(`Unsupported log type '${logType}'`);15  return null;16};17commands.killLogSubProcess = async function (opts = {}) {18  const {logType, logSubProcess} = opts;19  if (logType === LOG_TYPES.syslog) {20    return await killSyslogCapture(logSubProcess);21  }22  log.warn(`Unsupported log type '${logType}'`);23  return null;24};25async function startSyslogCapture (pid) {26  const log = getLogger('iOSSyslog');27  await killSyslogCapture();28  const args = ['-w', '-k', 'SenderImageUUID', '-k', 'TimeSinceBoot', '-k', 'Message', '-k', 'ProcessID', '-k', 'Level', '-k', 'Sender', '-k', 'PID', '-k', 'ActivityID', '-k', 'Subsystem', '-k', 'Category', '-k', 'ImageUUID', '-k', 'ImageOffset', '-k', 'ThreadID', '-k', 'Continuation', '-k', 'SenderImagePath', '-k', 'SenderMachUUID', '-k', 'AuxMessage', '-k', 'AuxImageUUID', '-k', 'AuxImageOffset', '-k', 'AuxMachUUID', '-k', 'AuxImagePath', '-k', 'SenderImageOffset', '-k', 'SenderMachUUID', '--predicate', `processID == ${pid}`];29  const syslog = spawn('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { killLogSubProcess } = require('appium-xcuitest-driver/lib/commands/log');2killLogSubProcess();3const { killLogSubProcess } = require('appium-ios-driver/lib/commands/log');4killLogSubProcess();5const { killLogSubProcess } = require('appium-xcuitest-driver/lib/commands/log');6killLogSubProcess();7const { killLogSubProcess } = require('appium-ios-driver/lib/commands/log');8killLogSubProcess();9const { killLogSubProcess } = require('appium-xcuitest-driver/lib/commands/log');10killLogSubProcess();11const { killLogSubProcess } = require('appium-ios-driver/lib/commands/log');12killLogSubProcess();13const { killLogSubProcess } = require('appium-xcuitest-driver/lib/commands/log');14killLogSubProcess();15const { killLogSubProcess } = require('appium-ios-driver/lib/commands/log');16killLogSubProcess();17const { killLogSubProcess } = require('appium-xcuitest-driver/lib/commands/log');18killLogSubProcess();19const { killLogSubProcess } = require('appium-ios-driver/lib/commands/log');20killLogSubProcess();21const { killLogSubProcess } = require('appium-xcuitest-driver/lib/commands/log');22killLogSubProcess();23const { killLogSubProcess } = require('appium-ios-driver/lib/commands/log');24killLogSubProcess();

Full Screen

Using AI Code Generation

copy

Full Screen

1var xcuittest = require('appium-xcuitest-driver');2var driver = new xcuittest.XCUITestDriver();3driver.killLogSubProcess();4var xcuittest = require('appium-xcuitest-driver');5var driver = new xcuittest.XCUITestDriver();6driver.killLogSubProcess();7var xcuittest = require('appium-xcuitest-driver');8var driver = new xcuittest.XCUITestDriver();9driver.killLogSubProcess();10var xcuittest = require('appium-xcuitest-driver');11var driver = new xcuittest.XCUITestDriver();12driver.killLogSubProcess();13var xcuittest = require('appium-xcuitest-driver');14var driver = new xcuittest.XCUITestDriver();15driver.killLogSubProcess();16var xcuittest = require('appium-xcuitest-driver');17var driver = new xcuittest.XCUITestDriver();18driver.killLogSubProcess();19var xcuittest = require('appium-xcuitest-driver');20var driver = new xcuittest.XCUITestDriver();21driver.killLogSubProcess();22var xcuittest = require('appium-xcuitest-driver');23var driver = new xcuittest.XCUITestDriver();24driver.killLogSubProcess();25var xcuittest = require('appium-xcuitest-driver');26var driver = new xcuittest.XCUITestDriver();27driver.killLogSubProcess();28var xcuittest = require('appium-xcuitest-driver');29var driver = new xcuittest.XCUITestDriver();

Full Screen

Using AI Code Generation

copy

Full Screen

1const appium = require('appium');2const { XCUITestDriver } = appium.xcuitest;3let driver = new XCUITestDriver();4driver.killLogSubProcess();5driver = null;6@shruti-rajagopalan I don’t think this is an issue. The method killLogSubProcess() is available only in the XCUITestDriver class, not in the Driver class. You can check the source code here:

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful