UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

141 lines 7.53 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 desired_1 = require("../desired"); const session_1 = require("../helpers/session"); const support_1 = require("appium/support"); const path_1 = __importDefault(require("path")); const setup_1 = require("../../setup"); 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 UICAT_CONTAINER = `@${setup_1.UICATALOG_BUNDLE_ID}`; async function pullFileAsString(driver, remotePath) { const remoteData64 = await driver.pullFile(remotePath); return Buffer.from(remoteData64, 'base64').toString(); } describe('XCUITestDriver - file movement', function () { this.timeout(session_1.MOCHA_TIMEOUT); let driver; before(async function () { const uiCatalogCaps = await (0, desired_1.getUICatalogCaps)(); driver = await (0, session_1.initSession)(uiCatalogCaps); }); after(async function () { await (0, session_1.deleteSession)(); }); describe('sim relative', function () { describe('files', function () { it('should not be able to fetch a file from the file system at large', async function () { await (0, chai_1.expect)(driver.pullFile(__filename)).to.be.rejected; }); it('should be able to fetch the Address book', async function () { const stringData = await pullFileAsString(driver, `${UICAT_CONTAINER}/PkgInfo`); (0, chai_1.expect)(stringData.indexOf('APPL')).to.not.equal(-1); }); it('should not be able to fetch something that does not exist', async function () { await (0, chai_1.expect)(driver .pullFile('Library/AddressBook/nothere.txt')).to.be.rejectedWith(/does not exist/); }); it('should be able to push and pull a file', async function () { const stringData = `random string data ${Math.random()}`; const base64Data = Buffer.from(stringData).toString('base64'); const remotePath = `${UICAT_CONTAINER}/remote.txt`; await driver.pushFile(remotePath, base64Data); const remoteStringData = await pullFileAsString(driver, remotePath); (0, chai_1.expect)(remoteStringData).to.equal(stringData); }); it('should be able to delete a file', async function () { const stringData = `random string data ${Math.random()}`; const base64Data = Buffer.from(stringData).toString('base64'); const remotePath = `${UICAT_CONTAINER}/remote.txt`; await driver.pushFile(remotePath, base64Data); const remoteStringData = await pullFileAsString(driver, remotePath); (0, chai_1.expect)(remoteStringData).to.equal(stringData); await driver.execute('mobile: deleteFile', { remotePath }); await (0, chai_1.expect)(pullFileAsString(driver, remotePath)).to.be.rejectedWith(/does not exist/); }); }); describe('folders', function () { it('should not pull folders from file system', async function () { await (0, chai_1.expect)(driver.pullFolder(__dirname)).to.be.rejected; }); it('should not be able to fetch a folder that does not exist', async function () { await (0, chai_1.expect)(driver.pullFolder('Library/Rollodex')).to.be.rejectedWith(/does not exist/); }); it('should pull all the files in Library/AddressBook', async function () { const remotePath = `Library/AddressBook`; const data = await driver.pullFolder(remotePath); const tmpRoot = await support_1.tempDir.openDir(); try { const zipPath = path_1.default.resolve(tmpRoot, 'data.zip'); const extractedDataPath = path_1.default.resolve(tmpRoot, 'extracted_data'); await support_1.fs.writeFile(zipPath, Buffer.from(data, 'base64')); await support_1.fs.mkdir(extractedDataPath); await support_1.zip.extractAllTo(zipPath, extractedDataPath); const itemsCount = (await support_1.fs.readdir(extractedDataPath)).length; (0, chai_1.expect)(itemsCount).to.be.above(1); } finally { await support_1.fs.rimraf(tmpRoot); } }); }); }); describe('app relative', function () { it('should be able to push and pull a file from the app directory', async function () { const stringData = `random string data ${Math.random()}`; const base64Data = Buffer.from(stringData).toString('base64'); const remotePath = `${UICAT_CONTAINER}/UICatalog.app/somefile.tmp`; await driver.pushFile(remotePath, base64Data); const remoteStringData = await pullFileAsString(driver, remotePath); (0, chai_1.expect)(remoteStringData).to.equal(stringData); }); it('should be able to delete a file from the app directory', async function () { const stringData = `random string data ${Math.random()}`; const base64Data = Buffer.from(stringData).toString('base64'); const remotePath = `${UICAT_CONTAINER}/UICatalog.app/somefile.tmp`; await driver.pushFile(remotePath, base64Data); const remoteStringData = await pullFileAsString(driver, remotePath); (0, chai_1.expect)(remoteStringData).to.equal(stringData); await driver.execute('mobile: deleteFile', { remotePath }); await (0, chai_1.expect)(pullFileAsString(driver, remotePath)).to.be.rejectedWith(/does not exist/); }); }); }); //# sourceMappingURL=file-movement-e2e-specs.js.map