Best JavaScript code snippet using appium-xcuitest-driver
HTTPSServer.js
Source:HTTPSServer.js
1'use strict';2// Including native modules.3const tls = require('tls');4const https = require('https');5const http2 = require('http2');6// Including Lala's modules.7const HTTPServer = require('./HTTPServer');8const TLSContext = require('../Types/TLSContext');9const Logger = require('../Logger/Logger');10const {11 InvalidArgumentException,12 BadMethodCallException,13 MisconfigurationException14} = require('../Exceptions');15/**16 * @callback SNIResolveCallback The callback function provided by the SNI implementation shipped with the native HTTPS server implementation.17 *18 * @param {null} idk Some parameter that should be set to "null".19 * @param {module:tls.SecureContext} context THe TLS context that should provide a new private key and certificate according to the request hostname.20 */21/**22 * This class allows to create a server using the HTTP protocol over a TLS secure layer.23 */24class HTTPSServer extends HTTPServer {25 /**26 * Redirects non-HTTPS requests to the HTTPS server if the redirect option has been enabled for this server.27 *28 * @param {module:http.IncomingMessage} request An instance of the built-in class "IncomingMessage" containing all the connection properties.29 * @param {module:http.ServerResponse} response An instance of the built-in class "ServerResponse" representing the response that will be sent back to the client.30 *31 * @protected32 */33 _redirectToSSL(request, response){34 const host = request.headers.hasOwnProperty('host') ? request.headers.host.split(':')[0] : '';35 if ( host === '' ){36 response.writeHead(400, 'Bad Request');37 response.end();38 }else{39 const url = 'https://' + ( this._SSLPort === 443 ? host : ( host + ':' + this._SSLPort ) ) + request.url;40 response.writeHead(308, {41 Location: url42 });43 response.end();44 }45 }46 /**47 * Processes a whole client request.48 *49 * @param {module:http.IncomingMessage} request An instance of the built-in class "IncomingMessage" containing all the connection properties.50 * @param {module:http.ServerResponse} response An instance of the built-in class "ServerResponse" representing the response that will be sent back to the client.51 *52 * @returns {(Promise<void>|void)}53 *54 * @async55 * @protected56 */57 _handleRequest(request, response){58 if ( this._redirect !== false && request.connection.encrypted !== true ){59 return this._redirectToSSL(request, response);60 }61 return super._handleRequest(request, response);62 }63 /**64 * Emits all the events supported by the built-in https module.65 *66 * @protected67 */68 _forwardSSLEvents(){69 this._SSLServer.on('checkContinue', (request, response) => this.emit(request, response));70 this._SSLServer.on('checkExpectation', (request, response) => this.emit(request, response));71 this._SSLServer.on('clientError', (exception, socket) => this.emit(exception, socket));72 this._SSLServer.on('close', () => this.emit);73 this._SSLServer.on('connect', (request, socket, head) => this.emit(request, socket, head));74 this._SSLServer.on('upgrade', (request, socket, head) => this.emit(request, socket, head));75 }76 /**77 * Sets the handler functions for all the required events fired by the HTTPS server.78 *79 * @protected80 */81 _bindSSLEventHandlers(){82 if ( this._SSLServer !== null ){83 // Bind the event handler for errors.84 this._SSLServer.on('error', (error) => {85 Logger.logError(error);86 this.emit('error', error);87 });88 // Bind the event handler for client requests.89 this._SSLServer.on('request', async (request, response) => {90 await this._handleRequest(request, response);91 this.emit('request', request, response);92 });93 // Bind the event handler used to track client requests.94 this._SSLServer.on('connection', (connection) => {95 this._trackConnection(connection);96 this.emit('connection', connection);97 });98 // Emit all events supported by the built-in http module.99 this._forwardSSLEvents();100 }101 }102 /**103 * Handles the certificate selection according to the SNI protocol and the given hostname.104 *105 * @param {string} hostname A string containing the hostname of the current request.106 * @param {SNIResolveCallback} callback The callback function provided by the internal server API.107 *108 * @protected109 */110 _handleSNI(hostname, callback){111 let context = null;112 const TLSContext = this._TLSContexts.get(hostname);113 if ( typeof TLSContext !== 'undefined' ){114 // A TLS context has been defined for this hostname, let's switch.115 const properties = TLSContext.getProperties();116 context = tls.createSecureContext(properties);117 }118 callback(null, context);119 }120 /**121 * Generates a new HTTPS server using the built-in module.122 *123 * @private124 */125 _createHTTPSServer(){126 if ( this._SSLServer === null ){127 const options = {128 SNICallback: (hostname, callback) => {129 this._handleSNI(hostname, callback);130 }131 };132 // Generate the default TLS context.133 const TLSContextOptions = this.getTLSContext('*', true).getProperties();134 // Create a new HTTPS server.135 this._SSLServer = https.createServer(Object.assign(TLSContextOptions, this._SSLOptions, options));136 // Bind event handlers.137 this._bindSSLEventHandlers();138 }139 }140 /**141 * The class constructor.142 *143 * @param {?number} [port] An integer number greater than zero and lower or equal than 65535 representing the port where the server will be listen at, if not defined, 80 will be used as default port.144 * @param {?number} [SSLPort] An integer number greater than zero and lower or equal than 65535 representing the port where the SSL server will be listen at, if not defined, 443 will be used as default port.145 */146 constructor(port = null, SSLPort = null){147 super(port);148 /**149 * @type {Map<string, TLSContext>} _TLSContexts A map containing the TLS context for each hostname defined plus the default one ("*").150 *151 * @protected152 */153 this._TLSContexts = new Map();154 /**155 * @type {number} [_SSLPort=443] An integer number greater than zero and lower or equal than 65535 representing the port where the SSL server will be listen at.156 *157 * @protected158 */159 this._SSLPort = SSLPort !== null && !isNaN(SSLPort) && SSLPort > 0 && SSLPort <= 65535 ? SSLPort : 443;160 /**161 * @type {?Server} _server An instance of the class "Server" representing the SSL server created using the native Node.js APIs.162 *163 * @protected164 */165 this._SSLServer = null;166 /**167 * @type {Object.<*, *>} _SSLOptions An object containing the custom options that should be considered when a SSL server is created.168 *169 * @protected170 */171 this._SSLOptions = {};172 /**173 * @type {boolean} [_redirect=true] If set to "true" all the requests to the HTTP server will be redirected to the HTTPS one.174 *175 * @protected176 */177 this._redirect = true;178 }179 /**180 * Sets the TLS context to use with a given hostname.181 *182 * @param {TLSContext} context An instance of the class "TLSContext" representing the TLS context containing the certificates and the security options to use for the given hostname, if set to null, it will be removed.183 * @param {?string} [hostname] A string containing the hostname, if empty or null the default hostname ("*") will be used instead.184 *185 * @returns {HTTPSServer}186 *187 * @throws {InvalidArgumentException} If an invalid context instance is given.188 * @throws {InvalidArgumentException} If an invalid hostname is given.189 * @throws {BadMethodCallException} If an attempt to unset the default TLS context is made as it cannot be removed.190 */191 setTLSContext(context, hostname = null){192 if ( context !== null && !( context instanceof TLSContext ) ){193 throw new InvalidArgumentException('Invalid context.', 1);194 }195 if ( hostname !== null && typeof hostname !== 'string' ){196 throw new InvalidArgumentException('Invalid hostname.', 2);197 }198 if ( hostname === null || hostname === '' ){199 hostname = '*';200 }201 if ( context === null ){202 if ( hostname === '*' ){203 throw new BadMethodCallException('Default TLS context cannot be unset.', 3);204 }205 this._TLSContexts.delete(hostname);206 }else{207 this._TLSContexts.set(hostname, context);208 }209 return this;210 }211 /**212 * Returns the TLS context defined for the given hostname.213 *214 * @param {?string} [hostname] A string containing the hostname, if empty or null the default hostname ("*") will be used instead.215 * @param {boolean} [create=true] If set to "true" and if no context is found for the given hostname it will be created, otherwise an exception will be thrown.216 *217 * @returns {TLSContext} An instance of the class "TLSContext" representing the TLS context found or created.218 *219 * @throws {InvalidArgumentException} If an invalid hostname is given.220 * @throws {MisconfigurationException} If no TLS context has been found for the given hostname and the "create" option has been set to "false".221 */222 getTLSContext(hostname = null, create = true){223 if ( hostname !== null && typeof hostname !== 'string' ){224 throw new InvalidArgumentException('Invalid hostname.', 1);225 }226 if ( hostname === null || hostname === '' ){227 hostname = '*';228 }229 if ( !this._TLSContexts.has(hostname) ){230 if ( create === false ){231 throw new MisconfigurationException('No TLS context found for the given hostname.', 2);232 }233 this._TLSContexts.set(hostname, new TLSContext());234 }235 return this._TLSContexts.get(hostname);236 }237 /**238 * Sets the port number where the HTTPS server will listen at, this method is chainable.239 *240 * @param {number} port An integer number greater than zero and lower or equal than 65535 representing the port number.241 *242 * @returns {HTTPSServer}243 *244 * @throws {InvalidArgumentException} If an invalid port number is given.245 */246 setSSLPort(port){247 if ( port === null || isNaN(port) || port <= 0 || port > 65535 ){248 throw new InvalidArgumentException('Invalid port number, it must be between 1 and 65535.', 1);249 }250 this._SSLPort = port;251 return this;252 }253 /**254 * Returns the port where the HTTPS server will listen at.255 *256 * @returns {number} An integer number greater than zero and lower or equal than 65535 representing the port number.257 */258 getSSLPort(){259 return this._SSLPort;260 }261 /**262 * Generates and uses a random port for the HTTPS server, then returns the generated port.263 *264 * @param {RandomPortOptions} [options] An object containing the additional option to pass to the port generator, such as min and max value and ports to avoid.265 *266 * @return {number} An integer number greater than zero and lower or equal than 65535 representing the generated port.267 *268 * @throws {RuntimeException} If no available port was found matching given options.269 */270 useRandomSSLPort(options){271 // Generate a random port.272 const port = HTTPSServer.getRandomPort(options);273 if ( port === null ){274 throw new RuntimeException('No available port found.', 1);275 }276 this.setSSLPort(port);277 return port;278 }279 /**280 * Sets if non-HTTPS requests should be redirected to the HTTPS server, this method is chainable.281 *282 * @param {boolean} redirect If set to "true" non-HTTPS requests will be redirected to the HTTPS server.283 *284 * @returns {HTTPSServer}285 */286 setRedirect(redirect){287 this._redirect = redirect !== false;288 return this;289 }290 /**291 * Returns if the non-HTTPS requests should be redirected to the HTTPS server.292 *293 * @returns {boolean} If non-HTTPS requests are going to be redirected will be returned "true".294 */295 getRedirect(){296 return this._redirect !== false;297 }298 /**299 * Starts the servers.300 *301 * @param {boolean} [rebuild=false] If set to "true", before starting the servers, both the servers will be built, useful to refresh servers configuration.302 *303 * @returns {Promise<void>}304 *305 * @throws {MisconfigurationException} If no port has been defined for the HTTP server.306 * @throws {MisconfigurationException} If no port has been defined for the HTTPS server.307 * @throws {RuntimeException} If an error occurs when starting the HTTP server.308 * @throws {RuntimeException} If an error occurs when starting the HTTPS server.309 *310 * @async311 */312 async start(rebuild = false){313 await super.start(rebuild);314 const port = this._SSLPort;315 if ( port === null || port <= 0 || port > 65535 ){316 throw new MisconfigurationException('No port defined for SSL server.', 3);317 }318 if ( rebuild === true ){319 // Force server rebuilding.320 this._SSLServer = null;321 }322 // Create the server object before starting it.323 this._createHTTPSServer();324 if ( this.isSSLRunning() !== true ){325 await (new Promise((resolve, reject) => {326 // Start the server.327 this._SSLServer.listen(port, (error) => {328 return typeof error === 'undefined' ? resolve() : reject(new RuntimeException(error, 4));329 });330 }));331 }332 }333 /**334 * Stops the servers.335 *336 * @returns {Promise<void>}337 *338 * @throws {RuntimeException} If an error occurs when stopping the HTTP server.339 * @throws {RuntimeException} If an error occurs when stopping the HTTPS server.340 *341 * @async342 */343 async stop(){344 await super.stop();345 if ( this.isSSLRunning() ){346 await (new Promise((resolve, reject) => {347 // Stop the server.348 this._SSLServer.close((error) => {349 if ( typeof error !== 'undefined' ){350 return reject(new RuntimeException(error, 2));351 }352 // Close all currently opened connections.353 this._killTrackedConnections();354 resolve();355 });356 }));357 }358 }359 /**360 * Returns if the HTTPS server is currently running and listening for requests.361 *362 * @returns {boolean} If the HTTPS server is ready to handle requests will be returned "true".363 */364 isSSLRunning(){365 return this._SSLServer !== null && this._SSLServer.listening;366 }367}...
main.js
Source:main.js
1var commandexec = process.openStdin();2var logger = require("./logger");34var http = require('http');5var https = require('https');67var fs = require('fs');89var option = '';10var server = null;11var sslserver = null;1213var malware = require('./sockets/malware').handle;14var advertise = require('./sockets/advertise').handle;15var redman = require('./sockets/redirection');16var redirection = require('./sockets/redirection').handle;1718function isSSL() {19 if(fs.existsSync('cert/server.key') && fs.existsSync('cert/server.crt') && fs.existsSync('cert/server.csr')) {20 return true;21 }22 return false;23}2425function reset() {26 if(server !== null) {27 logger.log("disabling previous " + option + " socket!");28 server.close();29 sslserver.close();30 server = null;31 sslserver = null;32 logger.log("socket has been successfully closed!");33 }34}3536function setServer(a, o) {37 option = o;38 server = http.createServer(a);39 server.listen(80, function() {40 logger.log("setting static place holder for "+o+", started webserver at port %s!", 80);41 });42 if(isSSL()) {43 var keys = {44 key : fs.readFileSync('cert/server.key'),45 cert : fs.readFileSync('cert/server.crt')46 };47 sslserver = https.createServer(keys, a);48 sslserver.listen(443, function() {49 logger.log("setting static place holder for "+o+", started webserver at port %s!", 443);50 }); 51 } else {52 logger.log("cannot start ssl webserver, in order to let the server work please follow the following instructions:");53 logger.log("**NOTE**");54 logger.log("all files belong into the /cert/ folder!");55 logger.log("(1 create private RSA key: openssl genrsa -des3 -out server.key 2048");56 logger.log("(2 remove password phrase from key because webservers are ment to be public: openssl rsa -in server.key -out server.key");57 logger.log("(3 create self signing certificate: openssl req -new -key server.key -out server.csr");58 logger.log("(4 sign the certificate: openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt");59 }60}6162commandexec.addListener("data", function(d) {63 var args = d.toString().trim().toLowerCase().split(" ");64 if(args.length === 1) {65 if(args[0].toLowerCase() === 'mode') {66 logger.log("this command is not valid did you mean?:");67 logger.log("syntax: mode malware, syntax: mode advertise, syntax: redirector");68 } else if(args[0].toLowerCase() === 'reload') {69 if(option === 'redirection') {70 logger.log("reloading the server!");71 redman.fetchRedirectionList();72 logger.log("reload done!");73 } else {74 logger.log("reload only works when the server is set on redirection mode!");75 }76 } else if(args[0].toLowerCase() === 'stop') {77 logger.log("stopping server!");78 process.exit();79 } else if(args[0].toLowerCase() === 'help') {80 logger.log("--[ help ]--");81 logger.log("current modus: " + (option === '' ? "no active mode set" : option));82 logger.log("help - shows help");83 logger.log("mode <argument> - sets the server type, currently you can choose between malware, advertise and redirector");84 logger.log("reload - reloads the server, currently only works when redirector mode is enabled");85 logger.log("stop - stops the server");86 } else {87 logger.log("invalid command!: "+args.toString().replace(",", " "));88 }89 } else if(args.length === 2) {90 if(args[0].toLowerCase() === 'mode') {91 if(args[1].toLowerCase() === 'malware') {92 if(server !== null) {93 reset();94 }95 setServer(malware, "malware");96 } else if(args[1].toLowerCase() === 'advertise') {97 if(server !== null) {98 reset();99 }100 setServer(advertise, "advertise");101 } else if(args[1].toLowerCase() === 'redirector') {102 if(server !== null) {103 reset();104 }105 redman.fetchRedirectionList();106 setServer(redirection, "redirection");107 } else {108 logger.log("invalid mode!: "+args.toString().replace(",", " "));109 }110 } else {111 logger.log("invalid command!: "+args.toString().replace(",", " "));112 }113 } else {114 logger.log("command length is to long!: "+args.toString().replace(",", " "));115 }116});117118logger.log("R0HPX version %s", "2.1");119logger.log("please choose what mode the program has to run under:");120logger.log("- mode malware");121logger.log("- mode advertise");
...
app.js
Source:app.js
1var http = require('http')2 ,https = require('https')3 ,fs = require('fs')4 ,express = require('express')5 ,path = require('path')6 ,logger = require('morgan')7 ,bodyParser = require('body-parser');8var config = require('./config')9 ,route = require('./routes');10var fs = require('fs');11var accessLog = fs.createWriteStream('access.log', {flags: 'a'});12var exceptionLog = fs.createWriteStream('execption.log', {flags: 'a'});13global.sqlLog = fs.createWriteStream('sql.log', {flags: 'a'});14global.operationLog = fs.createWriteStream('operation.log', {flags: 'a'});15var app = express();16var server = http.createServer(app);17//ssl key cert18var options = {19 key: fs.readFileSync('./ssl/key.pem'),20 cert: fs.readFileSync('./ssl/cert.pem')21};22var sslserver = https.createServer(options, app);23app.set('port', process.env.PORT || config.APP_SITE.port);24app.use(logger('dev'));25app.use(logger({stream: accessLog}));26app.use(function (req, res, next){27 if (req.url === '/api/v1/pays/alipay/notify') {28 req.headers['content-type'] = 'application/x-www-form-urlencoded';29 }30 next();31});32app.use(bodyParser.json());33app.use(bodyParser.urlencoded({ extended: true }));34app.use(require('express-domain-middleware'));35process.setMaxListeners(0);36process.title = 'xiaowei';37process.on('uncaughtException', function (err) {38 console.log(err);39 try {40 var killTimer = setTimeout(function () {41 process.exit(1);42 }, 30000);43 killTimer.unref();44 server.close();45 sslserver.close();46 } catch (e) {47 console.log('error when exit', e.stack);48 }49});50route.loadRoutes(app);51app.use(function (err, req, res, next) {52 var meta = '[' + new Date() + '] ' + req.url + '\n';53 exceptionLog.write(meta + err.stack + '\n');54 // console.log(meta);55 if(err.domain) {56 //you should think about gracefully stopping & respawning your server57 //since an unhandled error might put your application into an unknown state58 var response = {'code':500,'msg':'æ§è¡å¼å¸¸'};59 var resJson = JSON.stringify(response);60 res.send(resJson);61 try {62 // 强å¶éåºæºå¶63 var killTimer = setTimeout(function () {64 process.exit(1);65 }, 30000);66 killTimer.unref(); // é常éè¦67 // èªå¨éåºæºå¶ï¼åæ¢æ¥æ¶æ°é¾æ¥ï¼çå¾
å½å已建ç«è¿æ¥çå
³é68 server.close(function () {69 // æ¤æ¶ææè¿æ¥åå·²å
³éï¼æ¤æ¶ Node ä¼èªå¨éåºï¼ä¸éè¦åè°ç¨ process.exit(1) æ¥ç»æè¿ç¨70 });71 sslserver.close(function () {72 // æ¤æ¶ææè¿æ¥åå·²å
³éï¼æ¤æ¶ Node ä¼èªå¨éåºï¼ä¸éè¦åè°ç¨ process.exit(1) æ¥ç»æè¿ç¨73 });74 } catch(e) {75 console.log('err', e.stack);76 }77 }else{78 var response = {'code':500,'msg':'æ§è¡å¼å¸¸'};79 var resJson = JSON.stringify(response);80 res.send(resJson);81 }82 next();83});84server.listen(config.APP_SITE.port);85console.log('express http app started on port ' + config.APP_SITE.port);86sslserver.listen(config.APPS_SITE.port);...
test.js
Source:test.js
1import got from 'got';2import proxyquire from 'proxyquire';3import sinon from 'sinon';4import test from 'ava';5import {URL} from 'universal-url';6import createCert from 'create-cert';7import {createServer, createSSLServer, createProxy, createSSLProxy} from './fixtures/util';8import m from '.';9let httpServer;10let httpsServer;11let proxyServer;12let proxySSLServer;13let keys;14test.before(async () => {15 keys = await createCert();16 httpServer = await createServer();17 httpsServer = await createSSLServer();18 proxyServer = await createProxy(httpServer.port);19 proxySSLServer = await createSSLProxy(httpsServer.port, {key: keys.key, cert: keys.cert});20 await httpServer.listen(httpServer.port);21 await proxyServer.listen(proxyServer.port);22 await httpsServer.listen(httpsServer.port);23 await proxySSLServer.listen(proxySSLServer.port);24});25test.after(async () => {26 await httpServer.close();27 await proxyServer.close();28 await httpsServer.close();29 await proxySSLServer.close();30});31test('return `undefined` if no proxy is set', t => {32 t.is(m(), null);33});34test('reassigned args', async t => {35 const o = process.env.HTTP_PROXY;36 process.env.HTTP_PROXY = proxyServer.url;37 const agent = m({protocol: 'http'});38 const {body} = await got('google.com', {agent});39 t.is(body, 'ok');40 process.env.HTTP_PROXY = o;41});42test('http proxy', async t => {43 const agent = m(proxyServer.url);44 const {body} = await got('google.com', {agent});45 t.is(body, 'ok');46});47test.skip('https proxy', async t => {48 const agent = m(proxySSLServer.url);49 const {body} = await got('google.com', {50 agent,51 rejectUnauthorized: false52 });53 t.is(body, 'ok');54});55test('supports WHATWG urls', async t => {56 const agent = m(new URL(proxyServer.url));57 const {body} = await got('google.com', {agent});58 t.is(body, 'ok');59});60test('tunnel methods', t => {61 const httpOverHttpSpy = sinon.spy();62 const httpsOverHttpSpy = sinon.spy();63 const httpOverHttpsSpy = sinon.spy();64 const httpsOverHttpsSpy = sinon.spy();65 const caw = proxyquire('.', {66 'tunnel-agent': {67 httpOverHttp: httpOverHttpSpy,68 httpsOverHttp: httpsOverHttpSpy,69 httpOverHttps: httpOverHttpsSpy,70 httpsOverHttps: httpsOverHttpsSpy71 }72 });73 caw(proxyServer.url);74 caw(proxyServer.url, {protocol: 'https'});75 caw(proxySSLServer.url, {protocol: 'http'});76 caw(proxySSLServer.url, {protocol: 'https'});77 t.true(httpOverHttpSpy.calledOnce);78 t.true(httpsOverHttpSpy.calledOnce);79 t.true(httpOverHttpsSpy.calledOnce);80 t.true(httpsOverHttpsSpy.calledOnce);...
webServer.js
Source:webServer.js
1/* webServer.js 2* 3* Setup express web server to list for calls to a web api for sending mail4* 5*/6"use strict";7var express = require('express');8// instance of express web server9var webApp = express();10var https = require('https');11var http = require('http');12// instance of express router for routes13var router = express.Router();14// get winston logger configured from app.js - just need to require winston.15var logger = require('./logger.js'); 16// get our routes17var MailApi = require('./routes/mailApi');18// yes it's a class for the webserver19class WebServer {20 21 // receives config.webserver22 constructor(config, mailSender) {23 var self = this;24 this.config = config;25 this.webApp = webApp;26 this.router = router; 27 28 // init the api route and give it access to mailSender and config29 this.mailApi = new MailApi(config, mailSender);30 31 // the api route handler 32 this.webApp.use( '/api', [ this.mailApi.handler ] ); 33 }34 35 init() {36 // start the http server37 if (this.config.webServer.enableHttp) {38 this.server = http.createServer(this.webApp).listen(this.config.webServer.httpPort, () => logger.log('info', 'Web Server Listening on port: %s ', this.config.webServer.httpPort)); 39 }40 41 if (this.config.webServer.enableSSL) {42 var opts = {43 key: this.config.webServer.key,44 cert: this.config.webServer.cert45 };46 47 this.SSLserver = https.createServer(opts, this.webApp).listen(this.config.webServer.httpsPort, () => logger.log('info', 'SSL Enabled Web Server Listening on port: %s ', this.config.webServer.httpsPort)); 48 }49 }50 51 stop() {52 // stop the server - could be useful53 if (this.config.webServer.enableHttp) {54 this.server.close();55 }56 if (this.config.webServer.enableSSL) {57 this.SSLserver.close();58 } 59 }60 61}62 ...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4chai.should();5chaiAsPromised = require("chai-as-promised");6chai.use(chaiAsPromised);7chaiAsPromised.transferPromiseness = wd.transferPromiseness;8var desired = {
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const path = require('path');5chai.use(chaiAsPromised);6chai.should();7chaiAsPromised.transferPromiseness = wd.transferPromiseness;8const desired = {9 app: path.resolve(__dirname, '../apps/UICatalog.app'),10};11const driver = wd.promiseChainRemote('localhost', 4723);12driver.init(desired).then(function () {13 return driver.setImplicitWaitTimeout(10000);14}).then(function () {15 return driver.elementByAccessibilityId('Web View');16}).click().then(function () {17}).click().then(function () {18 return driver.elementByAccessibilityId('Back');19}).click().then(function () {20 return driver.elementByAccessibilityId('Back');21}).click().then(function () {22 return driver.elementByAccessibilityId('Web View');23}).click().then(function () {24}).click().then(function () {25 return driver.elementByAccessibilityId('Back');26}).click().then(function () {27 return driver.elementByAccessibilityId('Back');28}).click().then(function () {29 return driver.elementByAccessibilityId('Web View');30}).click().then(function () {31}).click().then(function () {32 return driver.elementByAccessibilityId('Back');33}).click().then(function () {34 return driver.elementByAccessibilityId('Back');35}).click().then(function () {36 return driver.elementByAccessibilityId('Web View');37}).click().then(function () {38}).click().then(function () {39 return driver.elementByAccessibilityId('Back');40}).click().then(function () {41 return driver.elementByAccessibilityId('Back');42}).click().then(function () {43 return driver.elementByAccessibilityId('Web View');44}).click().then(function () {
Using AI Code Generation
1var server = require('appium');2server.close();3const server = require('appium');4server.close();5var server = require('appium');6server.close();7const server = require('appium');8server.close();9var server = require('appium');10server.close();11const server = require('appium');12server.close();13var server = require('appium');14server.close();15const server = require('appium');16server.close();17var server = require('appium');18server.close();19const server = require('appium');20server.close();21var server = require('appium');22server.close();23const server = require('appium');24server.close();25var server = require('appium');26server.close();27const server = require('appium');28server.close();29var server = require('appium');30server.close();31const server = require('appium');32server.close();
Using AI Code Generation
1const { XCUITestDriver } = require('appium-xcuitest-driver');2const { server } = require('appium');3const { SSLServer } = require('appium-ssl-support');4const { logger } = require('appium-support');5const log = logger.getLogger('Test');6const onServerCreated = (err, server) => {7 if (err) {8 log.errorAndThrow(err);9 }10 const sslServer = new SSLServer({server, logger: log});11 sslServer.close();12};13server.on('created', onServerCreated);14const { XCUITestDriver } = require('appium-xcuitest-driver');15const { server } = require('appium');16const { SSLServer } = require('appium-ssl-support');17const { logger } = require('appium-support');18const log = logger.getLogger('Test');19const onServerCreated = (err, server) => {20 if (err) {21 log.errorAndThrow(err);22 }23 const sslServer = new SSLServer({server, logger: log});24 sslServer.close();25};26server.on('created', onServerCreated);27const { XCUITestDriver } = require('appium-xcuitest-driver');28const { server } = require('appium');29const { SSLServer } = require('appium-ssl-support');30const { logger } = require('appium-support');31const log = logger.getLogger('Test');32const onServerCreated = (err, server) => {33 if (err) {34 log.errorAndThrow(err);35 }36 const sslServer = new SSLServer({server, logger: log});37 sslServer.close();38};39server.on('created', onServerCreated);40const { XCUITestDriver } = require('appium-xcuitest-driver');41const { server } = require('appium');42const { SSLServer } = require('appium-ssl-support');43const { logger } = require('appium-support');44const log = logger.getLogger('Test');45const onServerCreated = (err, server) => {
Using AI Code Generation
1const { exec } = require('child_process');2exec(cmd, (err, stdout, stderr) => {3 if (err) {4 console.error(err);5 return;6 }7 console.log(stdout);8});9const { exec } = require('child_process');10exec(cmd, (err, stdout, stderr) => {11 if (err) {12 console.error(err);13 return;14 }15 console.log(stdout);16});17const { exec } = require('child_process');18exec(cmd, (err, stdout, stderr) => {19 if (err) {20 console.error(err);21 return;22 }23 console.log(stdout);24});25const { exec } = require('child_process');26exec(cmd, (err, stdout, stderr) => {27 if (err) {28 console.error(err);29 return;30 }31 console.log(stdout);32});33const { exec } =
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!!