UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

151 lines 8.08 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const sinon_1 = require("sinon"); const real_device_management_1 = require("../../lib/device/real-device-management"); const driver_1 = require("../../lib/driver"); const chai_1 = __importStar(require("chai")); const chai_as_promised_1 = __importDefault(require("chai-as-promised")); chai_1.default.use(chai_as_promised_1.default); describe('installToRealDevice', function () { const udid = 'test-udid'; const app = '/path/to.app'; const bundleId = 'test.bundle.id'; let sandbox; let driver; beforeEach(function () { sandbox = (0, sinon_1.createSandbox)(); driver = new driver_1.XCUITestDriver({}); }); afterEach(function () { sandbox.restore(); }); it('nothing happen without app', async function () { const realDevice = new real_device_management_1.RealDevice(udid); const removeStub = sandbox.stub(realDevice, 'remove').resolves(); const installStub = sandbox.stub(realDevice, 'install').resolves(); driver.opts = { udid }; driver._device = realDevice; await real_device_management_1.installToRealDevice.bind(driver)(undefined, bundleId, {}); (0, chai_1.expect)(removeStub.called).to.be.false; (0, chai_1.expect)(installStub.called).to.be.false; }); it('nothing happen without bundle id', async function () { const realDevice = new real_device_management_1.RealDevice(udid); const removeStub = sandbox.stub(realDevice, 'remove').resolves(); const installStub = sandbox.stub(realDevice, 'install').resolves(); driver._device = realDevice; driver.opts = { udid }; await real_device_management_1.installToRealDevice.bind(driver)(app, undefined, {}); (0, chai_1.expect)(removeStub.called).to.be.false; (0, chai_1.expect)(installStub.called).to.be.false; }); it('should install without remove', async function () { const opts = { skipUninstall: true }; const realDevice = new real_device_management_1.RealDevice(udid); const removeStub = sandbox.stub(realDevice, 'remove').resolves(); const installStub = sandbox.stub(realDevice, 'install').resolves(); driver._device = realDevice; driver.opts = { udid }; await real_device_management_1.installToRealDevice.bind(driver)(app, bundleId, opts); (0, chai_1.expect)(removeStub.called).to.be.false; (0, chai_1.expect)(installStub.calledOnce).to.be.true; }); it('should install after remove', async function () { const opts = { skipUninstall: false }; const realDevice = new real_device_management_1.RealDevice(udid); const removeStub = sandbox.stub(realDevice, 'remove').resolves(); const installStub = sandbox.stub(realDevice, 'install').resolves(); driver._device = realDevice; driver.opts = { udid }; await real_device_management_1.installToRealDevice.bind(driver)(app, bundleId, opts); (0, chai_1.expect)(removeStub.calledOnce).to.be.true; (0, chai_1.expect)(installStub.calledOnce).to.be.true; }); it('should raise an error for invalid verification error after uninstall', async function () { const opts = { skipUninstall: false }; const err_msg = `{"Error":"ApplicationVerificationFailed","ErrorDetail":-402620395,"ErrorDescription":"Failed to verify code signature of /path/to.app : 0xe8008015 (A valid provisioning profile for this executable was not found.)"}`; const realDevice = new real_device_management_1.RealDevice(udid); const removeStub = sandbox.stub(realDevice, 'remove').resolves(); const installStub = sandbox.stub(realDevice, 'install').throws(err_msg); driver._device = realDevice; driver.opts = { udid }; await (0, chai_1.expect)(real_device_management_1.installToRealDevice.bind(driver)(app, bundleId, opts)).to.be.rejectedWith('ApplicationVerificationFailed'); (0, chai_1.expect)(removeStub.calledOnce).to.be.true; (0, chai_1.expect)(installStub.calledOnce).to.be.true; }); it('should install after removal once because of MismatchedApplicationIdentifierEntitlement error', async function () { // This situation could happen when the app exists as offload, or cached state // with different application identifier const opts = { skipUninstall: true }; const realDevice = new real_device_management_1.RealDevice(udid); const removeStub = sandbox.stub(realDevice, 'remove').resolves(); const installStub = sandbox.stub(realDevice, 'install') .onCall(0).throws(`{"Error":"MismatchedApplicationIdentifierEntitlement","ErrorDescription":"Upgrade's application-identifier entitlement string (TEAM_ID.com.kazucocoa.example) does not match installed application's application-identifier string (ANOTHER_TEAM_ID.com.kazucocoa.example); rejecting upgrade."}`) .onCall(1).resolves(); driver._device = realDevice; driver.opts = { udid }; await real_device_management_1.installToRealDevice.bind(driver)(app, bundleId, opts); (0, chai_1.expect)(removeStub.calledOnce).to.be.true; (0, chai_1.expect)(installStub.calledTwice).to.be.true; }); it('should raise an error in the install ApplicationVerificationFailed error because it is not recoverable', async function () { const opts = { skipUninstall: true }; const err_msg = `{"Error":"ApplicationVerificationFailed","ErrorDetail":-402620395,"ErrorDescription":"Failed to verify code signature of /path/to.app : 0xe8008015 (A valid provisioning profile for this executable was not found.)"}`; const realDevice = new real_device_management_1.RealDevice(udid); const removeStub = sandbox.stub(realDevice, 'remove').resolves(); const installStub = sandbox.stub(realDevice, 'install').throws(err_msg); sandbox.stub(realDevice, 'isAppInstalled').resolves(true); driver._device = realDevice; driver.opts = { udid }; await (0, chai_1.expect)(real_device_management_1.installToRealDevice.bind(driver)(app, bundleId, opts)).to.be.rejectedWith('ApplicationVerificationFailed'); (0, chai_1.expect)(removeStub.called).to.be.false; (0, chai_1.expect)(installStub.calledOnce).to.be.true; }); }); //# sourceMappingURL=real-device-management-specs.js.map