UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

296 lines 14.4 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 asyncbox_1 = require("asyncbox"); const appium_ios_simulator_1 = require("appium-ios-simulator"); const simulator_1 = require("../helpers/simulator"); const node_simctl_1 = require("node-simctl"); const bluebird_1 = __importDefault(require("bluebird")); const session_1 = require("../helpers/session"); const desired_1 = require("../desired"); const setup_1 = require("../../setup"); const axios_1 = __importDefault(require("axios")); 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); const SIM_DEVICE_NAME = 'xcuitestDriverTest'; const simctl = new node_simctl_1.Simctl(); async function createDevice() { return await simctl.createDevice(SIM_DEVICE_NAME, desired_1.DEVICE_NAME, desired_1.PLATFORM_VERSION); } async function getNumSims() { return (await simctl.getDevices())[desired_1.PLATFORM_VERSION].length; } describe('XCUITestDriver', function () { this.timeout(session_1.MOCHA_TIMEOUT); let baseCaps; let caps; let driver; before(async function () { const udid = await createDevice(); const uiCatalogSimCaps = await (0, desired_1.getUICatalogSimCaps)(); baseCaps = (0, desired_1.amendCapabilities)(uiCatalogSimCaps, { 'appium:udid': udid }); caps = (0, desired_1.amendCapabilities)(baseCaps, { 'appium:usePrebuiltWDA': true, 'appium:wdaStartupRetries': 0, }); }); after(async function () { const sim = await (0, appium_ios_simulator_1.getSimulator)((0, desired_1.extractCapabilityValue)(caps, 'appium:udid'), { platform: 'iOS', checkExistence: false, }); await (0, simulator_1.cleanupSimulator)(sim); }); afterEach(async function () { // try to get rid of the driver, so if a test fails the rest of the // tests aren't compromised await (0, session_1.deleteSession)(); }); it('should start and stop a session', async function () { driver = await (0, session_1.initSession)(baseCaps); const els = await driver.$$('XCUIElementTypeWindow'); (0, chai_1.expect)(els.length).to.be.at.least(1); }); it('should start and stop a session doing pre-build', async function () { driver = await (0, session_1.initSession)((0, desired_1.amendCapabilities)(baseCaps, { 'appium:prebuildWDA': true })); const els = await driver.$$('XCUIElementTypeWindow'); (0, chai_1.expect)(els.length).to.be.at.least(1); }); it('should start and stop a session doing simple build-test', async function () { driver = await (0, session_1.initSession)((0, desired_1.amendCapabilities)(baseCaps, { 'appium:useSimpleBuildTest': true })); const els = await driver.$$('XCUIElementTypeWindow'); (0, chai_1.expect)(els.length).to.be.at.least(1); }); it('should start and stop a session with only bundle id', async function () { const localCaps = (0, desired_1.amendCapabilities)(caps, { 'appium:bundleId': setup_1.UICATALOG_BUNDLE_ID, 'appium:noReset': true, 'appium:app': undefined, }); await (0, chai_1.expect)((0, session_1.initSession)(localCaps)).to.not.be.rejected; }); it('should start and stop a session with only bundle id when no sim is running', async function () { await (0, simulator_1.killAllSimulators)(); const localCaps = (0, desired_1.amendCapabilities)(caps, { 'appium:bundleId': setup_1.UICATALOG_BUNDLE_ID, 'appium:noReset': true, 'appium:app': undefined, }); await (0, chai_1.expect)((0, session_1.initSession)(localCaps)).to.not.be.rejected; }); it('should fail to start and stop a session if unknown bundle id used', async function () { const localCaps = (0, desired_1.amendCapabilities)(caps, { 'appium:bundleId': 'io.blahblahblah.blah', 'appium:app': undefined, }); await (0, chai_1.expect)((0, session_1.initSession)(localCaps)).to.be.rejected; }); it('should fail to start and stop a session if unknown bundle id used when no sim is running', async function () { await (0, simulator_1.killAllSimulators)(); const localCaps = (0, desired_1.amendCapabilities)(caps, { 'appium:bundleId': 'io.blahblahblah.blah', 'appium:app': undefined, }); await (0, chai_1.expect)((0, session_1.initSession)(localCaps)).to.be.rejected; }); describe('WebdriverAgent port', function () { this.retries(3); it('should run on default port if no other specified', async function () { const localCaps = (0, desired_1.amendCapabilities)(baseCaps, { 'appium:fullReset': true, 'appium:useNewWDA': true, 'appium:wdaLocalPort': undefined, }); driver = await (0, session_1.initSession)(localCaps); await (0, chai_1.expect)((0, axios_1.default)({ url: `http://${session_1.HOST}:8100/status` })).to.not.be.rejected; }); it('should run on port specified', async function () { const localCaps = (0, desired_1.amendCapabilities)(baseCaps, { 'appium:fullReset': true, 'appium:useNewWDA': true, 'appium:wdaLocalPort': 6000, }); driver = await (0, session_1.initSession)(localCaps); await (0, chai_1.expect)((0, axios_1.default)({ url: `http://${session_1.HOST}:8100/status` })).to.be.rejectedWith(/ECONNREFUSED/); await (0, chai_1.expect)((0, axios_1.default)({ url: `http://${session_1.HOST}:8100/status` })).to.eventually.not.be.rejected; }); }); describe('initial orientation', function () { async function runOrientationTest(initialOrientation) { const localCaps = (0, desired_1.amendCapabilities)(caps, { 'appium:orientation': initialOrientation, }); driver = await (0, session_1.initSession)(localCaps); await (0, chai_1.expect)(driver.getOrientation()).to.eventually.eql(initialOrientation); } for (const orientation of ['LANDSCAPE', 'PORTRAIT']) { it(`should be able to start in a ${orientation} mode`, async function () { await runOrientationTest(orientation); }); } }); describe('reset', function () { beforeEach(async function () { await (0, session_1.deleteSession)(); await (0, asyncbox_1.retryInterval)(5, 1000, async () => { await (0, simulator_1.killAllSimulators)(); }); }); it('default: creates sim and deletes it afterwards', async function () { const uiCatalogSimCaps = await (0, desired_1.getUICatalogSimCaps)(); const caps = (0, desired_1.amendCapabilities)(uiCatalogSimCaps, { 'appium:enforceFreshSimulatorCreation': true, }); const simsBefore = await getNumSims(); await (0, session_1.initSession)(caps); const simsDuring = await getNumSims(); await (0, session_1.deleteSession)(); const simsAfter = await getNumSims(); (0, chai_1.expect)(simsDuring).to.equal(simsBefore + 1); (0, chai_1.expect)(simsAfter).to.equal(simsBefore); }); it('with udid: uses sim and resets afterwards if resetOnSessionStartOnly is false', async function () { // before const udid = await createDevice(); const sim = await (0, appium_ios_simulator_1.getSimulator)(udid, { platform: 'iOS', checkExistence: false, }); await sim.run(); try { // test const uiCatalogSimCaps = await (0, desired_1.getUICatalogSimCaps)(); const caps = (0, desired_1.amendCapabilities)(uiCatalogSimCaps, { 'appium:udid': udid, 'appium:fullReset': true, 'appium:resetOnSessionStartOnly': false, }); (0, chai_1.expect)(await sim.isRunning()).to.be.true; const simsBefore = await getNumSims(); await (0, session_1.initSession)(caps); const simsDuring = await getNumSims(); await (0, session_1.deleteSession)(); const simsAfter = await getNumSims(); (0, chai_1.expect)(await sim.isRunning()).to.be.false; // make sure no new simulators were created during the test (0, chai_1.expect)(simsDuring).to.equal(simsBefore); (0, chai_1.expect)(simsAfter).to.equal(simsBefore); } finally { // cleanup await (0, simulator_1.deleteDeviceWithRetry)(udid); } }); it('with udid booted: uses sim and leaves it afterwards', async function () { // before const udid = await createDevice(); const sim = await (0, appium_ios_simulator_1.getSimulator)(udid, { platform: 'iOS', checkExistence: false, }); await sim.run(); try { await bluebird_1.default.delay(2000); // test const uiCatalogSimCaps = await (0, desired_1.getUICatalogSimCaps)(); const caps = (0, desired_1.amendCapabilities)(uiCatalogSimCaps, { 'appium:udid': udid, 'appium:noReset': true, }); (0, chai_1.expect)(await sim.isRunning()).to.be.true; const simsBefore = await getNumSims(); await (0, session_1.initSession)(caps); const simsDuring = await getNumSims(); await (0, session_1.deleteSession)(); const simsAfter = await getNumSims(); (0, chai_1.expect)(await sim.isRunning()).to.be.true; (0, chai_1.expect)(simsDuring).to.equal(simsBefore); (0, chai_1.expect)(simsAfter).to.equal(simsBefore); } finally { await (0, simulator_1.cleanupSimulator)(sim); } }); it('with invalid udid: throws an error', async function () { // test const uiCatalogSimCaps = await (0, desired_1.getUICatalogSimCaps)(); const caps = (0, desired_1.amendCapabilities)(uiCatalogSimCaps, { 'appium:udid': 'some-random-udid', }); await (0, chai_1.expect)((0, session_1.initSession)(caps)).to.be.rejectedWith('Unknown device or simulator UDID'); }); it('with non-existent udid: throws an error', async function () { // test const udid = 'a77841db006fb1762fee0bb6a2477b2b3e1cfa7d'; const uiCatalogSimCaps = await (0, desired_1.getUICatalogSimCaps)(); const caps = (0, desired_1.amendCapabilities)(uiCatalogSimCaps, { 'appium:udid': udid }); await (0, chai_1.expect)((0, session_1.initSession)(caps)).to.be.rejectedWith('Unknown device or simulator UDID'); }); it('with noReset set to true: leaves sim booted', async function () { // before const udid = await createDevice(); const sim = await (0, appium_ios_simulator_1.getSimulator)(udid, { platform: 'iOS', checkExistence: false, }); try { // some systems require a pause before initializing. await bluebird_1.default.delay(2000); // test const uiCatalogSimCaps = await (0, desired_1.getUICatalogSimCaps)(); const caps = (0, desired_1.amendCapabilities)(uiCatalogSimCaps, { 'appium:udid': udid, 'appium:noReset': true, }); const simsBefore = await getNumSims(); await (0, session_1.initSession)(caps); const simsDuring = await getNumSims(); await (0, session_1.deleteSession)(); const simsAfter = await getNumSims(); (0, chai_1.expect)(await sim.isRunning()).to.be.true; (0, chai_1.expect)(simsDuring).to.equal(simsBefore); (0, chai_1.expect)(simsAfter).to.equal(simsBefore); } finally { await (0, simulator_1.cleanupSimulator)(sim); } }); }); }); //# sourceMappingURL=driver-e2e-specs.js.map