How to use plist.updatePlistFile method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

simulator-xcode-9.js

Source:simulator-xcode-9.js Github

copy

Full Screen

...223 newPrefs = _.merge(newPrefs, commonPrefs);224 return await preferencesPlistGuard.acquire(SimulatorXcode9.name, async () => {225 try {226 const currentPlistContent = await plist.parsePlistFile(plistPath);227 await plist.updatePlistFile(plistPath, _.merge(currentPlistContent, newPrefs), true);228 log.debug(`Updated ${this.udid} Simulator preferences at '${plistPath}' with ${JSON.stringify(newPrefs)}`);229 return true;230 } catch (e) {231 log.warn(`Cannot update ${this.udid} Simulator preferences at '${plistPath}'. ` +232 `Try to delete the file manually in order to reset it. Original error: ${e.message}`);233 return false;234 }235 });236 }237 /**238 * Shut down the current Simulator.239 * @override240 */241 async shutdown () {...

Full Screen

Full Screen

settings.js

Source:settings.js Github

copy

Full Screen

...76 if (_.isEqual(currentSettings, newSettings)) {77 // no setting changes, so do nothing78 return false;79 }80 await plist.updatePlistFile(pathToPlist, newSettings, true, false);81 return true;82}83async function readSettings (sim, plist) {84 let settings = {};85 for (let path of await plistPaths(sim, plist)) {86 settings[path] = await read(path);87 }88 return settings;89}90async function read (pathToPlist) {91 return await plist.parsePlistFile(pathToPlist, false);92}93async function updateLocationSettings (sim, bundleId, authorized) {94 // update location cache...

Full Screen

Full Screen

certificate.js

Source:certificate.js Github

copy

Full Screen

...177 const certBuffer = Buffer.from(content, 'base64');178 const commonName = extractCommonName(certBuffer);179 const mobileConfig = toMobileConfig(certBuffer, commonName);180 try {181 await plist.updatePlistFile(configPath, mobileConfig, false, false);182 } catch (err) {183 throw new Error(`Cannot store the generated config as '${configPath}'. ` +184 `Original error: ${err.message}`);185 }186 try {187 const {address, port} = this.server.address();188 const certUrl = `http://${address ? address : os.hostname()}` +189 `:${port ? port : 4723}/${configName}`;190 try {191 if (this.isRealDevice()) {192 try {193 await this.proxyCommand('/url', 'POST', {url: certUrl});194 } catch (err) {195 if (this.isWebContext()) {...

Full Screen

Full Screen

plist.js

Source:plist.js Github

copy

Full Screen

1import xmlplist from 'plist';2import bplistCreate from 'bplist-creator';3import bplistParse from 'bplist-parser';4import fs from './fs';5import log from './logger';6import _ from 'lodash';7const BPLIST_IDENTIFIER = {8 BUFFER: Buffer.from('bplist00'),9 TEXT: 'bplist00'10};11const PLIST_IDENTIFIER = {12 BUFFER: Buffer.from('<'),13 TEXT: '<'14};15// XML Plist library helper16async function parseXmlPlistFile (plistFilename) {17 let xmlContent = await fs.readFile(plistFilename, 'utf8');18 return xmlplist.parse(xmlContent);19}20/**21 * Parses a file in xml or binary format of plist22 * @param {string} plist The plist file path23 * @param {boolean} mustExist If set to false, this method will return an empty object when the file doesn't exist24 * @param {boolean} quiet If set to false, the plist path will be logged in debug level25 * @returns {Object} parsed plist JS Object26 */27async function parsePlistFile (plist, mustExist = true, quiet = true) {28 // handle nonexistant file29 if (!await fs.exists(plist)) {30 if (mustExist) {31 log.errorAndThrow(`Plist file doesn't exist: '${plist}'`);32 } else {33 log.debug(`Plist file '${plist}' does not exist. Returning an empty plist.`);34 return {};35 }36 }37 let obj = {};38 let type = 'binary';39 try {40 obj = await bplistParse.parseFile(plist);41 if (obj.length) {42 obj = obj[0];43 } else {44 throw new Error(`Binary file '${plist}'' appears to be empty`);45 }46 } catch (ign) {47 try {48 obj = await parseXmlPlistFile(plist);49 type = 'xml';50 } catch (err) {51 log.errorAndThrow(`Could not parse plist file '${plist}' as XML: ${err.message}`);52 }53 }54 if (!quiet) {55 log.debug(`Parsed plist file '${plist}' as ${type}`);56 }57 return obj;58}59/**60 * Updates a plist file with the given fields61 * @param {string} plist The plist file path62 * @param {Object} updatedFields The updated fields-value pairs63 * @param {boolean} binary If set to false, the file will be created as a xml plist64 * @param {boolean} mustExist If set to false, this method will update an empty plist65 * @param {boolean} quiet If set to false, the plist path will be logged in debug level66 */67async function updatePlistFile (plist, updatedFields, binary = true, mustExist = true, quiet = true) {68 let obj;69 try {70 obj = await parsePlistFile(plist, mustExist);71 } catch (err) {72 log.errorAndThrow(`Could not update plist: ${err.message}`);73 }74 _.extend(obj, updatedFields);75 let newPlist = binary ? bplistCreate(obj) : xmlplist.build(obj);76 try {77 await fs.writeFile(plist, newPlist);78 } catch (err) {79 log.errorAndThrow(`Could not save plist: ${err.message}`);80 }81 if (!quiet) {82 log.debug(`Wrote plist file '${plist}'`);83 }84}85/**86 * Creates a binary plist Buffer from an object87 * @param {Object} data The object to be turned into a binary plist88 * @returns {Buffer} plist in the form of a binary buffer89 */90function createBinaryPlist (data) {91 return bplistCreate(data);92}93/**94 * Parses a Buffer into an Object95 * @param {Buffer} data The beffer of a binary plist96 */97function parseBinaryPlist (data) {98 return bplistParse.parseBuffer(data);99}100function getXmlPlist (data) {101 if (_.isString(data) && data.startsWith(PLIST_IDENTIFIER.TEXT)) {102 return data;103 }104 if (_.isBuffer(data) && PLIST_IDENTIFIER.BUFFER.compare(data, 0, PLIST_IDENTIFIER.BUFFER.length) === 0) {105 return data.toString();106 }107 return null;108}109function getBinaryPlist (data) {110 if (_.isString(data) && data.startsWith(BPLIST_IDENTIFIER.TEXT)) {111 return Buffer.from(data);112 }113 if (_.isBuffer(data) && BPLIST_IDENTIFIER.BUFFER.compare(data, 0, BPLIST_IDENTIFIER.BUFFER.length) === 0) {114 return data;115 }116 return null;117}118/**119 * Creates a plist from an object120 * @param {Object} object The JS object to be turned into a plist121 * @param {boolean} binary Set it to true for a binary plist122 * @returns {string|Buffer} returns a buffer or a string in respect to the binary parameter123 */124function createPlist (object, binary = false) {125 if (binary) {126 return createBinaryPlist(object);127 } else {128 return xmlplist.build(object);129 }130}131/**132 * Parses an buffer or a string to a JS object a plist from an object133 * @param {string|Buffer} data The plist in the form of string or Buffer134 * @returns {Object} parsed plist JS Object135 * @throws Will throw an error if the plist type is unknown136 */137function parsePlist (data) {138 let textPlist = getXmlPlist(data);139 if (textPlist) {140 return xmlplist.parse(textPlist);141 }142 let binaryPlist = getBinaryPlist(data);143 if (binaryPlist) {144 return parseBinaryPlist(binaryPlist)[0];145 }146 throw new Error(`Unknown type of plist, data: ${data.toString()}`);147}...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...106 if (_.isNull(app) || _.isUndefined(app)) { return; }107 let plistFile = path.resolve(app, "Info.plist");108 let isiPhone = deviceString.toLowerCase().indexOf("ipad") === -1;109 let deviceTypeCode = isiPhone ? 1 : 2;110 await plist.updatePlistFile(plistFile, {UIDeviceFamily: [deviceTypeCode]});111}112function unwrapEl (el) {113 if(typeof el === 'object' && el.ELEMENT){114 return el.ELEMENT;115 }116 return el;117}118export default { rootDir, removeInstrumentsSocket,119 appIsPackageOrBundle, detectUdid, parseLocalizableStrings,120 shouldPrelaunchSimulator, setDeviceTypeInInfoPlist, getSimForDeviceString,...

Full Screen

Full Screen

plist-specs.js

Source:plist-specs.js Github

copy

Full Screen

...21 // write some data22 let updatedFields = {23 'io.appium.test': true24 };25 await plist.updatePlistFile(plistFile, updatedFields, true);26 // make sure the data is there27 let content = await plist.parsePlistFile(plistFile);28 content.should.have.property('io.appium.test');29 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var plist = require('appium-xcuitest-driver').plist;2var plistPath = 'path/to/plist/file';3plist.updatePlistFile(plistPath, 'CFBundleIdentifier', 'com.my.new.bundle.id');4var plist = require('appium-xcuitest-driver').plist;5var plistPath = 'path/to/plist/file';6plist.updatePlistFile(plistPath, 'CFBundleIdentifier', 'com.my.new.bundle.id');7var plist = require('appium-xcuitest-driver').plist;8var plistPath = 'path/to/plist/file';9plist.updatePlistFile(plistPath, 'CFBundleIdentifier', 'com.my.new.bundle.id');10var plist = require('appium-xcuitest-driver').plist;11var plistPath = 'path/to/plist/file';12plist.updatePlistFile(plistPath, 'CFBundleIdentifier', 'com.my.new.bundle.id');13var plist = require('appium-xcuitest-driver').plist;14var plistPath = 'path/to/plist/file';15plist.updatePlistFile(plistPath, 'CFBundleIdentifier', 'com.my.new.bundle.id');16var plist = require('appium-xcuitest-driver').plist;17var plistPath = 'path/to/plist/file';18plist.updatePlistFile(plistPath, 'CFBundleIdentifier', 'com.my.new.bundle.id');19var plist = require('appium-xcuitest-driver').plist;20var plistPath = 'path/to/plist/file';21plist.updatePlistFile(plistPath, 'CFBundleIdentifier', 'com.my.new.bundle.id');

Full Screen

Using AI Code Generation

copy

Full Screen

1const plist = require('appium-ios-device/lib/util/plist');2const path = require('path');3const plistFile = path.resolve('/Users/username/Downloads/MyApp.app/Info.plist');4const plistData = plist.parsePlistFile(plistFile);5console.log(plistData);6plist.updatePlistFile(plistFile, 'CFBundleIdentifier', 'com.test.myapp');7console.log(plistData);8Your name to display (optional):9Your name to display (optional):10const plist = require('appium-ios-device/lib/util/plist');11const path = require('path');12const plistFile = path.resolve('/Users/username/Downloads/MyApp.app/Info.plist');13const plistData = plist.parsePlistFile(plistFile);14console.log(plistData);15plist.updatePlistFile(plistFile, 'CFBundleIdentifier', 'com.test.myapp');16console.log(plistData);17Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var plist = require('plist');2var fs = require('fs');3var path = require('path');4var plistFile = path.resolve('./',5'com.example.appium-ios-test-automation-calculator.plist');6var plistFileContent = plist.parse(fs.readFileSync(plistFile, 'utf8'));7plistFileContent.CFBundleIdentifier = 'com.example.appium-ios-test-automation-calculator';8fs.writeFileSync(plistFile, plist.build(plistFileContent));

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