UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

129 lines 5.38 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 session_1 = require("../helpers/session"); 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('XCUITestDriver - alerts -', 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)(); }); beforeEach(async function () { await (0, asyncbox_1.retryInterval)(5, 500, async () => { const el = await driver.$('~Alert Views'); await el.click(); (0, chai_1.expect)(await driver.$$('~Simple')).to.have.length(1); }); }); afterEach(async function () { try { await driver.dismissAlert(); } catch { } await driver.back(); }); it('should detect Simple', async function () { const el = await driver.$('~Simple'); await el.click(); await bluebird_1.default.delay(2000); (0, chai_1.expect)(await driver.getAlertText()).to.include('A Short Title Is Best'); await driver.dismissAlert(); }); it('should detect Okay', async function () { const el = await driver.$('~Okay / Cancel'); await el.click(); // small pause for alert to open await bluebird_1.default.delay(1000); (0, chai_1.expect)(await driver.getAlertText()).to.include('A Short Title Is Best'); await driver.acceptAlert(); }); it('should detect Other', async function () { const el = await driver.$('~Other'); await el.click(); // small pause for alert to open await bluebird_1.default.delay(1000); (0, chai_1.expect)(await driver.getAlertText()).to.include('A Short Title Is Best'); await driver.dismissAlert(); }); describe('prompt -', function () { const testData = [ { name: 'text field', alert: 'Text Entry', field: 'XCUIElementTypeTextField', text: 'hello world', expectedText: 'hello world', }, { name: 'secure text field', alert: 'Secure Text Entry', field: 'XCUIElementTypeSecureTextField', text: 'hello world', expectedText: '•••••••••••', }, ]; for (const test of testData) { it(`should be able to interact with a prompt with a ${test.name}`, async function () { const el = await driver.$(`~${test.alert}`); await el.click(); // small pause for alert to open await bluebird_1.default.delay(1000); await driver.sendAlertText(test.text); const textField = await driver.$(test.field); const text = await textField.getText(); (0, chai_1.expect)(text).to.equal(test.expectedText); // on some devices the keyboard obscurs the buttons so no dismiss is possible await textField.setValue('\n'); }); } }); it('should throw a NoAlertOpenError when no alert is open', async function () { await (0, chai_1.expect)(driver.acceptAlert()).to.be.rejectedWith(/An attempt was made to operate on a modal dialog when one was not open/); }); }); //# sourceMappingURL=alert-e2e-specs.js.map