Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getDriverInfo () {
const stat = await fs.stat(path.resolve(__dirname, '..'));
const built = stat.mtime.getTime();
// get the package.json and the version from it
const pkg = require(__filename.includes('build/lib/utils') ? '../../package.json' : '../package.json');
const version = pkg.version;
return {
built,
version,
};
}
let files;
try {
files = await fs.glob(systemLogPath);
if (files.length < 1) {
throw new Error('Could not start log capture');
}
} catch (e) {
logger.error(`Could not start log capture because no iOS ` +
`simulator logs could be found at ${systemLogPath}. ` +
`Logging will not be functional for this run`);
}
let lastModifiedLogPath = files[0];
let lastModifiedLogTime = (await fs.stat(lastModifiedLogPath)).mtime;
for (let file of files) {
let {mtime} = await fs.stat(file);
if (mtime > lastModifiedLogTime) {
lastModifiedLogPath = file;
lastModifiedLogTime = mtime;
}
}
const tailArgs = ['-f', '-n', '1', lastModifiedLogPath];
try {
// cleanup existing listeners if the previous session has not been terminated properly
await exec('pkill', ['-xf', ['tail', ...tailArgs].join(' ')]);
} catch (e) {}
this.proc = new SubProcess('tail', tailArgs);
await this.finishStartingLogCapture();
} catch (err) {
logger.errorAndThrow(`Simulator log capture failed: ${err.message}`);
}
}
cmd = this.realDeviceLogger;
}
args = ['-u', this.udid];
env = process.env;
} else if ((this.realDeviceLogger || '').indexOf('deviceconsole') !== -1) {
logger.debug('Attempting iOS device log capture via deviceconsole');
let deviceconsole;
if (this.realDeviceLogger.toLowerCase() === 'deviceconsole') {
deviceconsole = DEVICE_CONSOLE_PATH;
} else {
// make sure that we have the path to the directory,
// not the actual executable
let stat;
try {
stat = await fs.stat(this.realDeviceLogger);
} catch (err) {
throw new Error(`Unable to find deviceconsole from 'realDeviceLogger' capability '${this.realDeviceLogger}': ${err.message}`);
}
if (stat.isDirectory()) {
deviceconsole = this.realDeviceLogger;
} else {
// make sure they've passed in `deviceconsole` and not something random
if (!_.endsWith(this.realDeviceLogger, 'deviceconsole')) {
throw new Error(`Unable to parse 'deviceconsole' installation directory from '${this.realDeviceLogger}'`);
}
// remove the executable, and trailing `/`, to get the install directory
deviceconsole = path.dirname(this.realDeviceLogger);
}
}
logger.debug(`Using 'deviceconsole' from '${deviceconsole}'`);
it('should upload largeFile to device', async () => {
const stats = await fs.stat(largeFile);
const largeFileSize = stats.size.toString();
let command = {
type: "push"
, source: largeFile
, destination: destination
};
await device.runCommand(command);
let lsCommand = {
type: "shell"
, string: "ls -al sdcard/ | grep largeFile"
, print: false
};
let output = await device.runCommand(lsCommand);
output.indexOf(largeFileSize).should.not.equal(-1);
});
it('should install for all platforms', async function () {
this.timeout(120000);
await assertNoPreviousDirs();
await installAll();
for (let [platform, arch] of getPlatforms()) {
let cdPath = await getChromedriverBinaryPath(platform, arch);
let cdStat = await fs.stat(cdPath);
cdStat.size.should.be.above(500000);
cdPath.should.contain(platform);
if (platform === 'linux') {
cdPath.should.contain(arch);
} else {
cdPath.should.not.contain(arch);
}
}
});
it('should throw an error in chromedriver if nothing is installed', async function () {
it('should upload smallFile to device', async () => {
const stats = await fs.stat(smallFile);
const smallFileSize = stats.size.toString();
let command = {
type: "push"
, source: smallFile
, destination: destination
};
await device.runCommand(command);
let lsCommand = {
type: "shell"
, string: "ls -al sdcard/ | grep smallFile"
, print: false
};
let output = await device.runCommand(lsCommand);
output.indexOf(smallFileSize).should.not.equal(-1);
});
return await B.map(paths, async (fullPath) => {
const stat = await fs.stat(fullPath);
return {
timestamp: stat.ctime.getTime(),
level: 'ALL',
message: await fs.readFile(fullPath, 'utf8')
};
});
}
extensions.prepareBuiltInApp = async function prepareBuiltInApp (appName, tmpDir, platformVersion) {
log.debug(`Looking for built in app '${appName}'`);
let newAppPath = path.resolve(tmpDir, `Appium-${appName}-${platformVersion}.app`);
let stat, appPath;
try {
[stat, appPath] = await this.getBuiltInApp(appName);
} catch (err) {
try {
stat = await fs.stat(newAppPath);
if (stat.isDirectory()) {
log.debug('Could not find original app, but found the temp ' +
'Appium one so using that: ${}');
return [newAppPath, appPath];
}
} catch (err) {
log.warn(`App is also not at '${newAppPath}'`);
throw new Error(`Could not find built in app '${appName}' in its home ` +
`or temp dir!`);
}
}
if (!stat.isDirectory()) {
throw new Error(`App found but it is not a directory: '${appPath}'`);
}
return await B.map(files, async (file) => {
let filename = path.resolve(this.logDir, file);
let stat = await fs.stat(filename);
return {
timestamp: stat.ctime.getTime(),
level: 'ALL',
message: await fs.readFile(filename, 'utf8')
};
});
}