How to use verifyIsSubPath method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

file-movement.js

Source:file-movement.js Github

copy

Full Screen

...69 const containerRoot = _.isFunction(containerRootSupplier)70 ? await containerRootSupplier(bundleId, containerType)71 : containerRootSupplier;72 const resultPath = path.posix.resolve(containerRoot, relativePath);73 verifyIsSubPath(resultPath, containerRoot);74 return [bundleId, resultPath];75}76/**77 * Save the given base64 data chunk as a binary file on the Simulator under test.78 *79 * @param {Object} device - The device object, which represents the device under test.80 * This object is expected to have the `udid` property containing the81 * valid device ID.82 * @param {string} remotePath - The remote path on the device. This variable can be prefixed with83 * bundle id, so then the file will be uploaded to the corresponding84 * application container instead of the default media folder, for example85 * '@com.myapp.bla:data/RelativePathInContainer/111.png'. The '@' character at the86 * beginning of the argument is mandatory in such case. The colon at the end of bundle identifier87 * is optional and is used to distinguish the container type.88 * Possible values there are 'app', 'data', 'groups', '<A specific App Group container>'.89 * The default value is 'app'.90 * The relative folder path is ignored if the file is going to be uploaded91 * to the default media folder and only the file name is considered important.92 * @param {string} base64Data - Base-64 encoded content of the file to be uploaded.93 */94async function pushFileToSimulator (device, remotePath, base64Data) {95 const buffer = Buffer.from(base64Data, 'base64');96 if (CONTAINER_PATH_PATTERN.test(remotePath)) {97 const [bundleId, dstPath] = await parseContainerPath(remotePath,98 async (appBundle, containerType) => await getAppContainer(device.udid, appBundle, null, containerType));99 log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +100 `Will put the data into '${dstPath}'`);101 if (!await fs.exists(path.dirname(dstPath))) {102 log.debug(`The destination folder '${path.dirname(dstPath)}' does not exist. Creating...`);103 await mkdirp(path.dirname(dstPath));104 }105 await fs.writeFile(dstPath, buffer);106 return;107 }108 const dstFolder = await tempDir.openDir();109 const dstPath = path.resolve(dstFolder, path.basename(remotePath));110 try {111 await fs.writeFile(dstPath, buffer);112 await addMedia(device.udid, dstPath);113 } finally {114 await fs.rimraf(dstFolder);115 }116}117/**118 * Save the given base64 data chunk as a binary file on the device under test.119 * ifuse/osxfuse should be installed and configured on the target machine in order120 * for this function to work properly. Read https://github.com/libimobiledevice/ifuse121 * and https://github.com/osxfuse/osxfuse/wiki/FAQ for more details.122 *123 * @param {Object} device - The device object, which represents the device under test.124 * This object is expected to have the `udid` property containing the125 * valid device ID.126 * @param {string} remotePath - The remote path on the device. This variable can be prefixed with127 * bundle id, so then the file will be uploaded to the corresponding128 * application container instead of the default media folder, for example129 * '@com.myapp.bla/RelativePathInContainer/111.png'. The '@' character at the130 * beginning of the argument is mandatory in such case.131 * @param {string} base64Data - Base-64 encoded content of the file to be uploaded.132 */133async function pushFileToRealDevice (device, remotePath, base64Data) {134 await verifyIFusePresence();135 const mntRoot = await tempDir.openDir();136 let isUnmountSuccessful = true;137 try {138 let dstPath = path.resolve(mntRoot, remotePath);139 let ifuseArgs = ['-u', device.udid, mntRoot];140 if (CONTAINER_PATH_PATTERN.test(remotePath)) {141 const [bundleId, pathInContainer] = await parseContainerPath(remotePath, mntRoot);142 dstPath = pathInContainer;143 log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +144 `Will put the data into '${dstPath}'`);145 ifuseArgs = ['-u', device.udid, '--container', bundleId, mntRoot];146 } else {147 verifyIsSubPath(dstPath, mntRoot);148 }149 await mountDevice(device, ifuseArgs);150 isUnmountSuccessful = false;151 try {152 if (!await fs.exists(path.dirname(dstPath))) {153 log.debug(`The destination folder '${path.dirname(dstPath)}' does not exist. Creating...`);154 await mkdirp(path.dirname(dstPath));155 }156 await fs.writeFile(dstPath, Buffer.from(base64Data, 'base64'));157 } finally {158 await exec('umount', [mntRoot]);159 isUnmountSuccessful = true;160 }161 } finally {162 if (isUnmountSuccessful) {163 await fs.rimraf(mntRoot);164 } else {165 log.warn(`Umount has failed, so not removing '${mntRoot}'`);166 }167 }168}169/**170 * Get the content of given file or folder from iOS Simulator and return it as base-64 encoded string.171 * Folder content is recursively packed into a zip archive.172 *173 * @param {Object} device - The device object, which represents the device under test.174 * This object is expected to have the `udid` property containing the175 * valid device ID.176 * @param {string} remotePath - The path to a file or a folder, which exists in the corresponding application177 * container on Simulator. Use178 * @<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container>179 * format to pull a file or a folder from an application container of the given type.180 * Possible container types are 'app', 'data', 'groups', '<A specific App Group container>'.181 * The default type is 'app'.182 * @param {boolean} isFile - Whether the destination item is a file or a folder183 * @returns {string} Base-64 encoded content of the file.184 */185async function pullFromSimulator (device, remotePath, isFile) {186 let pathOnServer;187 if (CONTAINER_PATH_PATTERN.test(remotePath)) {188 const [bundleId, dstPath] = await parseContainerPath(remotePath,189 async (appBundle, containerType) => await getAppContainer(device.udid, appBundle, null, containerType));190 log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +191 `Will get the data from '${dstPath}'`);192 pathOnServer = dstPath;193 } else {194 const simRoot = device.getDir();195 pathOnServer = path.posix.join(simRoot, remotePath);196 verifyIsSubPath(pathOnServer, simRoot);197 log.info(`Got the full item path: ${pathOnServer}`);198 }199 if (!await fs.exists(pathOnServer)) {200 log.errorAndThrow(`The remote ${isFile ? 'file' : 'folder'} at '${pathOnServer}' does not exist`);201 }202 const buffer = isFile203 ? await fs.readFile(pathOnServer)204 : await zip.toInMemoryZip(pathOnServer);205 return Buffer.from(buffer).toString('base64');206}207/**208 * Get the content of given file or folder from the real device under test and return it as base-64 encoded string.209 * Folder content is recursively packed into a zip archive.210 *211 * @param {Object} device - The device object, which represents the device under test.212 * This object is expected to have the `udid` property containing the213 * valid device ID.214 * @param {string} remotePath - The path to an existing remote file on the device. This variable can be prefixed with215 * bundle id, so then the file will be downloaded from the corresponding216 * application container instead of the default media folder, for example217 * '@com.myapp.bla/RelativePathInContainer/111.png'. The '@' character at the218 * beginning of the argument is mandatory in such case.219 * @param {boolean} isFile - Whether the destination item is a file or a folder220 * @return {string} Base-64 encoded content of the remote file221 */222async function pullFromRealDevice (device, remotePath, isFile) {223 await verifyIFusePresence();224 const mntRoot = await tempDir.openDir();225 let isUnmountSuccessful = true;226 try {227 let dstPath = path.resolve(mntRoot, remotePath);228 let ifuseArgs = ['-u', device.udid, mntRoot];229 if (CONTAINER_PATH_PATTERN.test(remotePath)) {230 const [bundleId, pathInContainer] = await parseContainerPath(remotePath, mntRoot);231 dstPath = pathInContainer;232 log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +233 `Will get the data from '${dstPath}'`);234 ifuseArgs = ['-u', device.udid, '--container', bundleId, mntRoot];235 } else {236 verifyIsSubPath(dstPath, mntRoot);237 }238 await mountDevice(device, ifuseArgs);239 isUnmountSuccessful = false;240 try {241 if (!await fs.exists(dstPath)) {242 log.errorAndThrow(`The remote ${isFile ? 'file' : 'folder'} at '${dstPath}' does not exist`);243 }244 const buffer = isFile245 ? await fs.readFile(dstPath)246 : await zip.toInMemoryZip(dstPath);247 return Buffer.from(buffer).toString('base64');248 } finally {249 await exec('umount', [mntRoot]);250 isUnmountSuccessful = true;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .end();9client.catch(function (err) {10 console.log(err);11});12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .end();20client.catch(function (err) {21 console.log(err);22});

Full Screen

Using AI Code Generation

copy

Full Screen

1const XCUITestDriver = require('appium-xcuitest-driver');2const path = require('path');3const driver = new XCUITestDriver();4const filePath = '/Users/username/Documents/abc.txt';5const dirPath = '/Users/username/Documents';6const isSubPath = driver.verifyIsSubPath(filePath, dirPath);7console.log('Is SubPath: ', isSubPath);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { verifyIsSubPath } = require('appium-xcuitest-driver/lib/ios-helpers');2describe('verifyIsSubPath', () => {3 it('should return true if the path is a subpath of the base path', () => {4 verifyIsSubPath('/Users/tester/Library/Developer/Xcode/DerivedData/test-abc123/Build/Products/Debug-iphonesimulator/test.app', '/Users/tester/Library/Developer/Xcode/DerivedData/test-abc123/Build/Products/Debug-iphonesimulator/test.app/').should.be.true;5 });6 it('should return false if the path is not a subpath of the base path', () => {7 verifyIsSubPath('/Users/tester/Library/Developer/Xcode/DerivedData/test-abc123/Build/Products/Debug-iphonesimulator/test.app', '/Users/tester/Library/Developer/Xcode/DerivedData/test-abc123/Build/Products/Debug-iphonesimulator/test.app1/').should.be.false;8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const assert = require('assert');3const options = {4 capabilities: {5 }6};7(async function () {8 const client = await wdio.remote(options);

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