How to use finishStartingLogCapture 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

...40 spawnEnv.PATH = `${process.env.PATH}:${DEVICE_CONSOLE_PATH}`;41 spawnEnv.DYLD_LIBRARY_PATH = `${DEVICE_CONSOLE_PATH}:${process.env.DYLD_LIBRARY_PATH}`;42 this.proc = new SubProcess('deviceconsole', ['-u', this.udid], {env: spawnEnv});43 }44 await this.finishStartingLogCapture();45 }46 async startCapture () {47 if (this.udid) { // if we have a real device48 return this.startCaptureRealDevice();49 }50 // otherwise, if we have a simulator...51 let xCodeVersion = await xcode.getVersion(true);52 logger.debug(`Starting iOS ${await this.sim.getPlatformVersion()} simulator log capture`);53 if (xCodeVersion.major < 5) {54 this.proc = new SubProcess('tail', ['-f', '-n', '1', SYSTEM_LOG_PATH]);55 await this.finishStartingLogCapture();56 return;57 }58 // this is xcode 6+59 if (_.isUndefined(this.sim.udid)) {60 logger.errorAndThrow(`iOS ${xCodeVersion.versionString} log capture requires a sim udid`);61 }62 let logPath = this.sim.getLogDir();63 try {64 if (logPath.indexOf('*') >= 0) {65 logger.error(`Log path has * in it. Unable to start log capture: ${logPath}`);66 return;67 }68 let systemLogPath = path.resolve(logPath, 'system.log');69 logger.debug(`System log path: ${systemLogPath}`);70 await mkdirp(logPath);71 await fs.writeFile(systemLogPath, 'A new Appium session is about to start!\n', {flag: 'a'});72 let files;73 try {74 files = await fs.glob(systemLogPath);75 if (files.length < 1) {76 throw new Error('Could not start log capture');77 }78 } catch (e) {79 logger.error(`Could not start log capture because no iOS ` +80 `simulator logs could be found at ${systemLogPath}. ` +81 `Logging will not be functional for this run`);82 }83 let lastModifiedLogPath = files[0];84 let lastModifiedLogTime = await fs.stat(lastModifiedLogPath).mtime;85 for (let file of files) {86 let mtime = await fs.stat(file).mtime;87 if (mtime > lastModifiedLogTime) {88 lastModifiedLogPath = file;89 lastModifiedLogTime = mtime;90 }91 }92 this.proc = new SubProcess('tail', ['-f', '-n', '1', lastModifiedLogPath]);93 await this.finishStartingLogCapture();94 } catch (err) {95 logger.errorAndThrow(`System log capture failed: ${err.message}`);96 }97 }98 async finishStartingLogCapture () {99 if (!this.proc) {100 logger.errorAndThrow('Could not capture device log');101 }102 let firstLine = true;103 this.proc.on('output', (stdout, stderr) => {104 if (stdout) {105 if (firstLine) {106 if (stdout.substr(-1, 1) === '\n') {107 // don't store the first line of the log because it came before the sim or device was launched...

Full Screen

Full Screen

ios-simulator-log.js

Source:ios-simulator-log.js Github

copy

Full Screen

...28 await exec('pkill', ['-xf', [tool, ...args].join(' ')]);29 } catch (ign) {}30 try {31 this.proc = new SubProcess(tool, args);32 await this.finishStartingLogCapture();33 } catch (e) {34 throw new Error(`Simulator log capture failed. Original error: ${e.message}`);35 }36 }37 async finishStartingLogCapture () {38 if (!this.proc) {39 log.errorAndThrow('Could not capture simulator log');40 }41 let firstLine = true;42 let logRow = '';43 this.proc.on('output', (stdout, stderr) => {44 if (stdout) {45 if (firstLine) {46 if (stdout.endsWith('\n')) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { finishStartingLogCapture } = require('appium-xcuitest-driver');2finishStartingLogCapture();3const { finishStartingLogCapture } = require('appium-xcuitest-driver/lib/commands/log');4finishStartingLogCapture();5const { finishStartingLogCapture } = require('appium-xcuitest-driver/build/lib/commands/log');6finishStartingLogCapture();7const { finishStartingLogCapture } = require('appium-xcuitest-driver');8finishStartingLogCapture().then((res) => {9 console.log(res);10});11const { finishStartingLogCapture } = require('appium-xcuitest-driver/lib/commands/log');12finishStartingLogCapture().then((res) => {13 console.log(res);14});15const { finishStartingLogCapture } = require('appium-xcuitest-driver/build/lib/commands/log');16finishStartingLogCapture().then((res) => {17 console.log(res);18});19const { finishStartingLogCapture } = require('appium-xcuitest-driver');20finishStartingLogCapture(true).then((res) => {21 console.log(res);22});23const { finishStartingLogCapture } = require('appium-xcuitest-driver/lib/commands/log');24finishStartingLogCapture(true).then((res) => {25 console.log(res);26});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AppiumDriver } = require('appium-base-driver');2const { XCUITestDriver } = require('appium-xcuitest-driver');3const { startServer } = require('appium');4async function main() {5 await startServer({6 });7 const appiumDriver = new AppiumDriver();8 const xcuitestDriver = new XCUITestDriver();9 await xcuitestDriver.finishStartingLogCapture();10 await xcuitestDriver.quit();11 await appiumDriver.quit();12}13main();14startLogCapture (opts = {})15opts: {16}17const { AppiumDriver } = require('appium-base-driver');18const { XCUITestDriver } = require('appium-xcuitest-driver');19const { startServer } = require('appium');20async function main() {21 await startServer({22 });23 const appiumDriver = new AppiumDriver();24 const xcuitestDriver = new XCUITestDriver();25 await xcuitestDriver.startLogCapture();26 await xcuitestDriver.quit();27 await appiumDriver.quit();28}29main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {XCUITestDriver} = require('appium-xcuitest-driver');2const {startLogCapture} = require('appium-ios-log');3const {startCapture} = require('appium-ios-device');4const {startCapture as startSimulatorCapture} = require('appium-ios-simulator');5const {startCapture as startWdaCapture} = require('appium-xcuitest-driver/lib/commands/log');6const xcodeLog = startLogCapture();7const deviceLog = startCapture();8const simulatorLog = startSimulatorCapture();9const wdaLog = startWdaCapture();10const driver = new XCUITestDriver();11driver.finishStartingLogCapture(xcodeLog, deviceLog, simulatorLog, wdaLog);12const {XCUITestDriver} = require('appium-xcuitest-driver');13const {startLogCapture} = require('appium-ios-log');14const {startCapture} = require('appium-ios-device');15const {startCapture as startSimulatorCapture} = require('appium-ios-simulator');16const {startCapture as startWdaCapture} = require('appium-xcuitest-driver/lib/commands/log');17const xcodeLog = startLogCapture();18const deviceLog = startCapture();19const simulatorLog = startSimulatorCapture();20const wdaLog = startWdaCapture();21const driver = new XCUITestDriver();22driver.finishStartingLogCapture(xcodeLog, deviceLog, simulatorLog, wdaLog);23const {XCUITestDriver} = require('appium-xcuitest-driver');24const {startLogCapture} = require('appium-ios-log');25const {startCapture} = require('appium-ios-device');26const {startCapture as startSimulatorCapture} = require('appium-ios-simulator');27const {startCapture as startWdaCapture} = require('appium-xcuitest-driver/lib/commands/log');28const xcodeLog = startLogCapture();29const deviceLog = startCapture();30const simulatorLog = startSimulatorCapture();31const wdaLog = startWdaCapture();32const driver = new XCUITestDriver();33driver.finishStartingLogCapture(xcodeLog, deviceLog, simulatorLog, wdaLog);

Full Screen

Using AI Code Generation

copy

Full Screen

1var appiumXCUITestDriver = require('appium-xcuitest-driver');2var startLogCapture = appiumXCUITestDriver.startLogCapture;3var finishLogCapture = appiumXCUITestDriver.finishLogCapture;4var startLogCapture = appiumXCUITestDriver.startLogCapture;5var finishLogCapture = appiumXCUITestDriver.finishLogCapture;6var appiumXCUITestDriver = require('appium-xcuitest-driver');7var startLogCapture = appiumXCUITestDriver.startLogCapture;8var finishLogCapture = appiumXCUITestDriver.finishLogCapture;9var startLogCapture = appiumXCUITestDriver.startLogCapture;10var finishLogCapture = appiumXCUITestDriver.finishLogCapture;11var appiumXCUITestDriver = require('appium-xcuitest-driver');12var startLogCapture = appiumXCUITestDriver.startLogCapture;13var finishLogCapture = appiumXCUITestDriver.finishLogCapture;14var startLogCapture = appiumXCUITestDriver.startLogCapture;15var finishLogCapture = appiumXCUITestDriver.finishLogCapture;16var appiumXCUITestDriver = require('appium-xcuitest-driver');17var startLogCapture = appiumXCUITestDriver.startLogCapture;18var finishLogCapture = appiumXCUITestDriver.finishLogCapture;19var startLogCapture = appiumXCUITestDriver.startLogCapture;20var finishLogCapture = appiumXCUITestDriver.finishLogCapture;

Full Screen

Using AI Code Generation

copy

Full Screen

1async startLogCapture () {2}3async stopLogCapture () {4}5commands.getLogTypes = async function () {6};7commands.getLog = async function (logType, opts) {8};9commands.execute = async function (script, args) {10};11commands.executeAsync = async function (script, args) {12};

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