UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

211 lines 10.2 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 bluebird_1 = __importDefault(require("bluebird")); const asyncbox_1 = require("asyncbox"); const desired_1 = require("../desired"); const element_1 = require("../helpers/element"); const session_1 = require("../helpers/session"); const helpers_1 = require("../web/helpers"); 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 BTN_OK_CNCL = 'Okay / Cancel'; describe('XCUITestDriver - gestures', function () { this.timeout(session_1.MOCHA_TIMEOUT); let driver; describe('dynamic gestures', function () { before(async function () { const uiCatalogCaps = await (0, desired_1.getUICatalogCaps)(); driver = await (0, session_1.initSession)(uiCatalogCaps); }); beforeEach(async function () { await driver.back(); await (0, asyncbox_1.retryInterval)(5, 500, async function () { const el = await driver.$('~Alert Views'); await driver.execute('mobile: scroll', { element: el, toVisible: true }); }); }); after(async function () { await (0, session_1.deleteSession)(); }); afterEach(async function () { // wait a moment to allow anything to happen await bluebird_1.default.delay(500); }); describe('tap, press, longpress', function () { beforeEach(async function () { const el = await driver.$('~Alert Views'); await el.click(); const btn = await driver.$(`~${BTN_OK_CNCL}`); await btn.waitForExist({ timeout: 500 }); }); async function exitModal(name) { // should exist, will throw error if it doesn't const els = await driver.$(`~${name}`); await (0, chai_1.expect)(els.isExisting()).to.eventually.be.equal(true); await (0, asyncbox_1.retryInterval)(5, 100, async () => { const el = await driver.$(`~${name}`); await el.click(); }); } describe('using action', function () { it('should tap on the element with action', async function () { const el = await driver.$(`~${BTN_OK_CNCL}`); await driver.action('pointer').move({ origin: el }).down().pause(100).up().perform(); await exitModal('OK'); }); it('should tap on arbitrary coordinates with action', async function () { const el = await driver.$(`~${BTN_OK_CNCL}`); const loc = await el.getLocation(); const size = await el.getSize(); await driver .action('pointer') .move(loc.x + size.width / 2, loc.y + size.height / 2) .down() .pause(100) .up() .perform(); await exitModal('OK'); }); }); }); // TODO: Need a scrollable screen. it.skip('should scroll using actions', async function () { const el1 = await driver.$('~Activity Indicators'); const loc1 = await el1.getLocation(); const size1 = await el1.getSize(); const el2 = await driver.$('~Progress Views'); const loc2 = await el2.getLocation(); const size2 = await el2.getSize(); const el3 = await driver.$('~Web View'); await (0, chai_1.expect)(el3.isDisplayed()).to.eventually.be.false; await driver .action('pointer') .move(loc1.x + size1.width / 2, loc1.y + size1.height / 2) .down() .pause(500) .move(loc2.x + size2.width / 2, loc2.y + size2.height / 2) .up() .perform(); await (0, asyncbox_1.retryInterval)(5, 1000, async function () { await (0, chai_1.expect)(el3.isDisplayed()).to.eventually.be.equal(true); }); }); it('should double tap on an element', async function () { await driver.execute('mobile: scroll', { direction: 'down' }); const steppers = await driver.$('~Steppers'); await steppers.click(); await bluebird_1.default.delay(1000); const stepper = await driver.$('~Increment'); await driver.action('pointer').move({ origin: stepper }).down().pause(500).up().perform(); await driver.action('pointer').move({ origin: stepper }).down().pause(500).up().perform(); await bluebird_1.default.delay(1000); const num = await driver.$('~2'); await (0, chai_1.expect)(num.isExisting()).to.eventually.be.true; }); // TODO: Need a scrollable screen. it.skip(`should swipe the table and the bottom cell's Y position should change accordingly`, async function () { const winEl = await driver.$(`${element_1.PREDICATE_SEARCH}:type == 'XCUIElementTypeWindow'`); const pickerEl = await driver.$('~Picker View'); const loc = await pickerEl.getLocation(); await (0, chai_1.expect)(driver.execute('mobile: swipe', { element: winEl, direction: 'up' })).to.not.be .rejected; const locMiddle = await pickerEl.getLocation(); (0, chai_1.expect)(locMiddle.y).to.be.below(loc.y); await (0, chai_1.expect)(driver.execute('mobile: swipe', { element: winEl, direction: 'down' })).to.not.be .rejected; const locFinal = await pickerEl.getLocation(); (0, chai_1.expect)(locFinal.y).to.be.above(locMiddle.y); }); describe('pinch and zoom', function () { beforeEach(async function () { await driver.execute('mobile: scroll', { direction: 'down' }); const el = await driver.$('~Web View'); await el.click(); }); // at this point this test relies on watching it happen, nothing is asserted // in automation, this just checks that errors aren't thrown it('should be able to pinch', async function () { const ctxs = await driver.execute('mobile: getContexts', { waitForWebviewMs: 1000 }); await driver.switchContext(ctxs[1].id); await driver.url(helpers_1.APPIUM_IMAGE); await driver.switchContext(ctxs[0].id); async function doZoom() { const el = await driver.$(`${element_1.PREDICATE_SEARCH}:type == 'XCUIElementTypeApplication'`); const thumb = driver .action('pointer') .move({ origin: el, x: 100, y: 0 }) .down() .pause(100) .move({ origin: el, x: 50, y: 0 }) .up(); const foreFinger = driver .action('pointer') .move({ origin: el, x: 100, y: 0 }) .down() .pause(100) .move({ origin: el, x: 105, y: 0 }) .up(); await driver.actions([thumb, foreFinger]); } await doZoom(); async function doPinch() { const el = await driver.$(`${element_1.PREDICATE_SEARCH}:type == 'XCUIElementTypeApplication'`); const thumb = driver .action('pointer') .move({ origin: el, x: 50, y: 0 }) .down() .pause(100) .move({ origin: el, x: 100, y: 0 }) .up(); const foreFinger = driver .action('pointer') .move({ origin: el, x: 100, y: 0 }) .down() .pause(100) .move({ origin: el, x: 50, y: 0 }) .up(); await driver.actions([thumb, foreFinger]); } await doPinch(); }); }); }); }); //# sourceMappingURL=gesture-e2e-specs.js.map