How to use device.simctl.addRootCertificate method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver.js

Source:driver.js Github

copy

Full Screen

...346 if (this.opts.customSSLCert) {347 const certHead = _.truncate(this.opts.customSSLCert, {length: 20});348 log.info(`Installing the custom SSL certificate '${certHead}'`);349 try {350 await this.opts.device.simctl.addRootCertificate(this.opts.customSSLCert, {raw: true});351 } catch (ign) {352 if (await hasSSLCert(this.opts.customSSLCert, this.opts.udid)) {353 log.info(`SSL certificate '${certHead}' already installed`);354 } else {355 log.info(`Making sure Simulator is shut down, ' +356 'so that SSL certificate installation takes effect`);357 await shutdownSimulator(this.opts.device);358 await installSSLCert(this.opts.customSSLCert, this.opts.udid);359 }360 }361 this.logEvent('customCertInstalled');362 }363 await this.startSim();364 if (this.opts.launchWithIDB && this.isSimulator()) {...

Full Screen

Full Screen

cert-utils.js

Source:cert-utils.js Github

copy

Full Screen

...23 * @param {object} device Simulator instance created by appium-ios-simulator module24 * @param {string} payload Certificate payload25 */26async function installCertificate (device, payload) {27 await device.simctl.addRootCertificate(payload, {raw: true});28}29/**30 * Check whether the given certificate is already installed.31 * The function is using hacky calls to make certificate stuff working for older SDKs.32 * Simulator must be in SHUTDOWN state for this API to work.33 *34 * @param {object} device Simulator instance created by appium-ios-simulator module35 * @param {string} payload Certificate payload36 * @returns {boolean} `true` if the certificate is already present in the root store.37 */38async function hasCertificateLegacy (device, payload) {39 return await hasSSLCert(payload, device.udid);40}41/**...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const path = require('path');3const util = require('util');4const readFile = util.promisify(fs.readFile);5const { exec } = require('child_process');6const certPath = path.join(__dirname, 'cert.pem');7readFile(certPath, 'utf8')8 .then((cert) => {9 return new Promise((resolve, reject) => {10 exec(`xcrun simctl addRootCertificate "${cert}" booted`, (err, stdout, stderr) => {11 if (err) {12 reject(err);13 } else {14 resolve(stdout);15 }16 });17 });18 })19 .then((stdout) => {20 console.log(stdout);21 })22 .catch((err) => {23 console.log(err);24 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const path = require('path');3const fs = require('fs');4const { execSync } = require('child_process');5async function main() {6 driver.on('status', console.log);7 driver.on('command', console.log);8 driver.on('http', console.log);9 const caps = {10 };11 await driver.init(caps);12 const rootCertPath = path.resolve(__dirname, 'root.crt');13 const rootCert = fs.readFileSync(rootCertPath, 'base64');14 const simId = await driver.execute('mobile:deviceInfo', { 'propertyName': 'udid' });15 const addCertCmd = `xcrun simctl addRootCertificate ${simId} ${rootCertPath}`;16 execSync(addCertCmd);17}18main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { execSync } = require('child_process');2const path = require('path');3const fs = require('fs');4const { promisify } = require('util');5const { exec } = require('teen_process');6const { system } = require('appium-support');7const readFileAsync = promisify(fs.readFile);8const writeFileAsync = promisify(fs.writeFile);9async function addRootCertificate (certPath, udid) {10 if (!system.isMac()) {11 throw new Error('Only Mac OS X systems are supported');12 }13 const {stdout} = await exec('security', ['find-certificate', '-a', '-c', 'ios-app-signer', '-Z', udid, '-p']);14 if (stdout.includes('SHA-1 hash')) {15 return;16 }17 const certContent = await readFileAsync(certPath, 'utf8');18 const {stdout: fingerprint} = await exec('openssl', ['x509', '-noout', '-fingerprint', '-sha1', '-inform', 'pem', '-in', certPath]);19 const fingerprintHash = fingerprint.match(/SHA1 Fingerprint=(.*)/)[1].replace(/:/g, '').toLowerCase();20 const {stdout: subject} = await exec('openssl', ['x509', '-noout', '-subject', '-inform', 'pem', '-in', certPath]);21 const keychainPath = path.resolve(__dirname, '..', 'Library', 'Keychains', `${udid}.keychain`);22 const {stdout: keychainPassword} = await exec('security', ['create-keychain', '-p', '', keychainPath]);23 await exec('security', ['unlock-keychain', '-p', keychainPassword, keychainPath]);24 await exec('security', ['import', certPath, '-k', keychainPath, '-T', '/usr/bin/codesign', '-T', '/usr/bin/security']);

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var rootCertificate = fs.readFileSync(path.resolve(__dirname, 'rootCertificate.pem'));4var rootCertificatePassword = 'password';5var driver = new wd.Builder()6 .withCapabilities({7 })8 .build();9driver.init()10 .then(function () {11 return driver.execute('mobile: device.simctl.addRootCertificate', {12 });13 })14 .then(function () {15 })16 .then(function () {17 return driver.sleep(5000);18 })19 .then(function () {20 return driver.quit();21 })22 .catch(function (err) {23 console.error('Error: ' + err);24 });

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', function () {2 it('should install a root certificate', async function () {3 await driver.device.simctl.addRootCertificate('path/to/cert.pem');4 });5});6describe('test', function () {7 it('should remove a root certificate', async function () {8 await driver.device.simctl.removeRootCertificate('path/to/cert.pem');9 });10});11describe('test', function () {12 it('should install a trusted certificate', async function () {13 await driver.device.simctl.addTrustedCertificate('path/to/cert.pem');14 });15});16describe('test', function () {17 it('should remove a trusted certificate', async function () {18 await driver.device.simctl.removeTrustedCertificate('path/to/cert.pem');19 });20});21describe('test', function () {22 it('should add an app to the login items list', async function () {23 await driver.device.simctl.addLoginItem('path/to/app.app');24 });25});26describe('test', function () {27 it('should remove an app from the login items list', async function () {28 await driver.device.simctl.removeLoginItem('path/to/app.app');29 });30});

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