How to use server.getWebSocketHandlers method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

ah1.js

Source:ah1.js Github

copy

Full Screen

...583helpers.removeAllSessionWebSocketHandlers = async function (server, sessionId) {584 if (!server || !_.isFunction(server.getWebSocketHandlers)) {585 return;586 }587 const activeHandlers = await server.getWebSocketHandlers(sessionId);588 for (const pathname of _.keys(activeHandlers)) {589 await server.removeWebSocketHandler(pathname);590 }591};592/**593 * Takes a desired capability and tries to JSON.parse it as an array,594 * and either returns the parsed array or a singleton array.595 *596 * @param {any} cap A desired capability597 */598helpers.parseArray = function (cap) {599 let parsedCaps;600 try {601 parsedCaps = JSON.parse(cap);...

Full Screen

Full Screen

android-helpers.js

Source:android-helpers.js Github

copy

Full Screen

...534helpers.removeAllSessionWebSocketHandlers = async function (server, sessionId) {535 if (!server || !_.isFunction(server.getWebSocketHandlers)) {536 return;537 }538 const activeHandlers = await server.getWebSocketHandlers(sessionId);539 for (const pathname of _.keys(activeHandlers)) {540 await server.removeWebSocketHandler(pathname);541 }542};543/**544 * Takes a desired capability and tries to JSON.parse it as an array,545 * and either returns the parsed array or a singleton array.546 *547 * @param {any} cap A desired capability548 */549helpers.parseArray = function (cap) {550 let parsedCaps;551 try {552 parsedCaps = JSON.parse(cap);...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...297async function removeAllSessionWebSocketHandlers (server, sessionId) {298 if (!server || !_.isFunction(server.getWebSocketHandlers)) {299 return;300 }301 const activeHandlers = await server.getWebSocketHandlers(sessionId);302 for (const pathname of _.keys(activeHandlers)) {303 await server.removeWebSocketHandler(pathname);304 }305}306/**307 * @typedef {Object} PlatformOpts308 *309 * @property {boolean} isSimulator - Whether the destination platform is a Simulator310 * @property {boolean} isTvOS - Whether the destination platform is a Simulator311 */312/**313 * Verify whether the given application is compatible to the314 * platform where it is going to be installed and tested.315 *...

Full Screen

Full Screen

log.js

Source:log.js Github

copy

Full Screen

...59 * as soon as they are visible to Appium.60 */61extensions.mobileStartLogsBroadcast = async function () {62 const pathname = WEBSOCKET_ENDPOINT(this.sessionId);63 if (!_.isEmpty(await this.server.getWebSocketHandlers(pathname))) {64 log.debug(`The system logs broadcasting web socket server is already listening at ${pathname}`);65 return;66 }67 log.info(`Assigning system logs broadcasting web socket server to ${pathname}`);68 // https://github.com/websockets/ws/blob/master/doc/ws.md69 const wss = new WebSocket.Server({70 noServer: true,71 });72 wss.on('connection', (ws, req) => {73 if (req) {74 const remoteIp = _.isEmpty(req.headers['x-forwarded-for'])75 ? req.connection.remoteAddress76 : req.headers['x-forwarded-for'];77 log.debug(`Established a new system logs listener web socket connection from ${remoteIp}`);78 } else {79 log.debug('Established a new system logs listener web socket connection');80 }81 if (_.isEmpty(this._syslogWebsocketListener)) {82 this._syslogWebsocketListener = (logRecord) => {83 if (ws && ws.readyState === WebSocket.OPEN) {84 ws.send(logRecord.message);85 }86 };87 }88 this.logs.syslog.on('output', this._syslogWebsocketListener);89 ws.on('close', (code, reason) => {90 if (!_.isEmpty(this._syslogWebsocketListener)) {91 this.logs.syslog.removeListener('output', this._syslogWebsocketListener);92 this._syslogWebsocketListener = null;93 }94 let closeMsg = 'System logs listener web socket is closed.';95 if (!_.isEmpty(code)) {96 closeMsg += ` Code: ${code}.`;97 }98 if (!_.isEmpty(reason)) {99 closeMsg += ` Reason: ${reason}.`;100 }101 log.debug(closeMsg);102 });103 });104 await this.server.addWebSocketHandler(pathname, wss);105};106/**107 * Stops the previously started syslog broadcasting wesocket server.108 * This method will return immediately if no server is running.109 */110extensions.mobileStopLogsBroadcast = async function () {111 const pathname = WEBSOCKET_ENDPOINT(this.sessionId);112 if (_.isEmpty(await this.server.getWebSocketHandlers(pathname))) {113 return;114 }115 log.debug('Stopping the system logs broadcasting web socket server');116 await this.server.removeWebSocketHandler(pathname);117};...

Full Screen

Full Screen

server.js

Source:server.js Github

copy

Full Screen

1import path from 'path';2import express from 'express';3import http from 'http';4import favicon from 'serve-favicon';5import bodyParser from 'body-parser';6import methodOverride from 'method-override';7import log from './logger';8import { startLogFormatter, endLogFormatter } from './express-logging';9import { allowCrossDomain, fixPythonContentType, defaultToJSONContentType,10 catchAllHandler, catch404Handler, catch4XXHandler,11 allowCrossDomainAsyncExecute} from './middleware';12import { guineaPig, guineaPigScrollable, guineaPigAppBanner, welcome, STATIC_DIR } from './static';13import { produceError, produceCrash } from './crash';14import { addWebSocketHandler, removeWebSocketHandler, removeAllWebSocketHandlers,15 getWebSocketHandlers } from './websocket';16import B from 'bluebird';17async function server (configureRoutes, port, hostname = null, allowCors = true) {18 // create the actual http server19 const app = express();20 let httpServer = http.createServer(app);21 httpServer.addWebSocketHandler = addWebSocketHandler;22 httpServer.removeWebSocketHandler = removeWebSocketHandler;23 httpServer.removeAllWebSocketHandlers = removeAllWebSocketHandlers;24 httpServer.getWebSocketHandlers = getWebSocketHandlers;25 // http.Server.close() only stops new connections, but we need to wait until26 // all connections are closed and the `close` event is emitted27 const close = httpServer.close.bind(httpServer);28 httpServer.close = async () => {29 return await new B((resolve, reject) => {30 httpServer.on('close', resolve);31 close((err) => {32 if (err) reject(err); // eslint-disable-line curly33 });34 });35 };36 return await new B((resolve, reject) => {37 httpServer.on('error', (err) => {38 if (err.code === 'EADDRNOTAVAIL') {39 log.error('Could not start REST http interface listener. ' +40 'Requested address is not available.');41 } else {42 log.error('Could not start REST http interface listener. The requested ' +43 'port may already be in use. Please make sure there is no ' +44 'other instance of this server running already.');45 }46 reject(err);47 });48 httpServer.on('connection', (socket) => {49 socket.setTimeout(600 * 1000); // 10 minute timeout50 socket.on('error', reject);51 });52 configureServer(app, configureRoutes, allowCors);53 let serverArgs = [port];54 if (hostname) {55 // If the hostname is omitted, the server will accept56 // connections on any IP address57 serverArgs.push(hostname);58 }59 httpServer.listen(...serverArgs, (err) => {60 if (err) {61 reject(err);62 }63 resolve(httpServer);64 });65 });66}67function configureServer (app, configureRoutes, allowCors = true) {68 app.use(endLogFormatter);69 // set up static assets70 app.use(favicon(path.resolve(STATIC_DIR, 'favicon.ico')));71 app.use(express.static(STATIC_DIR));72 // crash routes, for testing73 app.use('/wd/hub/produce_error', produceError);74 app.use('/wd/hub/crash', produceCrash);75 // add middlewares76 if (allowCors) {77 app.use(allowCrossDomain);78 } else {79 app.use(allowCrossDomainAsyncExecute);80 }81 app.use(fixPythonContentType);82 app.use(defaultToJSONContentType);83 app.use(bodyParser.urlencoded({extended: true}));84 app.use(methodOverride());85 app.use(catch4XXHandler);86 app.use(catchAllHandler);87 // make sure appium never fails because of a file size upload limit88 app.use(bodyParser.json({limit: '1gb'}));89 // set up start logging (which depends on bodyParser doing its thing)90 app.use(startLogFormatter);91 configureRoutes(app);92 // dynamic routes for testing, etc.93 app.all('/welcome', welcome);94 app.all('/test/guinea-pig', guineaPig);95 app.all('/test/guinea-pig-scrollable', guineaPigScrollable);96 app.all('/test/guinea-pig-app-banner', guineaPigAppBanner);97 // catch this last, so anything that falls through is 404ed98 app.use(catch404Handler);99}...

Full Screen

Full Screen

websockets-e2e-specs.js

Source:websockets-e2e-specs.js Github

copy

Full Screen

1import _ from 'lodash';2import { server, routeConfiguringFunction,3 DEFAULT_WS_PATHNAME_PREFIX } from '../..';4import { FakeDriver } from '../protocol/fake-driver';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import WebSocket from 'ws';8import B from 'bluebird';9chai.use(chaiAsPromised);10describe('Websockets (e2e)', function () {11 let baseServer;12 let driver;13 const SESSION_ID = 'foo';14 const WS_DATA = 'Hello';15 const PORT = 8181;16 before(async function () {17 driver = new FakeDriver();18 driver.sessionId = SESSION_ID;19 baseServer = await server({20 routeConfiguringFunction: routeConfiguringFunction(driver),21 port: PORT,22 });23 });24 after(async function () {25 await baseServer.close();26 });27 describe('web sockets support', function () {28 it('should be able to add websocket handler and remove it', async function () {29 const wss = new WebSocket.Server({30 noServer: true,31 });32 wss.on('connection', (ws) => {33 if (ws && ws.readyState === WebSocket.OPEN) {34 ws.send(WS_DATA);35 }36 });37 const previousListenerCount = baseServer.listenerCount('upgrade');38 const endpoint = `${DEFAULT_WS_PATHNAME_PREFIX}/hello`;39 const timeout = 5000;40 await baseServer.addWebSocketHandler(endpoint, wss);41 baseServer.listenerCount('upgrade').should.be.above(previousListenerCount);42 _.keys(await baseServer.getWebSocketHandlers()).length.should.eql(1);43 await new B((resolve, reject) => {44 const client = new WebSocket(`ws://localhost:${PORT}${endpoint}`);45 client.on('connection', (ws, req) => {46 ws.should.not.be.empty;47 req.connection.remoteAddress.should.not.be.empty;48 });49 client.on('message', (data) => {50 data.toString().should.eql(WS_DATA);51 resolve();52 });53 client.on('error', reject);54 setTimeout(() => reject(new Error('No websocket messages have been received after the timeout')),55 timeout);56 });57 (await baseServer.removeWebSocketHandler(endpoint)).should.be.true;58 _.keys(await baseServer.getWebSocketHandlers()).length.should.eql(0);59 await new B((resolve, reject) => {60 const client = new WebSocket(`ws://localhost:${PORT}${endpoint}`);61 client.on('message', (data) =>62 reject(new Error(`No websocket messages are expected after the handler ` +63 `has been removed. '${data?.toString()}' is received instead. `))64 );65 client.on('error', resolve);66 setTimeout(resolve, timeout);67 });68 baseServer.listenerCount('upgrade').should.be.above(previousListenerCount);69 });70 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumAndroidDriver = require('appium-android-driver');2var server = new AppiumAndroidDriver();3var wsHandlers = server.getWebSocketHandlers();4var AppiumIOSDriver = require('appium-ios-driver');5var server = new AppiumIOSDriver();6var wsHandlers = server.getWebSocketHandlers();7var AppiumWindowsDriver = require('appium-windows-driver');8var server = new AppiumWindowsDriver();9var wsHandlers = server.getWebSocketHandlers();10var AppiumMacDriver = require('appium-mac-driver');11var server = new AppiumMacDriver();12var wsHandlers = server.getWebSocketHandlers();13var AppiumYouiEngineDriver = require('appium-youiengine-driver');14var server = new AppiumYouiEngineDriver();15var wsHandlers = server.getWebSocketHandlers();16var AppiumTizenDriver = require('appium-tizen-driver');17var server = new AppiumTizenDriver();18var wsHandlers = server.getWebSocketHandlers();19var AppiumWebDriver = require('appium-webdriver');20var server = new AppiumWebDriver();21var wsHandlers = server.getWebSocketHandlers();22var AppiumSelendroidDriver = require('appium-selendroid-driver');23var server = new AppiumSelendroidDriver();24var wsHandlers = server.getWebSocketHandlers();25var AppiumEspressoDriver = require('appium-espresso-driver');26var server = new AppiumEspressoDriver();27var wsHandlers = server.getWebSocketHandlers();28var AppiumXCUITestDriver = require('appium-xcuitest-driver');29var server = new AppiumXCUITestDriver();30var wsHandlers = server.getWebSocketHandlers();

Full Screen

Using AI Code Generation

copy

Full Screen

1var appiumAndroidDriver = require('appium-android-driver');2var server = new appiumAndroidDriver.AppiumServer();3var webSocketHandlers = server.getWebSocketHandlers();4console.log(webSocketHandlers);5var appiumIOSDriver = require('appium-ios-driver');6var server = new appiumIOSDriver.AppiumServer();7var webSocketHandlers = server.getWebSocketHandlers();8console.log(webSocketHandlers);9var appiumWindowsDriver = require('appium-windows-driver');10var server = new appiumWindowsDriver.AppiumServer();11var webSocketHandlers = server.getWebSocketHandlers();12console.log(webSocketHandlers);13var appiumMacDriver = require('appium-mac-driver');14var server = new appiumMacDriver.AppiumServer();15var webSocketHandlers = server.getWebSocketHandlers();16console.log(webSocketHandlers);17var appiumYouiEngineDriver = require('appium-youiengine-driver');18var server = new appiumYouiEngineDriver.AppiumServer();19var webSocketHandlers = server.getWebSocketHandlers();20console.log(webSocketHandlers);21var appiumTizenDriver = require('appium-tizen-driver');22var server = new appiumTizenDriver.AppiumServer();23var webSocketHandlers = server.getWebSocketHandlers();24console.log(webSocketHandlers);25var appiumFireFoxOSDriver = require('appium-firefoxos-driver');26var server = new appiumFireFoxOSDriver.AppiumServer();27var webSocketHandlers = server.getWebSocketHandlers();28console.log(webSocketHandlers);

Full Screen

Using AI Code Generation

copy

Full Screen

1const appium = require('appium');2const { AndroidDriver } = require('appium-android-driver');3const { Server } = appium;4const server = new Server();5const driver = new AndroidDriver();6const wsHandlers = driver.getWebSocketHandlers();7server.attachWebSocketHandler('/myHandler', wsHandlers);8server.start();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5var expect = chai.expect;6var assert = chai.assert;7var should = chai.should();8var server = require('appium-android-driver').server;9var handlers = server.getWebSocketHandlers();10console.log(handlers);11var wd = require('wd');12var chai = require('chai');13var chaiAsPromised = require('chai-as-promised');14chai.use(chaiAsPromised);15var expect = chai.expect;16var assert = chai.assert;17var should = chai.should();18var server = require('appium-android-driver').server;19var handlers = server.getWebSocketHandlers();20console.log(handlers);21var wd = require('wd');22var chai = require('chai');23var chaiAsPromised = require('chai-as-promised');24chai.use(chaiAsPromised);25var expect = chai.expect;26var assert = chai.assert;27var should = chai.should();28var server = require('appium-android-driver').server;29var handlers = server.getWebSocketHandlers();30console.log(handlers);31var wd = require('wd');32var chai = require('chai');33var chaiAsPromised = require('chai-as-promised');34chai.use(chaiAsPromised);35var expect = chai.expect;36var assert = chai.assert;37var should = chai.should();38var server = require('appium-android-driver').server;39var handlers = server.getWebSocketHandlers();40console.log(handlers);41var wd = require('wd');42var chai = require('chai');43var chaiAsPromised = require('chai-as-promised');44chai.use(chaiAsPromised);45var expect = chai.expect;46var assert = chai.assert;47var should = chai.should();48var server = require('appium-android

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var _ = require('underscore');4var path = require('path');5var server = require('appium').server;6var appium = server.main;7var port = 4723;8var driver = wd.remote('localhost', port);9var desiredCaps = {10 app: path.resolve(__dirname, 'app-debug.apk'),11};12appium.set('port', port);13appium.set('appium-version', '1.0.0');14appium.set('log-level', 'debug');15appium.set('log-timestamp', true);16appium.set('local-timezone', true);17appium.set('log-no-colors', true);18appium.set('log', 'appium.log');19appium.set('tmp', '/tmp/appium');20appium.set('base-path', '/wd/hub');21appium.listen(port, function() {22 console.log('Appium started on port ' + port);23 driver.init(desiredCaps, function(err) {24 if (err) {25 console.log(err);26 } else {27 console.log('Appium started on port ' + port);28 var handlers = driver.getWebSocketHandlers();29 console.log(handlers);30 driver.quit();31 }32 });33});34I am trying to use the method getWebSocketHandlers() of Appium Android Driver which returns a map of websocket handlers. But I am getting error as handlers is undefined. I am using appium 1.2.0 and Node.js 0.10.25. I am using the code given in the link

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful