appium-safari-driver
Version:
Appium driver for Safari browser
119 lines • 4.48 kB
JavaScript
;
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;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SafariDriver = void 0;
const driver_1 = require("appium/driver");
const safari_1 = require("./safari");
const desired_caps_1 = require("./desired-caps");
const cookieCommands = __importStar(require("./commands/cookies"));
const findCommands = __importStar(require("./commands/find"));
const recordScreenCommands = __importStar(require("./commands/record-screen"));
const utils_1 = require("./utils");
const method_map_1 = require("./method-map");
/** @type {import('@appium/types').RouteMatcher[]} */
const NO_PROXY = [
['GET', new RegExp('^/session/[^/]+/appium')],
['POST', new RegExp('^/session/[^/]+/appium')],
['POST', new RegExp('^/session/[^/]+/element/[^/]+/elements?$')],
['POST', new RegExp('^/session/[^/]+/elements?$')],
['DELETE', new RegExp('^/session/[^/]+/cookie$')],
];
class SafariDriver extends driver_1.BaseDriver {
constructor(opts = {}) {
// @ts-ignore TODO: make args typed
super(opts);
this.deleteCookies = cookieCommands.deleteCookies;
this.findElOrEls = findCommands.findElOrEls;
this.startRecordingScreen = recordScreenCommands.startRecordingScreen;
this.stopRecordingScreen = recordScreenCommands.stopRecordingScreen;
this.desiredCapConstraints = desired_caps_1.desiredCapConstraints;
this.locatorStrategies = [
'xpath',
'tag name',
'link text',
'partial link text',
'css selector',
// Let these two reach Safari Driver and fail there with a proper error message
'id',
'name',
];
this.resetState();
}
resetState() {
// @ts-ignore That's ok
this.safari = null;
this.proxyReqRes = null;
this.isProxyActive = false;
this._screenRecorder = null;
}
proxyActive() {
return this.isProxyActive;
}
getProxyAvoidList() {
return NO_PROXY;
}
canProxy() {
return true;
}
// @ts-ignore TODO: make args typed
async createSession(...args) {
// @ts-ignore TODO: make args typed
const [sessionId, caps] = await super.createSession(...args);
this.safari = new safari_1.SafariDriverServer(this.log);
try {
await this.safari.start((0, utils_1.formatCapsForServer)(caps), {
reqBasePath: this.basePath,
});
}
catch (e) {
await this.deleteSession();
throw e;
}
this.proxyReqRes = this.safari.proxy?.proxyReqRes.bind(this.safari.proxy);
this.isProxyActive = true;
return [sessionId, caps];
}
async deleteSession() {
this.log.info('Ending Safari session');
await this._screenRecorder?.stop(true);
await this.safari?.stop();
this.resetState();
await super.deleteSession();
}
}
exports.SafariDriver = SafariDriver;
SafariDriver.newMethodMap = method_map_1.newMethodMap;
exports.default = SafariDriver;
//# sourceMappingURL=driver.js.map