UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

263 lines 14.5 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 lodash_1 = __importDefault(require("lodash")); const desired_1 = require("../desired"); const session_1 = require("../helpers/session"); const helpers_1 = require("./helpers"); const asyncbox_1 = require("asyncbox"); 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 GET_ELEM_SYNC = `return document.getElementsByTagName('h1')[0].innerHTML;`; const GET_ELEM_ASYNC = `arguments[arguments.length - 1](document.getElementsByTagName('h1')[0].innerHTML);`; const FRAMESET_TITLE = 'Frameset guinea pig'; const IFRAME_FRAMESET_TITLE = 'Iframe guinea pig'; const SUB_FRAME_1_TITLE = 'Sub frame 1'; const SUB_FRAME_2_TITLE = 'Sub frame 2'; const SUB_FRAME_3_TITLE = 'Sub frame 3'; const DEFAULT_IMPLICIT_TIMEOUT_MS = 1000; describe('safari - windows and frames', function () { describe('without safariAllowPopups', function () { this.timeout(session_1.MOCHA_TIMEOUT); let driver; before(async function () { const caps = (0, desired_1.amendCapabilities)(desired_1.SAFARI_CAPS, { 'appium:safariInitialUrl': helpers_1.GUINEA_PIG_PAGE, 'appium:safariAllowPopups': false, }); driver = await (0, session_1.initSession)(caps); await driver.setTimeout({ pageLoad: 100 }); }); after(async function () { await (0, session_1.deleteSession)(); }); it('should not be able to open js popup windows', async function () { await driver.executeScript("window.open('/test/guinea-pig2.html', null)", []); await (0, chai_1.expect)((0, helpers_1.spinTitleEquals)(driver, 'I am another page title', 5)).to.be.rejected; }); }); describe('with safariAllowPopups', function () { this.timeout(session_1.MOCHA_TIMEOUT); let driver; before(async function () { const caps = (0, desired_1.amendCapabilities)(desired_1.SAFARI_CAPS, { 'appium:safariInitialUrl': helpers_1.GUINEA_PIG_PAGE, 'appium:safariAllowPopups': true, // using JS atoms to open new window will, even if safari does not disable // popups, open an alert asking if it is ok. 'appium:nativeWebTap': true, }); driver = await (0, session_1.initSession)(caps); await driver.setTimeout({ pageLoad: 90000 }); }); after(async function () { await (0, session_1.deleteSession)(); }); describe('windows', function () { before(async function () { await driver.setTimeout({ implicit: DEFAULT_IMPLICIT_TIMEOUT_MS }); }); beforeEach(async function () { await (0, helpers_1.openPage)(driver, helpers_1.GUINEA_PIG_PAGE); }); it('should be able to open js popup windows', async function () { await driver.updateSettings({ autoClickAlertSelector: '**/XCUIElementTypeStaticText[`label == "Allow"`]' }); await driver.executeScript(`window.open('/test/guinea-pig2.html', '_blank');`, []); await (0, chai_1.expect)((0, helpers_1.spinTitleEquals)(driver, 'I am another page title', 5)).to.eventually.not.be .rejected; await driver.updateSettings({ autoClickAlertSelector: '' }); await driver.closeWindow(); }); it('should throw nosuchwindow if there is not one', async function () { await (0, chai_1.expect)(driver .switchToWindow('noexistman')).to.be.rejectedWith(/window could not be found/); }); it('should be able to open and close windows', async function () { if (process.env.CI && (0, desired_1.isIosVersionBelow)('18.0')) { this.skip(); } const el = await driver.$('#blanklink'); await el.click(); await (0, helpers_1.spinTitleEquals)(driver, 'I am another page title'); await driver.closeWindow(); await (0, helpers_1.spinTitleEquals)(driver, 'I am a page title'); }); it('should be able to use window handles', async function () { if (process.env.CI && (0, desired_1.isIosVersionBelow)('18.0')) { this.skip(); } const initialWindowHandle = await driver.getWindowHandle(); const el = await driver.$('#blanklink'); await el.click(); await (0, helpers_1.spinTitleEquals)(driver, 'I am another page title'); const newWindowHandle = await driver.getWindowHandle(); // should still have the first page await driver.switchToWindow(initialWindowHandle); await (0, helpers_1.spinTitleEquals)(driver, 'I am a page title'); // should still have the second page await driver.switchToWindow(newWindowHandle); await (0, helpers_1.spinTitleEquals)(driver, 'I am another page title'); // close and we should have the original page await driver.closeWindow(); await (0, helpers_1.spinTitleEquals)(driver, 'I am a page title'); }); it('should be able to go back and forward', async function () { if (process.env.CI && (0, desired_1.isIosVersionBelow)('18.0')) { this.skip(); } const link = await driver.$('=i am a link'); await link.click(); const waitUntilNotExist = async (locator, timeout = 5000) => { await driver.setTimeout({ implicit: 0 }); try { await (0, asyncbox_1.waitForCondition)(async () => lodash_1.default.isEmpty(await driver.$$(locator)), { waitMs: timeout, intervalMs: 300, }); } catch { throw new Error(`Element located by '${locator}' still exists after ${timeout}ms timeout`); } finally { await driver.setTimeout({ implicit: DEFAULT_IMPLICIT_TIMEOUT_MS }); } }; await waitUntilNotExist('#i_am_a_textbox'); await driver.back(); await waitUntilNotExist('#only_on_page_2'); await driver.forward(); await waitUntilNotExist('#i_am_a_textbox'); await driver.back(); }); // broken on real devices, see https://github.com/appium/appium/issues/5167 it('should be able to open js popup windows with safariAllowPopups set to true @skip-real-device', async function () { if (process.env.CI && (0, desired_1.isIosVersionBelow)('18.0')) { this.skip(); } const link = await driver.$('=i am a new window link'); await link.click(); await (0, helpers_1.spinTitleEquals)(driver, 'I am another page title', 30); }); }); describe('frames', function () { beforeEach(async function () { await (0, helpers_1.openPage)(driver, helpers_1.GUINEA_PIG_FRAME_PAGE); }); it('should switch to frame by index', async function () { await driver.switchToFrame(0); await (0, chai_1.expect)(driver.getTitle()).to.eventually.equal(FRAMESET_TITLE); const h1 = await driver.$('<h1 />'); await (0, chai_1.expect)(h1.getText()).to.eventually.equal(SUB_FRAME_1_TITLE); }); it('should switch to frame by element', async function () { await driver.switchToFrame(await driver.$('#frame3')); await (0, chai_1.expect)(driver.getTitle()).to.eventually.equal(FRAMESET_TITLE); const h1 = await driver.$('<h1 />'); await (0, chai_1.expect)(h1.getText()).to.eventually.equal(SUB_FRAME_3_TITLE); }); it('should switch back to default content from frame', async function () { await driver.switchToFrame(await driver.$('[name="first"]')); await (0, chai_1.expect)(driver.getTitle()).to.eventually.equal(FRAMESET_TITLE); const h1 = await driver.$('<h1 />'); await (0, chai_1.expect)(h1.getText()).to.eventually.equal(SUB_FRAME_1_TITLE); await driver.switchToFrame(null); (0, chai_1.expect)(lodash_1.default.isEmpty(await driver.$$('<frameset />'))).to.be.false; }); it('should switch to child frames', async function () { await driver.switchToFrame(await driver.$('[name="third"]')); await (0, chai_1.expect)(driver.getTitle()).to.eventually.equal(FRAMESET_TITLE); await driver.switchToFrame(await driver.$('[name="childframe"]')); (0, chai_1.expect)(lodash_1.default.isEmpty(await driver.$$('#only_on_page_2'))).to.be.false; }); it('should execute javascript in frame', async function () { await driver.switchToFrame(1); await (0, chai_1.expect)(driver.executeScript(GET_ELEM_SYNC, [])).to.eventually.equal(SUB_FRAME_2_TITLE); }); it('should execute async javascript in frame', async function () { await driver.setTimeout({ script: 2000 }); await driver.switchToFrame(0); await (0, chai_1.expect)(driver.executeAsync(GET_ELEM_ASYNC)).to.eventually.equal(SUB_FRAME_1_TITLE); }); it('should get source within a frame', async function () { await (0, chai_1.expect)(driver.getPageSource()).to.eventually.include(FRAMESET_TITLE); await driver.switchToFrame(0); const frameSource = await driver.getPageSource(); (0, chai_1.expect)(frameSource).to.include(SUB_FRAME_1_TITLE); (0, chai_1.expect)(frameSource).to.not.include(FRAMESET_TITLE); }); }); describe('iframes', function () { beforeEach(async function () { await (0, helpers_1.openPage)(driver, helpers_1.GUINEA_PIG_IFRAME_PAGE); }); it('should switch to iframe by index', async function () { await driver.switchToFrame(0); await (0, chai_1.expect)(driver.getTitle()).to.eventually.equal(IFRAME_FRAMESET_TITLE); const h1 = await driver.$('<h1 />'); await (0, chai_1.expect)(h1.getText()).to.eventually.equal(SUB_FRAME_1_TITLE); }); it('should switch to iframe by element', async function () { await driver.switchToFrame(await driver.$('#id-iframe3')); await (0, chai_1.expect)(driver.getTitle()).to.eventually.equal(IFRAME_FRAMESET_TITLE); const h1 = await driver.$('<h1 />'); await (0, chai_1.expect)(h1.getText()).to.eventually.equal(SUB_FRAME_3_TITLE); }); it('should not switch to iframe by element of wrong type', async function () { const h1 = await driver.findElement('tag name', 'h1'); await (0, chai_1.expect)(driver.switchToFrame(h1)).to.be.rejected; }); it('should switch back to default content from iframe', async function () { await driver.switchToFrame(await driver.$('[name="iframe1"]')); await (0, chai_1.expect)(driver.getTitle()).to.eventually.equal(IFRAME_FRAMESET_TITLE); const h1 = await driver.$('<h1 />'); await (0, chai_1.expect)(h1.getText()).to.eventually.equal(SUB_FRAME_1_TITLE); await driver.switchToFrame(null); (0, chai_1.expect)(lodash_1.default.size(await driver.$$('<iframe />'))).to.eql(3); }); it('should get source within an iframe', async function () { await (0, chai_1.expect)(driver.getPageSource()).to.eventually.include(IFRAME_FRAMESET_TITLE); await driver.switchToFrame(await driver.$('[name="iframe1"]')); const frameSource = await driver.getPageSource(); (0, chai_1.expect)(frameSource).to.include(SUB_FRAME_1_TITLE); (0, chai_1.expect)(frameSource).to.not.include(IFRAME_FRAMESET_TITLE); }); }); }); }); //# sourceMappingURL=safari-window-e2e-specs.js.map