UNPKG

appium-flutter-driver

Version:
52 lines 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertTappable = exports.assertNotVisible = exports.assertVisible = void 0; const appium_flutter_finder_1 = require("appium-flutter-finder"); // Serialize a finder to base64 const serializeFinder = (finder) => Buffer.from(JSON.stringify(finder)).toString('base64'); // Type guards const isRawFinder = (input) => input && typeof input === 'object' && typeof input.finderType === 'string'; const isFlutterElementLike = (input) => input && typeof input === 'object' && typeof input.getRawFinder === 'function'; // Convert FinderInput to base64 string function getFinderBase64(input) { if (typeof input === 'string') { return input; // already base64 } if (isFlutterElementLike(input)) { return serializeFinder(input.getRawFinder()); } if (isRawFinder(input)) { return serializeFinder(input); } if ('key' in input) { return (0, appium_flutter_finder_1.byValueKey)(input.key); } if ('text' in input) { return (0, appium_flutter_finder_1.byText)(input.text); } if ('label' in input) { return (0, appium_flutter_finder_1.byTooltip)(input.label); } throw new Error('Invalid finder input: must provide key, text, label, raw finder, or FlutterElement'); } // Generic helper to wrap assert commands async function executeAssertion(driver, command, input, timeout = 5000, extraArgs = {}) { const base64 = getFinderBase64(input); try { await driver.executeElementCommand(command, base64, { timeout, ...extraArgs, }); } catch (err) { throw new Error(`Assertion failed on command "${command}" within ${timeout}ms\n${err}`); } } // Exported assertion commands const assertVisible = async (driver, input, timeout = 5000) => await executeAssertion(driver, 'waitFor', input, timeout, { visible: true }); exports.assertVisible = assertVisible; const assertNotVisible = async (driver, input, timeout = 5000) => await executeAssertion(driver, 'waitForAbsent', input, timeout); exports.assertNotVisible = assertNotVisible; const assertTappable = async (driver, input, timeout = 5000) => await executeAssertion(driver, 'waitForTappable', input, timeout); exports.assertTappable = assertTappable; //# sourceMappingURL=assertions.js.map