Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// TODO: Wait until the connection is actually closed
// after the corresponding fixes are done in appium-ios-device
// module. Without the fixes the close event might be delayed for up to
// 30 seconds (see https://github.com/appium/appium-xcuitest-driver/pull/1094#issuecomment-546578765)
this.serverSocket.once('close', () => {
this.log.info('The connection has been closed');
this.serverSocket = null;
});
this.serverSocket.close();
}
}
const log = logger.getLogger('DevCon Factory');
const SPLITTER = ':';
class DeviceConnectionsFactory {
constructor () {
this._connectionsMapping = {};
}
_udidAsToken (udid) {
return `${util.hasValue(udid) ? udid : ''}${SPLITTER}`;
}
_portAsToken (port) {
return `${SPLITTER}${util.hasValue(port) ? port : ''}`;
}
_toKey (udid = null, port = null) {
// transpile:main
import http from 'http';
import B from 'bluebird';
import ws from 'ws';
import { logger } from 'appium-support';
const log = logger.getLogger('RemoteDebugger');
let WebSocketServer = ws.Server;
// fake server for allowing both http requests and
// websocket requests, as needed to test Appium's
// version of webkit remote debugging support
class WebKitRemoteDebuggerServer {
constructor () {
this.server = null;
this.websocketServer = null;
this.nextResponse = null;
}
// start the server
// if a websocket server is needed, pass in `true`
async start (ws = false) {
/*
* derived from jQuery Cookie Plugin v1.4.1
* https://github.com/carhartl/jquery-cookie
*/
// needed to communicate/translate between JSONWire cookies and regular JavaScript cookies
import _ from 'lodash';
import { logger } from 'appium-support';
const log = logger.getLogger('Cookie');
// parses the value if needed and converts the value if a converter is provided
// internal function, not exported
function convertCookie (value, converter) {
if (value.indexOf('"') === 0) {
// this is a quoted cookied according to RFC2068
// remove enclosing quotes and internal quotes and backslashes
value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}
let parsedValue;
try {
parsedValue = decodeURIComponent(value.replace(/\+/g, ' '));
} catch (e) {
// no need to fail if we can't decode
log.warn(e);
screenRecordCmd += ` --bit-rate=${adjustedBitrate}`;
}
const adbArgs = [
...adb.executable.defaultArgs,
'exec-out',
// The loop is required, because by default the maximum record duration
// for screenrecord is always limited
`while true; do ${screenRecordCmd} -; done`,
];
const deviceStreaming = spawn(adb.executable.path, adbArgs);
deviceStreaming.on('exit', (code, signal) => {
log.debug(`Device streaming process exited with code ${code}, signal ${signal}`);
});
let isStarted = false;
const deviceStreamingLogger = logger.getLogger(`${SCREENRECORD_BINARY}@${this.opts.udid}`);
const errorsListener = (chunk) => {
const stderr = chunk.toString();
if (_.trim(stderr)) {
deviceStreamingLogger.debug(stderr);
}
};
deviceStreaming.stderr.on('data', errorsListener);
const startupListener = (chunk) => {
if (!isStarted) {
isStarted = !_.isEmpty(chunk);
}
};
deviceStreaming.stdout.on('data', startupListener);
try {
public static async getInstance(): Promise {
if (!this.instance) {
this.instance = new ServerDeviceConnection(logger.getLogger('ServerDeviceConnection'));
}
return this.instance;
}
constructor(private readonly log: logger) {
import log from './logger';
import { SERVER_APK_PATH as apkPath, TEST_APK_PATH as testApkPath, version as serverVersion } from 'appium-uiautomator2-server';
import { util, logger, tempDir, fs, timing } from 'appium-support';
import B from 'bluebird';
import helpers from './helpers';
import request from 'request-promise';
import path from 'path';
const REQD_PARAMS = ['adb', 'tmpDir', 'host', 'systemPort', 'devicePort', 'disableWindowAnimation'];
const SERVER_LAUNCH_TIMEOUT = 30000;
const SERVER_INSTALL_RETRIES = 20;
const SERVICES_LAUNCH_TIMEOUT = 30000;
const SERVER_PACKAGE_ID = 'io.appium.uiautomator2.server';
const SERVER_TEST_PACKAGE_ID = `${SERVER_PACKAGE_ID}.test`;
const INSTRUMENTATION_TARGET = `${SERVER_TEST_PACKAGE_ID}/androidx.test.runner.AndroidJUnitRunner`;
const instrumentationLogger = logger.getLogger('Instrumentation');
class UiAutomator2Server {
constructor (opts = {}) {
for (let req of REQD_PARAMS) {
if (!opts || !util.hasValue(opts[req])) {
throw new Error(`Option '${req}' is required!`);
}
this[req] = opts[req];
}
this.jwproxy = new JWProxy({
server: this.host,
port: this.systemPort,
keepAlive: true,
});
this.proxyReqRes = this.jwproxy.proxyReqRes.bind(this.jwproxy);
}
import { logger } from 'appium-support';
const log = logger.getLogger('ADB');
export default log;
import { logger } from 'appium-support';
const log = logger.getLogger('Instruments');
export default log;
import { logger } from 'appium-support';
let log = logger.getLogger('iOS');
export default log;