UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

137 lines 5.99 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 }); exports.oldCookie2 = exports.oldCookie1 = exports.newCookie = exports.GUINEA_PIG_APP_BANNER_PAGE = exports.GUINEA_PIG_SCROLLABLE_PAGE = exports.APPIUM_IMAGE = exports.PHISHING_END_POINT = exports.GUINEA_PIG_IFRAME_PAGE = exports.GUINEA_PIG_FRAME_PAGE = exports.GUINEA_PIG_PAGE = void 0; exports.spinTitle = spinTitle; exports.spinTitleEquals = spinTitleEquals; exports.spinWait = spinWait; exports.openPage = openPage; exports.doesIncludeCookie = doesIncludeCookie; exports.doesNotIncludeCookie = doesNotIncludeCookie; exports.spinBodyIncludes = spinBodyIncludes; const asyncbox_1 = require("asyncbox"); const session_1 = require("../helpers/session"); const lodash_1 = __importDefault(require("lodash")); const chai_1 = __importStar(require("chai")); chai_1.default.should(); const BASE_END_POINT = `http://${session_1.HOST}:${session_1.PORT}`; const TEST_END_POINT = `${BASE_END_POINT}/test`; const GUINEA_PIG_PAGE = `${TEST_END_POINT}/guinea-pig`; exports.GUINEA_PIG_PAGE = GUINEA_PIG_PAGE; const GUINEA_PIG_SCROLLABLE_PAGE = `${GUINEA_PIG_PAGE}-scrollable`; exports.GUINEA_PIG_SCROLLABLE_PAGE = GUINEA_PIG_SCROLLABLE_PAGE; const GUINEA_PIG_APP_BANNER_PAGE = `${GUINEA_PIG_PAGE}-app-banner`; exports.GUINEA_PIG_APP_BANNER_PAGE = GUINEA_PIG_APP_BANNER_PAGE; const GUINEA_PIG_FRAME_PAGE = `${TEST_END_POINT}/frameset.html`; exports.GUINEA_PIG_FRAME_PAGE = GUINEA_PIG_FRAME_PAGE; const GUINEA_PIG_IFRAME_PAGE = `${TEST_END_POINT}/iframes.html`; exports.GUINEA_PIG_IFRAME_PAGE = GUINEA_PIG_IFRAME_PAGE; // if the phishing URL stops working for some reason, see // http://testsafebrowsing.appspot.com/ for alternatives const PHISHING_END_POINT = 'http://testsafebrowsing.appspot.com/s/phishing.html'; exports.PHISHING_END_POINT = PHISHING_END_POINT; const APPIUM_IMAGE = `${BASE_END_POINT}/appium.png`; exports.APPIUM_IMAGE = APPIUM_IMAGE; const newCookie = { name: 'newcookie', value: 'i am new here', }; exports.newCookie = newCookie; const oldCookie1 = { name: 'guineacookie1', value: 'i am a cookie value', }; exports.oldCookie1 = oldCookie1; const oldCookie2 = { name: 'guineacookie2', value: 'cookié2', }; exports.oldCookie2 = oldCookie2; function doesIncludeCookie(cookies, cookie) { (0, chai_1.expect)(cookies.map((c) => c.name)).to.include(cookie.name); (0, chai_1.expect)(cookies.map((c) => c.value)).to.include(cookie.value); } function doesNotIncludeCookie(cookies, cookie) { (0, chai_1.expect)(cookies.map((c) => c.name)).to.not.include(cookie.name); (0, chai_1.expect)(cookies.map((c) => c.value)).to.not.include(cookie.value); } async function spinTitle(driver) { return await (0, asyncbox_1.retry)(10, async function () { const title = await driver.getTitle(); if (lodash_1.default.isNil(title)) { throw new Error('Did not get a page title'); } return title; }); } async function spinBodyIncludes(driver, expected) { return await (0, asyncbox_1.retry)(10, async function () { const el = await driver.$('//body'); const body = await el.getHTML(); if (!lodash_1.default.includes(body, expected)) { throw new Error(`Could not find '${expected}' in the page body. Found: '${body}'`); } }); } async function spinTitleEquals(driver, expectedTitle, tries = 10, interval = 500) { await (0, asyncbox_1.retryInterval)(tries, interval, async function () { const title = await spinTitle(driver); if (title !== expectedTitle) { throw new Error(`Could not find expected title: '${expectedTitle}'. Found: '${title}'`); } }); } async function spinTitleNotEquals(driver, wrongTitle, tries = 10, interval = 500) { await (0, asyncbox_1.retryInterval)(tries, interval, async function () { const title = await spinTitle(driver); if (title === wrongTitle) { throw new Error(`Found title we did not expect: '${title}'`); } }); } async function spinWait(fn, waitMs = 10000, intMs = 500) { const tries = parseInt(String(waitMs / intMs), 10); await (0, asyncbox_1.retryInterval)(tries, intMs, fn); } async function openPage(driver, url, tries = 10, interval = 500) { await (0, asyncbox_1.retryInterval)(tries, interval, async function () { await driver.navigateTo(url); await spinTitleNotEquals(driver, 'cannot open page'); }); } //# sourceMappingURL=helpers.js.map