Best JavaScript code snippet using appium-base-driver
twonline.js
Source:twonline.js
...71 });72}73// ajax74//CORS middleware75function allowCrossDomain(req, res) {76 res.header('Access-Control-Allow-Origin', "*");77 res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');78 res.header('Access-Control-Allow-Headers', 'Content-Type');79}80app.get("/get/:plname/:plclan/", function(req, res) {81 res.header("Content-Type", "application/json");82 allowCrossDomain(req, res);83 var name = req.params.plname == "matchall" ? "" : req.params.plname;84 var clan = req.params.plclan == "matchall" ? "" : req.params.plclan;85 var obj = {};86 var body;87 if (!(name || clan))88 obj.error = "Invalid request";89 else {90 var plInfo = findPlayers([{name: name, clan: clan}]);91 if (!plInfo.players.length)92 obj.error = "Player not found"93 else {94 var pls = plInfo.players;95 obj.players = []; 96 for (var i = 0; i < pls.length; i++) {97 obj.players.push({98 name: pls[i].pl.name,99 clan: pls[i].pl.clan,100 srvId: pls[i].srvId,101 }); 102 }103 // add servers104 obj.servers = [];105 for (var i = 0; i < plInfo.servers.length; i++) {106 var srv = plInfo.servers[i];107 obj.servers.push({108 name: srv.name,109 map: srv.map,110 gametype: srv.gametype,111 numPlayers: srv.numClients, 112 maxPlayers: srv.maxClients,113 addr: srv.address+":"+srv.port,114 }); 115 }116 }117 }118 res.status(200).send(JSON.stringify(obj));119});120app.get("/server/:ip/:port/", function(req, res) {121 res.header("Content-Type", "application/json");122 allowCrossDomain(req, res);123 var ip = req.params.ip;124 var port = req.params.port;125 var obj = {};126 var body;127 if (!ip && !port)128 obj.error = "Invalid request";129 else {130 var srvs = getServers(ip, port);131 if (srvs.length == 0) {132 obj.error = "Server not found";133 } else {134 obj = srvs[0];135 }136 }137 res.status(200).send(JSON.stringify(obj));138});139app.get("/get/qzclan", function(req, res) {140 res.header("Content-Type", "application/json");141 allowCrossDomain(req, res);142 143 var obj = {};144 var body;145 var plInfo = findPlayers([{clan: "'qZ"}, {clan: "QuintessenZ"}, {name: "'qZ |BlaGK|âº", clan: "enjoy!"}]);146 if (!plInfo.players.length)147 obj.error = "Player not found"148 else {149 var pls = plInfo.players;150 obj.players = []; 151 for (var i = 0; i < pls.length; i++) {152 obj.players.push({153 name: pls[i].pl.name,154 clan: pls[i].pl.clan,155 srvId: pls[i].srvId,156 }); 157 }158 // add servers159 obj.servers = [];160 for (var i = 0; i < plInfo.servers.length; i++) {161 var srv = plInfo.servers[i];162 obj.servers.push({163 name: srv.name,164 map: srv.map,165 gametype: srv.gametype,166 numPlayers: srv.numClients, 167 maxPlayers: srv.maxClients,168 addr: srv.address+":"+srv.port,169 }); 170 }171 }172 res.status(200).send(JSON.stringify(obj));173});174app.get("/serversof/:ip/", function(req, res) {175 res.header("Content-Type", "application/json");176 allowCrossDomain(req, res);177 var ip = req.params.ip;178 var obj = {};179 var body;180 if (!ip)181 obj.error = "Invalid request";182 else {183 var obj = getServers(ip, null);184 if (!obj)185 obj.error = "Server not found";186 }187 res.status(200).send(JSON.stringify(obj));188});189app.get("/servernamesof/:ip/", function(req, res) {190 res.header("Content-Type", "application/json");191 allowCrossDomain(req, res);192 var ip = req.params.ip;193 var obj = {};194 var body;195 if (!ip)196 obj.error = "Invalid request";197 else {198 var srvs = getServers(ip, null);199 var nameList = [];200 srvs.forEach(function(e) { nameList.push(e.name) });201 obj = nameList;202 }203 res.status(200).send(JSON.stringify(obj));204});205update();...
app.js
Source:app.js
1/**2 * Module dependencies.3 */4var express = require('express')5 , http = require('http')6 , config = require('./config.js')7 , cloudformation = require('./routes/cloudformation.js')8 , jsonStripComments = require('./routes/json-stripe-comments.js')9 , sqs = require('./routes/sqs.js')10 , ec2 = require('./routes/ec2.js')11 , route53 = require('./routes/route53.js')12 , importExport = require('./routes/importExport.js')13 , allServices = require('./routes/allServices.js');14var app = express();15// all environments16app.use(express.logger('dev'));17app.use(express.bodyParser());18app.use(express.methodOverride());19app.use(app.router);20// development only21if (app.get('env') === 'development') {22 app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));23 app.locals.pretty = true;24 app.locals.port = 8080;25}26// production only27if (app.get('env') === 'production') {28 app.use(express.errorHandler());29 app.locals.port = process.env.PORT || 80;30};31/*32 * ERROR HANDLING33 */34var logErrors = function(err, req, res, next) {35 console.error(err.stack);36 next(err);37};38function clientErrorHandler(err, req, res, next) {39 if (req.xhr) {40 res.send(500, { error: err });41 } else {42 next(err);43 }44}45function errorHandler(err, req, res, next) {46 res.status(500);47 res.render('error', { error: err });48}49//50// CORS Options51//52var allowCrossDomain = function(req, res, next) {53 res.header('Access-Control-Allow-Origin', '*');54 res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');55 res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, X-Auth-Token');56 // intercept OPTIONS method57 if ('OPTIONS' == req.method) {58 res.send(200);59 }60 else {61 next();62 }63};64app.use(logErrors);65app.use(clientErrorHandler);66app.use(errorHandler);67process.on('uncaughtException', function(err) {68 console.log('process died ', err);69});70/**71 * Routes72 */73// CloudFormation74app.put('/cloudformation', allowCrossDomain, cloudformation.createStack);75app.put('/cloudformationURLTemplate', allowCrossDomain, cloudformation.createStackURLTemplate);76app.post('/cloudformation', allowCrossDomain, cloudformation.updateStack);77app.delete('/cloudformation/:stackName', allowCrossDomain, cloudformation.deleteStack);78app.post('/cloudformation/validate', allowCrossDomain, cloudformation.validateTemplate);79app.get('/cloudformation/describeStacks/:stackName', allowCrossDomain, cloudformation.describeStacks);80// JSON strip comments81app.post('/json-strip-comments', allowCrossDomain, jsonStripComments.strip);82// Health checks83app.get('/heartbeat', allowCrossDomain, function(req, res) {84 res.json(200, { message: 'Alive'});85});86// EC287app.post('/ec2/:apiName', allowCrossDomain, ec2.ec2API);88// Route5389app.post('/route53/changeResourceRecordSets', allowCrossDomain, route53.changeResourceRecordSets);90// ImportExport91app.post('/importExport/:apiName', allowCrossDomain, importExport.api);92// All Services93app.post('/:serviceName/:apiName', allowCrossDomain, allServices.allAPI);94/**95 * Start Server96 */97http.createServer(app).listen(app.locals.port, function(){98 console.log('Server listening on port ' + app.locals.port);...
authors.js
Source:authors.js
1import express from 'express';2import pool from '../config/sqlPool';3import sqlQuery from '../config/query';4import allowCrossDomain from '../config/middleware';5const router = express.Router();6router.get('/', allowCrossDomain, async (req, res) => {7 const [authors, fields] = await sqlQuery.getAuthors();8 res.json(authors);9});10router.get('/:id', async (req, res) => {11 const authorId = req.params.id;12 console.log('author');13 const author = await sqlQuery.getAuthorById(authorId);14 res.status(200).json(author);15});16router.get('/relation/:id', async (req, res) => {17 const authorId = req.params.id;18 const [authorsAndBooks, fields] = await sqlQuery.getAuthorsAndBooks(authorId);19 res.status(200).json(authorsAndBooks);20})21router.delete('/delete/:id', allowCrossDomain, async (req, res) => {22 console.log('delete id', req.params.id);23 const [deleteAuthor, fields] = await sqlQuery.deleteAuthor(req.params.id);24 res.send(deleteAuthor);25});26router.post('/insert', async (req, res) => {27 console.log('you are in author', req.body);28 const [result, fields] = await sqlQuery.getAuthorInsert(req.body);29 res.json(result);30});31router.put('/update/:id', async (req, res) => {32 const updateId = req.params.id;33 const updateRequest = req.body;34 console.log('you are in updateRequest: updateId', updateId, 'updateRequest:', updateRequest);35 await sqlQuery.updateAuthor(updateId, updateRequest);36 res.json(updateRequest);37});...
server.js
Source:server.js
1var express = require('express');2var bodyParser = require('body-parser');3var allowCrossDomain = function (req, res, next) {4 res.header('Access-Control-Allow-Origin', "*");5 res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');6 res.header('Access-Control-Allow-Headers', 'Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, app-id');7 if (req.method === "OPTIONS")8 res.sendStatus(200);9 else10 next();11}12app = express();13app.use(bodyParser.json());14app.use(function (err, req, res, next) {15 if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {16 console.error('Bad JSON');17 next(err);18 }19});2021// assign route files to variables22var customer = require('./routes/customer_routes');23var item = require('./routes/item_routes');24var order = require('./routes/order_routes');25var staff = require('./routes/staff_routes');26var customer_orders = require('./routes/customer-orders_routes');27var home = require('./routes/home_routes');2829app.use('/customer', allowCrossDomain, customer);30app.use('/item', allowCrossDomain, item);31app.use('/order', allowCrossDomain, order);32app.use('/staff', allowCrossDomain, staff);33app.use('/customer-orders', allowCrossDomain, customer_orders);34app.use('/home', allowCrossDomain, home);35
...
books.js
Source:books.js
1import express from 'express';2import pool from '../config/sqlPool';3import sqlQuery from '../config/query';4import allowCrossDomain from '../config/middleware';5const router = express.Router();6router.get('/', allowCrossDomain, async (req, res) => {7 console.log('withoutId');8 const [books, fields] = await sqlQuery.getBooks();9 res.json(books);10});11router.post('/insert', allowCrossDomain, async (req, res) => {12 console.log('bookRequest', req.body);13 const [book, fields] = await sqlQuery.getBookInsert(req.body);14 res.json(book);15});16router.put('/update/:id', allowCrossDomain, async (req, res) => {17 const updateId = req.params.id;18 const updateRequest = req.body;19 await sqlQuery.updateBook(updateId, updateRequest);20 res.json(updateRequest);21});22router.delete('/delete/:id', allowCrossDomain, async (req, res) => {23 const reqId = req.params.id;24 console.log(reqId);25 await sqlQuery.deleteBook(reqId);26 res.status(200).send(`Id:${reqId} book is deleted`);27});28router.get('/:id', async (req, res) => {29 const reqId = req.params.id;30 console.log('book request Id:', reqId);31 const [book, fields] = await sqlQuery.getBookById(reqId);32 console.log(book);33 res.status(200).json(book);34});...
redisTest.js
Source:redisTest.js
1/**2 * Created by mac on 2018/1/24.3 */4const express = require('express');5const session = require('express-session');6var allowCrossDomain = require('./config/allowCrossDomain');7const RedisStore = require('connect-redis')(session);8let app = express();9// å
许跨å10app.use(allowCrossDomain.allowCrossDomain)11app.use(session({12 secret: 'keyboard cat',13 cookie: ('name', 'value', { path: '/', httpOnly: false,secure: false, maxAge: 600000 }),14 //éæ°ä¿åï¼å¼ºå¶ä¼è¯ä¿åå³ä½¿æ¯æªä¿®æ¹çãé»è®¤ä¸ºtrueä½æ¯å¾åä¸15 resave: true,16 //强å¶âæªåå§åâçä¼è¯ä¿åå°åå¨ã17 saveUninitialized: true,18 store : new RedisStore({19 "host": "127.0.0.1",20 "port" : "6379",21 "ttl" : 1800,22 "logErrors" : true23 })24}));25var redistestpost = require('./redisTestpost').redistestpost(app)26app.listen(4000,()=>{27 console.log('start');...
cors.js
Source:cors.js
1// crappy IE hacks have made it to the server!!!!2// man ie is horrible. Ok, here is the issue: https://github.com/senchalabs/connect/issues/3553// here is the fix: https://github.com/advanced/express-ie-cors, patch below4var expressIeCors = require('express-ie-cors')({contentType: "application/x-www-form-urlencoded;charset=utf-8"});5module.exports = function(app, config) {6 // setup cors7 var allowCrossDomain = null;8 if( config.server.allowedDomains ) {9 allowCrossDomain = function(req, res, next) {10 if( config.server.allowedDomains.indexOf(req.hostname) == -1 &&11 config.server.allowedDomains.indexOf('*') == -1 ) {12 return next();13 }14 res.header('Access-Control-Allow-Origin', '*');15 res.header('Access-Control-Allow-Methods', 'GET,POST');16 res.header('Access-Control-Allow-Headers', 'Content-Type');17 next();18 };19 }20 if( allowCrossDomain ) {21 app.use(allowCrossDomain);22 app.use(expressIeCors);23 }...
middleware.js
Source:middleware.js
1const allowCrossDomain = function(req, res, next) {2 res.header('Access-Control-Allow-Origin', "*");3 res.header('Access-Control-Allow-Headers', "*");4 next();5}...
Using AI Code Generation
1var AppiumBaseDriver = require('appium-base-driver');2var appiumBaseDriver = new AppiumBaseDriver();3appiumBaseDriver.allowCrossDomain();4var AppiumExpressDriver = require('appium-express-driver');5var appiumExpressDriver = new AppiumExpressDriver();6appiumExpressDriver.allowCrossDomain();7var appiumJsonwpProxy = require('appium-jsonwp-proxy');8appiumJsonwpProxy.allowCrossDomain();9var RemoteDebugger = require('appium-remote-debugger');10var remoteDebugger = new RemoteDebugger();11remoteDebugger.allowCrossDomain();12var RemoteDebugger = require('appium-remote-debugger');13var remoteDebugger = new RemoteDebugger();14remoteDebugger.allowCrossDomain();15var RemoteDebugger = require('appium-remote-debugger');16var remoteDebugger = new RemoteDebugger();17remoteDebugger.allowCrossDomain();18var RemoteDebugger = require('appium-remote-debugger');19var remoteDebugger = new RemoteDebugger();20remoteDebugger.allowCrossDomain();21var RemoteDebugger = require('appium-remote-debugger');22var remoteDebugger = new RemoteDebugger();23remoteDebugger.allowCrossDomain();24var RemoteDebugger = require('appium-remote-debugger');25var remoteDebugger = new RemoteDebugger();26remoteDebugger.allowCrossDomain();27var RemoteDebugger = require('appium-remote-debugger');28var remoteDebugger = new RemoteDebugger();29remoteDebugger.allowCrossDomain();30var RemoteDebugger = require('appium-remote-debugger');31var remoteDebugger = new RemoteDebugger();32remoteDebugger.allowCrossDomain();33var RemoteDebugger = require('appium-remote-debugger');34var remoteDebugger = new RemoteDebugger();35remoteDebugger.allowCrossDomain();
Using AI Code Generation
1var allowCrossDomain = require('./node_modules/appium-base-driver/lib/mjsonwp/middleware').allowCrossDomain;2var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');3var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;4var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');5var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;6var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');7var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;8var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');9var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;10var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');11var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;12var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');13var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;14var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');15var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;16var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');17var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;18var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');19var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;20var appiumBaseDriver = require('./node_modules/appium-base-driver/lib/basedriver/driver');21var AppiumBaseDriver = appiumBaseDriver.AppiumBaseDriver;22var appiumBaseDriver = require('./node_modules/appium-base-driver/lib
Using AI Code Generation
1var allowCrossDomain = require('appium-base-driver').allowCrossDomain;2var getResponseFor = require('appium-base-driver').getResponseFor;3app.get('/wd/hub/session/:sessionId/element/:elementId/attribute/:name', allowCrossDomain, function(req, res) {4 var response = getResponseFor(req);5 res.send(response);6});7app.post('/wd/hub/session/:sessionId/element/:elementId/attribute/:name', allowCrossDomain, function(req, res) {8 var response = getResponseFor(req);9 res.send(response);10});11app.get('/wd/hub/session/:sessionId/element/:elementId/element/:id/attribute/:name', allowCrossDomain, function(req, res) {12 var response = getResponseFor(req);13 res.send(response);14});15app.post('/wd/hub/session/:sessionId/element/:elementId/element/:id/attribute/:name', allowCrossDomain, function(req, res) {16 var response = getResponseFor(req);17 res.send(response);18});19app.get('/wd/hub/session/:sessionId/element/:elementId/elements/:id/attribute/:name', allowCrossDomain, function(req, res) {20 var response = getResponseFor(req);21 res.send(response);22});23app.post('/wd/hub/session/:sessionId/element/:elementId/elements/:id/attribute/:name', allowCrossDomain, function(req, res) {24 var response = getResponseFor(req);25 res.send(response);26});27app.get('/wd/hub/session/:sessionId/element/:elementId/css/:propertyName', allowCrossDomain, function(req, res) {28 var response = getResponseFor(req);29 res.send(response);30});31app.post('/wd/hub/session/:sessionId/element/:elementId/css/:propertyName', allowCrossDomain, function(req, res) {32 var response = getResponseFor(req);33 res.send(response);34});35app.get('/wd/hub/session/:sessionId/element/:elementId/
Using AI Code Generation
1var request = require('request');2var allowCrossDomain = require('../node_modules/appium-base-driver/lib/mjsonwp/mjsonwp.js').allowCrossDomain;3var appiumBaseDriver = require('../node_modules/appium-base-driver/lib/mjsonwp/mjsonwp.js').MJSONWP;4var appiumBaseDriver = new appiumBaseDriver();5var appiumBaseDriverMethod = appiumBaseDriver.allowCrossDomain;6var appiumBaseDriverMethod = allowCrossDomain;7appiumBaseDriverMethod(request, response, function() {8 console.log('callback');9});10var appiumBaseDriver = require('../node_modules/appium-base-driver/lib/mjsonwp/mjsonwp.js');11var appiumBaseDriverMethod = appiumBaseDriver.allowCrossDomain;12appiumBaseDriverMethod(request, response, function() {13 console.log('callback');14});15var appiumBaseDriver = require('../node_modules/appium-base-driver/lib/mjsonwp/mjsonwp.js');16var appiumBaseDriverMethod = appiumBaseDriver.MJSONWP.allowCrossDomain;17appiumBaseDriverMethod(request, response, function() {18 console.log('callback');19});20var appiumBaseDriver = require('../node_modules/appium-base-driver/lib/mjsonwp/mjsonwp.js');21var appiumBaseDriverMethod = appiumBaseDriver.MJSONWP.prototype.allowCrossDomain;22appiumBaseDriverMethod(request, response, function() {23 console.log('callback');24});25var appiumBaseDriver = require('../node_modules/appium-base-driver/lib/mjsonwp/mjsonwp.js');26var appiumBaseDriverMethod = appiumBaseDriver.MJSONWP.prototype.allowCrossDomain;27appiumBaseDriverMethod(request, response, function() {28 console.log('callback');29});30var appiumBaseDriver = require('../node_modules/appium-base-driver/lib/mjsonwp/mjsonwp.js');31var appiumBaseDriverMethod = appiumBaseDriver.MJSONWP.prototype.allowCrossDomain;32appiumBaseDriverMethod(request, response, function() {33 console.log('callback');34});
Using AI Code Generation
1const AppiumBaseDriver = require('appium-base-driver');2const appium = require('appium');3const express = require('express');4const request = require('request');5const appiumServer = appium.main;6const appiumServerArgs = {7};8const appiumServerConfig = {9};10const appiumServerInstance = new AppiumBaseDriver.Server(appiumServerConfig);11const appiumServerStart = appiumServerInstance.start();12const appiumServerStop = appiumServerInstance.stop();13const appiumServerRestart = appiumServerInstance.restart();14const appiumServerStatus = appiumServerInstance.status();15const appiumServerIsRunning = appiumServerInstance.isRunning();16const appiumServerIsShuttingDown = appiumServerInstance.isShuttingDown();17const appiumServerIsShutDown = appiumServerInstance.isShutDown();18const appiumServerIsStarting = appiumServerInstance.isStarting();19const appiumServerIsStopped = appiumServerInstance.isStopped();20const appiumServerIsStartingUp = appiumServerInstance.isStartingUp();21const appiumServerIsRunning = appiumServerInstance.isRunning();22const appiumServerIsShuttingDown = appiumServerInstance.isShuttingDown();23const appiumServerIsShutDown = appiumServerInstance.isShutDown();24const appiumServerIsStarting = appiumServerInstance.isStarting();25const appiumServerIsStopped = appiumServerInstance.isStopped();26const appiumServerIsStartingUp = appiumServerInstance.isStartingUp();27const appiumServerIsRunning = appiumServerInstance.isRunning();28const appiumServerIsShuttingDown = appiumServerInstance.isShuttingDown();29const appiumServerIsShutDown = appiumServerInstance.isShutDown();30const appiumServerIsStarting = appiumServerInstance.isStarting();31const appiumServerIsStopped = appiumServerInstance.isStopped();
Using AI Code Generation
1describe('test', function() {2 it('test', function() {3 .allowCrossDomain()4 .title()5 .should.become('Google')6 .nodeify(done);7 });8});9var commands = {10 allowCrossDomain: function() {11 return this.proxyReqRes.allowCrossDomain();12 }13};14var commands = {15 allowCrossDomain: function() {16 return this.proxyReqRes.allowCrossDomain();17 }18};19var commands = {20 allowCrossDomain: function() {21 return this.proxyReqRes.allowCrossDomain();22 }23};
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!!