UNPKG

appwright

Version:

E2E mobile app testing done right, with the Playwright test runner

79 lines (78 loc) 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.expect = exports.test = void 0; const test_1 = require("@playwright/test"); const providers_1 = require("../providers"); const workerInfo_1 = require("./workerInfo"); const appium_1 = require("../providers/appium"); exports.test = test_1.test.extend({ deviceProvider: async ({}, use, testInfo) => { const deviceProvider = (0, providers_1.createDeviceProvider)(testInfo.project); await use(deviceProvider); }, device: async ({ deviceProvider }, use, testInfo) => { const device = await deviceProvider.getDevice(); const deviceProviderName = testInfo.project.use.device?.provider; testInfo.annotations.push({ type: "providerName", description: deviceProviderName, }); testInfo.annotations.push({ type: "sessionId", description: deviceProvider.sessionId, }); await deviceProvider.syncTestDetails?.({ name: testInfo.title }); await use(device); await device.close(); if (deviceProviderName === "emulator" || deviceProviderName === "local-device") { await (0, appium_1.stopAppiumServer)(); } await deviceProvider.syncTestDetails?.({ name: testInfo.title, status: testInfo.status, reason: testInfo.error?.message, }); }, persistentDevice: [ async ({}, use, workerInfo) => { const { project, workerIndex } = workerInfo; const beforeSession = new Date(); const deviceProvider = (0, providers_1.createDeviceProvider)(project); const device = await deviceProvider.getDevice(); const sessionId = deviceProvider.sessionId; if (!sessionId) { throw new Error("Worker must have a sessionId."); } const providerName = project.use.device ?.provider; const afterSession = new Date(); const workerInfoStore = new workerInfo_1.WorkerInfoStore(); await workerInfoStore.saveWorkerStartTime(workerIndex, sessionId, providerName, beforeSession, afterSession); await use(device); await workerInfoStore.saveWorkerEndTime(workerIndex, new Date()); await device.close(); }, { scope: "worker" }, ], }); /** * Function to extend Playwright’s expect assertion capabilities. * This adds a new method `toBeVisible` which checks if an element is visible on the screen. * * @param locator The AppwrightLocator that locates the element on the device screen. * @param options * @returns */ exports.expect = exports.test.expect.extend({ toBeVisible: async (locator, options) => { const isVisible = await locator.isVisible(options); return { message: () => (isVisible ? "" : `Element was not found on the screen`), pass: isVisible, name: "toBeVisible", expected: true, actual: isVisible, }; }, });