UNPKG

appium-webdriveragent

Version:
161 lines 10 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 chai_1 = __importStar(require("chai")); const chai_as_promised_1 = __importDefault(require("chai-as-promised")); const utils_1 = require("../../lib/utils"); const constants_1 = require("../../lib/constants"); const support_1 = require("@appium/support"); const path_1 = __importDefault(require("path")); const assert_1 = require("assert"); const os_1 = require("os"); const sinon_1 = __importDefault(require("sinon")); chai_1.default.use(chai_as_promised_1.default); function get_arch() { return (0, os_1.arch)() === 'arm64' ? 'arm64' : 'x86_64'; } describe('utils', function () { describe('#getXctestrunFilePath', function () { const platformVersion = '12.0'; const sdkVersion = '12.2'; const udid = 'xxxxxyyyyyyzzzzzz'; const bootstrapPath = 'path/to/data'; const platformName = constants_1.PLATFORM_NAME_IOS; let sandbox; beforeEach(function () { sandbox = sinon_1.default.createSandbox(); }); afterEach(function () { sandbox.restore(); }); it('should return sdk based path with udid', async function () { sandbox.stub(support_1.fs, 'exists') .withArgs(path_1.default.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)) .resolves(true); sandbox.stub(support_1.fs, 'copyFile'); const deviceInfo = { isRealDevice: true, udid, platformVersion, platformName }; await (0, chai_1.expect)((0, utils_1.getXctestrunFilePath)(deviceInfo, sdkVersion, bootstrapPath)) .to.eventually.equal(path_1.default.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)); sandbox.assert.notCalled(support_1.fs.copyFile); }); it('should return sdk based path without udid, copy them', async function () { const existsStub = sandbox.stub(support_1.fs, 'exists'); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)).resolves(false); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`)).resolves(true); sandbox.stub(support_1.fs, 'copyFile') .withArgs(path_1.default.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`), path_1.default.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)) .resolves(); const deviceInfo = { isRealDevice: true, udid, platformVersion, platformName: constants_1.PLATFORM_NAME_IOS }; await (0, chai_1.expect)((0, utils_1.getXctestrunFilePath)(deviceInfo, sdkVersion, bootstrapPath)) .to.eventually.equal(path_1.default.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)); }); it('should return platform based path', async function () { const existsStub = sandbox.stub(support_1.fs, 'exists'); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)).resolves(false); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-${get_arch()}.xctestrun`)).resolves(false); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)).resolves(true); sandbox.stub(support_1.fs, 'copyFile'); const deviceInfo = { isRealDevice: false, udid, platformVersion, platformName: constants_1.PLATFORM_NAME_IOS }; await (0, chai_1.expect)((0, utils_1.getXctestrunFilePath)(deviceInfo, sdkVersion, bootstrapPath)) .to.eventually.equal(path_1.default.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)); sandbox.assert.notCalled(support_1.fs.copyFile); }); it('should return platform based path without udid, copy them', async function () { const existsStub = sandbox.stub(support_1.fs, 'exists'); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)).resolves(false); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-${get_arch()}.xctestrun`)).resolves(false); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)).resolves(false); existsStub.withArgs(path_1.default.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-${get_arch()}.xctestrun`)).resolves(true); sandbox.stub(support_1.fs, 'copyFile') .withArgs(path_1.default.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-${get_arch()}.xctestrun`), path_1.default.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)) .resolves(); const deviceInfo = { isRealDevice: false, udid, platformVersion, platformName: constants_1.PLATFORM_NAME_IOS }; await (0, chai_1.expect)((0, utils_1.getXctestrunFilePath)(deviceInfo, sdkVersion, bootstrapPath)) .to.eventually.equal(path_1.default.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)); }); it('should raise an exception because of no files', async function () { const expected = path_1.default.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-${get_arch()}.xctestrun`); sandbox.stub(support_1.fs, 'exists').resolves(false); const deviceInfo = { isRealDevice: false, udid, platformVersion, platformName: constants_1.PLATFORM_NAME_IOS }; try { await (0, utils_1.getXctestrunFilePath)(deviceInfo, sdkVersion, bootstrapPath); (0, assert_1.fail)(); } catch (err) { (0, chai_1.expect)(err.message).to.equal(`If you are using 'useXctestrunFile' capability then you need to have a xctestrun file (expected: '${expected}')`); } }); }); describe('#getAdditionalRunContent', function () { it('should return ios format', function () { const wdaPort = (0, utils_1.getAdditionalRunContent)(constants_1.PLATFORM_NAME_IOS, 8000); (0, chai_1.expect)(wdaPort.WebDriverAgentRunner .EnvironmentVariables.USE_PORT).to.equal('8000'); }); it('should return tvos format', function () { const wdaPort = (0, utils_1.getAdditionalRunContent)(constants_1.PLATFORM_NAME_TVOS, '9000'); (0, chai_1.expect)(wdaPort.WebDriverAgentRunner_tvOS .EnvironmentVariables.USE_PORT).to.equal('9000'); }); }); describe('#getXctestrunFileName', function () { const platformVersion = '12.0'; const udid = 'xxxxxyyyyyyzzzzzz'; it('should return ios format, real device', function () { const platformName = 'iOs'; const deviceInfo = { isRealDevice: true, udid, platformVersion, platformName }; (0, chai_1.expect)((0, utils_1.getXctestrunFileName)(deviceInfo, '10.2.0')).to.equal('WebDriverAgentRunner_iphoneos10.2.0-arm64.xctestrun'); }); it('should return ios format, simulator', function () { const platformName = 'ios'; const deviceInfo = { isRealDevice: false, udid, platformVersion, platformName }; (0, chai_1.expect)((0, utils_1.getXctestrunFileName)(deviceInfo, '10.2.0')).to.equal(`WebDriverAgentRunner_iphonesimulator10.2.0-${get_arch()}.xctestrun`); }); it('should return tvos format, real device', function () { const platformName = 'tVos'; const deviceInfo = { isRealDevice: true, udid, platformVersion, platformName }; (0, chai_1.expect)((0, utils_1.getXctestrunFileName)(deviceInfo, '10.2.0')).to.equal('WebDriverAgentRunner_tvOS_appletvos10.2.0-arm64.xctestrun'); }); it('should return tvos format, simulator', function () { const platformName = 'tvOS'; const deviceInfo = { isRealDevice: false, udid, platformVersion, platformName }; (0, chai_1.expect)((0, utils_1.getXctestrunFileName)(deviceInfo, '10.2.0')).to.equal(`WebDriverAgentRunner_tvOS_appletvsimulator10.2.0-${get_arch()}.xctestrun`); }); }); }); //# sourceMappingURL=utils-specs.js.map