Best JavaScript code snippet using appium-xcuitest-driver
ah1.js
Source:ah1.js
...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);602 } catch (ign) { }603 if (_.isArray(parsedCaps)) {...
android-helpers.js
Source:android-helpers.js
...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);553 } catch (ign) { }554 if (_.isArray(parsedCaps)) {...
utils.js
Source:utils.js
...327 return;328 }329 const activeHandlers = await server.getWebSocketHandlers(sessionId);330 for (const pathname of _.keys(activeHandlers)) {331 await server.removeWebSocketHandler(pathname);332 }333}334/**335 * Returns true if the urlString is localhost336 * @param {?string} urlString337 * @returns {boolean} Return true if the urlString is localhost338 */339function isLocalHost (urlString) {340 try {341 const {hostname} = url.parse(urlString);342 return ['localhost', '127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(hostname);343 } catch (ign) {344 log.warn(`'${urlString}' cannot be parsed as a valid URL`);345 }...
log.js
Source:log.js
...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};...
server.js
Source:server.js
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}...
websockets-e2e-specs.js
Source:websockets-e2e-specs.js
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 });...
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const expect = chai.expect;6const PORT = 4723;7const HOST = 'localhost';8const config = {9};10describe('XCUITestDriver - server.removeWebSocketHandler', function () {11 let driver;12 before(async function () {13 driver = await wd.promiseChainRemote(URL);14 await driver.init(config);15 });16 after(async function () {17 await driver.quit();18 });19 it('should remove the websocket handler', async function () {20 await driver.execute('mobile: removeWebSocketHandler', {route: '/wd/hub/session/:sessionId'});21 });22});23const wd = require('wd');24const chai = require('chai');25const chaiAsPromised = require('chai-as-promised');26chai.use(chaiAsPromised);27const expect = chai.expect;28const PORT = 4723;29const HOST = 'localhost';30const config = {31};32describe('XCUITestDriver - server.removeWebSocketHandler', function () {33 let driver;34 before(async function () {35 driver = await wd.promiseChainRemote(URL);36 await driver.init(config);37 });38 after(async function () {39 await driver.quit();40 });41 it('should remove the websocket handler', async function () {42 await driver.execute('mobile: removeWebSocketHandler', {route: '/wd/hub/session/:sessionId'});43 });44});
Using AI Code Generation
1const Appium = require('appium');2const appium = new Appium();3const { XCUITestDriver } = require('appium-xcuitest-driver');4const { server } = require('appium-base-driver');5const driver = new XCUITestDriver();6const host = 'localhost';7const port = 4723;8(async function main() {9 await appium.startServer({10 });11 await driver.createSession({12 });13 await server.removeWebSocketHandler('/wd/hub/session/4d2c2a2a-0c8f-4e9e-8c7b-0f8e8a7a8d3a/screenshot');14 await driver.deleteSession();15 await appium.stopServer();16}());17const commands = {}, helpers = {}, extensions = {};18commands.getScreenshot = async function getScreenshot () {19 const {width, height} = await this.getWindowSize();20 const screenshot = await this.proxyCommand('/screenshot', 'GET');21 const base64ScreenshotData = screenshot.value;22 const imgData = Buffer.from(base64ScreenshotData, 'base64');23 const image = await this.jimp.read(imgData);24 const imgWidth = image.bitmap.width;25 const imgHeight = image.bitmap.height;26 const aspectRatio = imgWidth / imgHeight;27 const scaledWidth = width * aspectRatio;28 const scaledHeight = height / aspectRatio;29 {width, height: scaledHeight} :30 {width: scaledWidth, height};31 image.scaleToFit(scaledSize.width, scaledSize.height);32 image.crop(0, 0, width, height);33 const base64Screenshot = await image.getBase64Async('image/png');
Using AI Code Generation
1const webdriverio = require('webdriverio');2const assert = require('assert');3const opts = {4 capabilities: {5 },6};7(async () => {8 const client = await webdriverio.remote(opts);9 const title = await client.getTitle();10 console.log('Title was: ' + title);11 await client.removeWebSocketHandler('receive_message');12 await client.deleteSession();13})();14const webdriverio = require('webdriverio');15const assert = require('assert');16const opts = {17 capabilities: {18 },19};20(async () => {21 const client = await webdriverio.remote(opts);22 const title = await client.getTitle();23 console.log('Title was: ' + title);24 await client.removeWebSocketHandler('receive_message');25 await client.deleteSession();26})();27const webdriverio = require('webdriverio');28const assert = require('assert');29const opts = {30 capabilities: {31 },32};33(async () => {34 const client = await webdriverio.remote(opts);35 const title = await client.getTitle();36 console.log('Title was: ' + title);
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .then(function() {9 return client.removeWebSocketHandler('path');10 })11 .end();12Syntax: getLogTypes()13var webdriverio = require('webdriverio');14var options = {15 desiredCapabilities: {16 }17};18var client = webdriverio.remote(options);19 .init()20 .then(function() {21 return client.getLogTypes();22 })23 .end();24Syntax: getLog(logType)25var webdriverio = require('webdriverio');26var options = {27 desiredCapabilities: {
Using AI Code Generation
1const wd = require('wd');2const {execSync} = require('child_process');3const {server} = require('appium-xcuitest-driver');4const PORT = 4723;5const HOST = 'localhost';6const driver = wd.promiseChainRemote(HOST, PORT);7const caps = {8};9async function main () {10 await driver.init(caps);11 await server.removeWebSocketHandler(driver.sessionID);12 await driver.get('h
Using AI Code Generation
1const AppiumXCUITestDriver = require('appium-xcuitest-driver');2const server = new AppiumXCUITestDriver();3appium -p 4723 --default-capabilities '{"platformName":"iOS","platformVersion":"11.2","deviceName":"iPhone 8"}' --log-level info4const AppiumXCUITestDriver = require('appium-xcuitest-driver');5const server = new AppiumXCUITestDriver();6server.removeWebSocketHandler('test');7const AppiumXCUITestDriver = require('appium-xcuitest-driver');8const server = new AppiumXCUITestDriver();9server.removeWebSocketHandler('test
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!