How to use createProxyServer method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

index.js

Source:index.js Github

copy

Full Screen

...24}25test('proxy request GET', (t) => {26 t.plan(2)27 const server = createOrigin()28 const proxyServer = createProxyServer(8888)29 const req = proxy({30 hostname: 'localhost',31 port: 9090,32 method: 'GET',33 proxy: {34 hostname: 'localhost',35 port: 8888,36 method: 'GET'37 }38 }, (res) => {39 var data = ''40 var cnt = 041 res.on('data', (chunk) => {42 data += chunk43 cnt++44 })45 res.on('end', () => {46 t.equal(cnt, 10, 'received in 10 chunks')47 t.equal(data, '12345678910', 'correct final response')48 server.close()49 proxyServer.close()50 })51 })52 req.end()53})54test('proxy request GET as a queryparameter', (t) => {55 t.plan(2)56 const server = createOrigin()57 const proxyServer = createProxyServer(8888)58 const req = http.request({59 hostname: 'localhost',60 port: 8888,61 method: 'GET',62 path: '/?proxy=http://localhost:9090'63 }, (res) => {64 var data = ''65 var cnt = 066 res.on('data', (chunk) => {67 data += chunk68 cnt++69 })70 res.on('end', () => {71 t.equal(cnt, 10, 'received in 10 chunks')72 t.equal(data, '12345678910', 'correct final response')73 server.close()74 proxyServer.close()75 })76 })77 req.end()78})79test('proxy request GET in path', (t) => {80 t.plan(2)81 const server = createOrigin()82 const proxyServer = createProxyServer(8888)83 const req = http.request({84 hostname: 'localhost',85 port: 8888,86 method: 'GET',87 path: '/proxy=' + encodeURIComponent('http://localhost:9090')88 }, (res) => {89 var data = ''90 var cnt = 091 res.on('data', (chunk) => {92 data += chunk93 cnt++94 })95 res.on('end', () => {96 t.equal(cnt, 10, 'received in 10 chunks')97 t.equal(data, '12345678910', 'correct final response')98 server.close()99 proxyServer.close()100 })101 })102 req.end()103})104test('proxy request GET in path + cache buster', (t) => {105 t.plan(2)106 const server = createOrigin()107 const proxyServer = createProxyServer(8888)108 const req = http.request({109 hostname: 'localhost',110 port: 8888,111 method: 'GET',112 path: '/1.1.9PLOY_ENV%3Dstaging/proxy=' + encodeURIComponent('http://localhost:9090')113 }, (res) => {114 var data = ''115 var cnt = 0116 res.on('data', (chunk) => {117 data += chunk118 cnt++119 })120 res.on('end', () => {121 t.equal(cnt, 10, 'received in 10 chunks')122 t.equal(data, '12345678910', 'correct final response')123 server.close()124 proxyServer.close()125 })126 })127 req.end()128})129test('proxy request GET as a queryparameter enhance request handler', (t) => {130 t.plan(2)131 const server = createOrigin()132 const proxyServer = createProxyServer(8888, false, (req) => {133 req.url = req.url.replace('something', 'http://localhost:9090')134 })135 const req = http.request({136 hostname: 'localhost',137 port: 8888,138 method: 'GET',139 path: '/?proxy=something'140 }, (res) => {141 var data = ''142 var cnt = 0143 res.on('data', (chunk) => {144 data += chunk145 cnt++146 })147 res.on('end', () => {148 t.equal(cnt, 10, 'received in 10 chunks')149 t.equal(data, '12345678910', 'correct final response')150 server.close()151 proxyServer.close()152 })153 })154 req.end()155})156test('proxy request GET as a queryparameter enhance request handler, block response', (t) => {157 t.plan(1)158 const server = createOrigin()159 const proxyServer = createProxyServer(8888, false, (req, res) => {160 return res.end('yo wrong')161 })162 const req = http.request({163 hostname: 'localhost',164 port: 8888,165 method: 'GET',166 path: '/?proxy=something'167 }, (res) => {168 var data = ''169 res.on('data', (chunk) => {170 data += chunk171 })172 res.on('end', () => {173 t.equal(data, 'yo wrong', 'correct response')174 server.close()175 proxyServer.close()176 })177 })178 req.end()179})180test('proxy request GET as a queryparameter enhance request handler, return a promise', (t) => {181 t.plan(2)182 const server = createOrigin()183 const proxyServer = createProxyServer(8888, false, (req) => {184 req.url = req.url.replace('something', 'http://localhost:9090')185 return new Promise((resolve, reject) => {186 setTimeout(resolve, 100)187 })188 })189 const req = http.request({190 hostname: 'localhost',191 port: 8888,192 method: 'GET',193 path: '/?proxy=something'194 }, (res) => {195 var data = ''196 var cnt = 0197 res.on('data', (chunk) => {198 data += chunk199 cnt++200 })201 res.on('end', () => {202 t.equal(cnt, 10, 'received in 10 chunks')203 t.equal(data, '12345678910', 'correct final response')204 server.close()205 proxyServer.close()206 })207 })208 req.end()209})210test('proxy request GET as a queryparameter enhance request handler, block response using a promise', (t) => {211 t.plan(1)212 const server = createOrigin()213 const proxyServer = createProxyServer(8888, false, (req, res) => {214 return new Promise((resolve, reject) => {215 setTimeout(() => {216 resolve(res.end('yo wrong'))217 }, 100)218 })219 })220 const req = http.request({221 hostname: 'localhost',222 port: 8888,223 method: 'GET',224 path: '/?proxy=something'225 }, (res) => {226 var data = ''227 res.on('data', (chunk) => {228 data += chunk229 })230 res.on('end', () => {231 t.equal(data, 'yo wrong', 'correct response')232 server.close()233 proxyServer.close()234 })235 })236 req.end()237})238test('proxy request GET as qeuryparam with json', (t) => {239 t.plan(2)240 const server = createOrigin()241 const proxyServer = createProxyServer(8888)242 const req = http.request({243 hostname: 'localhost',244 port: 8888,245 method: 'GET',246 path: '/?proxy={"host":"localhost","port":"9090"}'247 }, (res) => {248 var data = ''249 var cnt = 0250 res.on('data', (chunk) => {251 data += chunk252 cnt++253 })254 res.on('end', () => {255 t.equal(cnt, 10, 'received in 10 chunks')256 t.equal(data, '12345678910', 'correct final response')257 server.close()258 proxyServer.close()259 })260 })261 req.end()262})263test('proxy request GET as qeuryparam with wrong json - error', (t) => {264 t.plan(1)265 const server = createOrigin()266 const proxyServer = createProxyServer(8888)267 const req = http.request({268 hostname: 'localhost',269 port: 8888,270 method: 'GET',271 path: '/?proxy={haha}'272 }, (res) => {273 var data = ''274 res.on('data', (chunk) => {275 data += chunk276 })277 res.on('end', () => {278 t.equal(data, 'wrong json: {haha}', 'correct error message')279 server.close()280 proxyServer.close()281 })282 })283 req.end()284})285test('proxy request POST', (t) => {286 t.plan(4)287 const server = createOrigin()288 const proxyServer = createProxyServer(8888, false, false, () => {289 t.ok(true, 'fires proxy middleware')290 })291 const req = proxy({292 hostname: 'localhost',293 port: 9090,294 method: 'POST',295 proxy: {296 hostname: 'localhost',297 port: 8888,298 method: 'POST'299 }300 }, (res) => {301 var data = ''302 var cnt = 0303 res.on('data', (c) => {304 data += c305 cnt++306 })307 res.on('end', () => {308 t.equal(res.headers.hello, 'haha', 'correct headers from origin get passed')309 t.equal(cnt, 10, 'received in 10 chunks')310 t.equal(data, '1!2!3!4!5!6!7!8!9!10!', 'correct final response, recieves payload')311 server.close()312 proxyServer.close()313 })314 })315 req.write('!')316 req.end()317})318test('proxy request statusCode response', (t) => {319 t.plan(2)320 const statusCode = 500321 const statusMessage = 'nasty server error'322 const server = createOrigin(statusCode, statusMessage)323 const proxyServer = createProxyServer(8888)324 const req = proxy({325 hostname: 'localhost',326 port: 9090,327 method: 'GET',328 proxy: {329 hostname: 'localhost',330 port: 8888,331 method: 'GET'332 }333 }, (res) => {334 t.equal(res.statusCode, 500, 'proxy should forward the statusCode')335 t.equal(res.statusMessage, 'nasty server error')336 server.close()337 proxyServer.close()338 })339 req.end()340})341test('proxy request error forwarding', (t) => {342 t.plan(3)343 const server = createOrigin()344 const proxyServer = createProxyServer(8888)345 const errorReq = proxy({346 hostname: 'weirdurl.weirdness',347 port: 9090,348 method: 'POST',349 proxy: {350 hostname: 'localhost',351 port: 8888,352 method: 'POST'353 }354 }, (res) => {355 var data = ''356 res.on('data', (c) => {357 data += c358 })359 res.on('end', () => {360 t.equal(res.statusCode, 500, '500 statuscode')361 t.same(362 JSON.parse(res.statusMessage),363 {364 error: 'getaddrinfo ENOTFOUND weirdurl.weirdness weirdurl.weirdness:9090',365 options: {366 hostname: 'weirdurl.weirdness',367 port: 9090,368 method: 'POST'369 }370 },371 'correct errorMessage'372 )373 t.equal(data, '', 'empty response on error')374 server.close()375 proxyServer.close()376 })377 })378 errorReq.end()379})380test('proxy request error forwarding', (t) => {381 t.plan(1)382 const proxyServer = createProxyServer(8888)383 http.request({384 hostname: 'localhost',385 port: 8888386 }, (res) => {387 var str = ''388 res.on('data', (chunk) => { str += chunk })389 res.on('end', () => {390 t.equal(str, 'minimal-http-proxy ' + pckg.version, 'return minimal-http-proxy on normal requests')391 proxyServer.close()392 })393 }).end()394})395test('proxy request over https', (t) => {396 t.plan(1)397 const req = proxy({398 hostname: 'google.com',399 protocol: 'https',400 method: 'GET',401 proxy: {402 hostname: 'proxy.vigour.io',403 method: 'POST',404 protocol: 'https',405 path: '/?random=true'406 }407 }, (res) => {408 var str = ''409 res.on('data', (chunk) => { str += chunk })410 res.on('end', () => {411 t.equal(!!str, true, 'returns data')412 })413 })414 req.end()415})416test('proxy request over https using qeuryparam', (t) => {417 t.plan(1)418 const proxyServer = createProxyServer(8888)419 const req = http.request({420 hostname: 'localhost',421 port: 8888,422 method: 'GET',423 path: '/?proxy=https://google.com'424 }, (res) => {425 var str = ''426 res.on('data', (chunk) => { str += chunk })427 res.on('end', () => {428 t.equal(!!str, true, 'returns data')429 proxyServer.close()430 })431 })432 req.end()...

Full Screen

Full Screen

http-proxy.js

Source:http-proxy.js Github

copy

Full Screen

...4 * Creates the proxy server.5 *6 * Examples:7 *8 * httpProxy.createProxyServer({ .. }, 8000)9 * // => '{ web: [Function], ws: [Function] ... }'10 *11 * @param {Object} Options Config object passed to the proxy12 *13 * @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests14 *15 * @api public16 */17function createProxyServer(options) {18 /*19 * `options` is needed and it must have the following layout:20 *21 * {22 * target : <url string to be parsed with the url module>23 * forward: <url string to be parsed with the url module>24 * agent : <object to be passed to http(s).request>25 * ssl : <object to be passed to https.createServer()>26 * ws : <true/false, if you want to proxy websockets>27 * xfwd : <true/false, adds x-forward headers>28 * secure : <true/false, verify SSL certificate>29 * toProxy: <true/false, explicitly specify if we are proxying to another proxy>30 * prependPath: <true/false, Default: true - specify whether you want to prepend the target's path to the proxy path>31 * ignorePath: <true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request>...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const AppiumBaseDriver = require('appium-base-driver');2const appiumBaseDriver = new AppiumBaseDriver();3const proxyServer = appiumBaseDriver.createProxyServer({port: 8100, base: '/wd/hub'});4const AppiumBaseDriver = require('appium-base-driver');5const appiumBaseDriver = new AppiumBaseDriver();6const proxyServer = appiumBaseDriver.createProxyServer({port: 8100, base: '/wd/hub'});7const AppiumBaseDriver = require('appium-base-driver');8const appiumBaseDriver = new AppiumBaseDriver();9const proxyServer = appiumBaseDriver.createProxyServer({port: 8100, base: '/wd/hub'});10const AppiumBaseDriver = require('appium-base-driver');11const appiumBaseDriver = new AppiumBaseDriver();12const proxyServer = appiumBaseDriver.createProxyServer({port: 8100, base: '/wd/hub'});13const AppiumBaseDriver = require('appium-base-driver');14const appiumBaseDriver = new AppiumBaseDriver();15const proxyServer = appiumBaseDriver.createProxyServer({port: 8100, base: '/wd/hub'});16const AppiumBaseDriver = require('appium-base-driver');17const appiumBaseDriver = new AppiumBaseDriver();18const proxyServer = appiumBaseDriver.createProxyServer({port: 8100, base: '/wd/hub'});19const AppiumBaseDriver = require('appium-base-driver');20const appiumBaseDriver = new AppiumBaseDriver();21const proxyServer = appiumBaseDriver.createProxyServer({port: 8100, base: '/wd/hub'});22const AppiumBaseDriver = require('appium-base-driver');23const appiumBaseDriver = new AppiumBaseDriver();24const proxyServer = appiumBaseDriver.createProxyServer({port: 8100,

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AppiumBaseDriver } = require('appium-base-driver');2const { createProxyServer } = AppiumBaseDriver.prototype;3const opts = {4 logFn: () => {},5};6const server = createProxyServer(opts);7server.listen(3000, () => {8 console.log('Server listening on port 3000');9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var appium = require('appium-base-driver');2var server = appium.createProxyServer({port: 4732, base: '/wd/hub'});3server.listen(4732, function() {4 console.log("Appium server listening on port 4732");5});6var appium = require('appium-base-driver');7var server = appium.createServer({port: 4732, base: '/wd/hub'});8server.listen(4732, function() {9 console.log("Appium server listening on port 4732");10});11var appium = require('appium-base-driver');12var server = appium.createServer({port: 4732, base: '/wd/hub'});13server.listen(4732, function() {14 console.log("Appium server listening on port 4732");15});16var appium = require('appium-base-driver');17var server = appium.createServer({port: 4732, base: '/wd/hub'});18server.listen(4732, function() {19 console.log("Appium server listening on port 4732");20});21var appium = require('appium-base-driver');22var server = appium.createServer({port: 4732, base: '/wd/hub'});23server.listen(4732, function() {24 console.log("Appium server listening on port 4732");25});26var appium = require('appium-base-driver');27var server = appium.createServer({port: 4732, base: '/wd/hub'});28server.listen(4732, function() {29 console.log("Appium server listening on port 4732");30});31var appium = require('appium-base-driver');32var server = appium.createServer({port: 4732, base: '/wd/hub'});33server.listen(4732, function() {34 console.log("Appium server listening on port 4732");35});36var appium = require('appium-base-driver');37var server = appium.createServer({port:

Full Screen

Using AI Code Generation

copy

Full Screen

1var Appium = require('appium');2var appium = new Appium();3var driver = appium.createProxyServer();4driver.init({5});6driver.quit();7var Appium = require('appium');8var appium = new Appium();9var driver = appium.createSession();10driver.init({11});12driver.quit();13var Appium = require('appium');14var appium = new Appium();15var driver = appium.createSession();16driver.init({17});18driver.quit();19var Appium = require('appium');20var appium = new Appium();21var driver = appium.createSession();22driver.init({23});24driver.quit();25var Appium = require('appium');

Full Screen

Using AI Code Generation

copy

Full Screen

1const BaseDriver = require('appium-base-driver').BaseDriver;2const driver = new BaseDriver();3driver.createProxyServer();4driver.stopProxyServer();5const proxy = driver.getProxyServer();6driver.setProxyServer(proxy);7const proxy = driver.getProxyServer();8driver.setProxyServer(proxy);9const proxy = driver.getProxyServer();10driver.setProxyServer(proxy);11const proxy = driver.getProxyServer();12driver.setProxyServer(proxy);13const proxy = driver.getProxyServer();14driver.setProxyServer(proxy);15const proxy = driver.getProxyServer();16driver.setProxyServer(proxy);17const proxy = driver.getProxyServer();18driver.setProxyServer(proxy);19const proxy = driver.getProxyServer();20driver.setProxyServer(proxy);21const proxy = driver.getProxyServer();

Full Screen

Using AI Code Generation

copy

Full Screen

1const proxy = await driver.createProxyServer();2const proxyHost = proxy.proxyHost;3const proxyPort = proxy.proxyPort;4const driver = await wdio.remote({5 capabilities: {6 proxy: {7 },8 },9});10const proxy = await driver.createProxyServer();11const proxyHost = proxy.proxyHost;12const proxyPort = proxy.proxyPort;13const driver = await wdio.remote({14 capabilities: {15 proxy: {16 },17 },18});19const proxy = await driver.createProxyServer();20const proxyHost = proxy.proxyHost;21const proxyPort = proxy.proxyPort;22const driver = await wdio.remote({23 capabilities: {24 proxy: {25 },26 },27});

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 Base 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