Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
});
});
before(async function () {
// travis can't write to /tmp, so let's create a tmp directory
try {
await fs.mkdir(TEMP_DIR);
} catch (e) {}
await fs.rimraf(altTmpDir);
});
before(async function () {
// travis can't write to /tmp, so let's create a tmp directory
try {
await fs.mkdir(TEMP_DIR);
} catch (e) {}
await fs.rimraf(altTraceDir);
});
it('should pull all the files in Library/AddressBook', async function () {
const remotePath = `Library/AddressBook`;
const data = await driver.pullFolder(remotePath);
const tmpRoot = await tempDir.openDir();
try {
const zipPath = path.resolve(tmpRoot, 'data.zip');
const extractedDataPath = path.resolve(tmpRoot, 'extracted_data');
await fs.writeFile(zipPath, Buffer.from(data, 'base64'));
await fs.mkdir(extractedDataPath);
await zip.extractAllTo(zipPath, extractedDataPath);
const itemsCount = (await fs.readdir(extractedDataPath)).length;
itemsCount.should.be.above(1);
} finally {
await fs.rimraf(tmpRoot);
}
});
});
beforeEach(async function () {
tempDirectory = `${assetsDir}/temp`;
await fs.rimraf(tempDirectory);
await fs.mkdir(tempDirectory);
});
before(async () => {
await fs.mkdir(tempTestPath);
});
after(async () => {
await service.walkDir(relativePath, true, async (itemPath, isDir) => {
const pathOnServer = path.join(tmpFolder, itemPath);
if (isDir) {
await fs.mkdir(pathOnServer);
} else {
const readStream = await service.createReadStream(itemPath, {autoDestroy: true });
const writeStream = fs.createWriteStream(pathOnServer, {autoClose: true});
promises.push(new B((resolve) => writeStream.on('close', resolve)));
readStream.pipe(writeStream);
}
});
try {
async function downloadUiAutomator2ServerApk () {
await fs.mkdir(UI2_DIR);
log.info(`downloading UiAutomator2 Server APK ${UI2_VER} : ${UI2_SERVER_DOWNLOAD}`);
log.info(`downloading UiAutomator2 Server test APK ${UI2_VER} : ${UI2_SERVER_TEST_DOWNLOAD}`);
let serverApk = await request.get({url: UI2_SERVER_DOWNLOAD, encoding: null});
let serverTestApk = await request.get({url: UI2_SERVER_TEST_DOWNLOAD, encoding: null});
if (!(serverApk instanceof Buffer)) {
throw new Error(Object.prototype.toString.call(serverApk));
}
if (!(serverTestApk instanceof Buffer)) {
throw new Error(Object.prototype.toString.call(serverTestApk));
}
let serverFingerprint = await sha512(serverApk);
let serverTestFingerprint = await sha512(serverTestApk);
if (serverFingerprint !== SERVER_DOWNLOAD_SHA512) {
log.errorAndThrow(`bad Server SHA512 fingerprint: ${serverFingerprint}`);
log.error("Stopping the installation");
commands.pushFile = async function (file, base64Data) {
const rootDir = path.resolve(__dirname, '..', '..', '..');
const fileDir = path.resolve(rootDir, 'app');
const localFile = path.resolve(fileDir, file);
if (file.indexOf('/') > -1) {
log.errorAndThrow(`It is expected that file point to a file and not to a folder. ` + `'${file}' is given instead`);
}
if (_.isArray(base64Data)) {
base64Data = Buffer.from(base64Data).toString('utf8');
}
const content = Buffer.from(base64Data, 'base64');
let isFileDir = await fs.exists(fileDir);
if (!isFileDir) {
await fs.mkdir(fileDir);
}
await fs.writeFile(localFile, content.toString('binary'), 'binary');
return true;
};