UNPKG

@appium/base-driver

Version:

Base driver class for Appium drivers

69 lines 3.13 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.STATIC_DIR = void 0; exports.guineaPig = guineaPig; exports.guineaPigScrollable = guineaPigScrollable; exports.guineaPigAppBanner = guineaPigAppBanner; exports.welcome = welcome; const node_path_1 = __importDefault(require("node:path")); const logger_1 = require("./logger"); const lodash_1 = __importDefault(require("lodash")); const support_1 = require("@appium/support"); const bluebird_1 = __importDefault(require("bluebird")); exports.STATIC_DIR = lodash_1.default.isNull(node_path_1.default.resolve(__dirname).match(/build[/\\]lib[/\\]express$/)) ? node_path_1.default.resolve(__dirname, '..', '..', 'static') : node_path_1.default.resolve(__dirname, '..', '..', '..', 'static'); /** Dynamic page mapped to /test/guinea-pig */ async function guineaPig(req, res) { await guineaPigTemplate(req, res, 'guinea-pig.html'); } /** Dynamic page mapped to /test/guinea-pig-scrollable */ async function guineaPigScrollable(req, res) { await guineaPigTemplate(req, res, 'guinea-pig-scrollable.html'); } /** Dynamic page mapped to /test/guinea-pig-app-banner */ async function guineaPigAppBanner(req, res) { await guineaPigTemplate(req, res, 'guinea-pig-app-banner.html'); } /** Dynamic page mapped to /welcome */ async function welcome(req, res) { const params = { message: "Let's browse!" }; logger_1.log.debug(`Sending welcome response with params: ${JSON.stringify(params)}`); const template = await getTemplate('welcome.html'); res.send(template(params)); } async function guineaPigTemplate(req, res, page) { const delay = parseInt(String(req.params.delay ?? (req.query?.delay ?? 0)), 10); const throwError = String(req.params.throwError ?? req.query?.throwError ?? ''); const params = { throwError, serverTime: new Date(), userAgent: req.headers['user-agent'], comment: 'None', }; if (req.method === 'POST' && req.body && typeof req.body === 'object' && 'comments' in req.body) { params.comment = String(req.body.comments ?? params.comment); } logger_1.log.debug(`Sending guinea pig response with params: ${JSON.stringify(params)}`); if (delay) { logger_1.log.debug(`Waiting ${delay}ms before responding`); await bluebird_1.default.delay(delay); } res.set('content-type', 'text/html'); res.cookie('guineacookie1', 'i am a cookie value', { path: '/' }); res.cookie('guineacookie2', 'cookié2', { path: '/' }); res.cookie('guineacookie3', 'cant access this', { domain: '.blargimarg.com', path: '/', }); const template = await getTemplate(page); res.send(template(params)); } async function getTemplate(templateName) { const content = await support_1.fs.readFile(node_path_1.default.resolve(exports.STATIC_DIR, 'test', templateName)); return lodash_1.default.template(content.toString()); } //# sourceMappingURL=static.js.map