How to use createHttpTransport method in Appium

Best JavaScript code snippet using appium

rop.js

Source:rop.js Github

copy

Full Screen

...64 }65 } else {66 // create websocket-initiated transport67 sid = createSessionId()68 trans = createHttpTransport(sid)69 self.transports[sid] = trans70 }71 console.log(new Buffer(sid, 'binary'))72 ws.send(new Buffer(sid, 'binary'))73 trans.__io.websocket = ws74 ws.onmessage = function (e) {75 trans.__io.onmessage(new RopBuffer(e.data))76 }77 ws.onclose = function (e) {78 trans.__io.onclose()79 delete self.transports[sid]80 }81 trans.__io.flushPendingMessages() // not part of IO interface82 })83 var handleHttpRequest = function (path, request, response) {84 // Create xhr-initiated transport85 if (path === '') {86 var sid = createSessionId()87 var trans = createHttpTransport(sid)88 trans.__timeout = Date.now() + HTTP_TRANSPORT_TIMEOUT89 self.transports[sid] = trans90 response.writeHead(200, {91 'Content-Type': 'text/plain',92 'Access-Control-Allow-Origin': '*'93 })94 response.write(sid)95 response.end()96 log.info('Created xhr-initiated transport:'+sid)97 return98 }99 // otherwise, treat as rop over xhr.100 var sid = path.substring(1)101 var trans = self.transports[sid]...

Full Screen

Full Screen

HttpTransport.js

Source:HttpTransport.js Github

copy

Full Screen

1/*******************************************************************************2 * Copyright (c) 2017 Texas Instruments and others All rights reserved. This3 * program and the accompanying materials are made available under the terms of4 * the Eclipse Public License v1.0 which accompanies this distribution, and is5 * available at http://www.eclipse.org/legal/epl-v10.html6 * 7 * Contributors: Raymond Pang - Initial API and implementation8 ******************************************************************************/9var gc = gc || {};10gc.databind = gc.databind || {};11(function() // closure for private static methods and data.12{13 var myWindow;14 var HttpTransport = function(useProxy) {15 this.connected = false;16 this.conn = {};17 this.useProxy = useProxy;18 this.uriMap = new Map();19 this.requestOutstanding = new Map();20 gc.databind.AbstractPubSubTransport.call(this);21 };22 var PubSubTopicBind = function(name, viewInstance) {23 gc.databind.VariableLookupBindValue.call(this);24 this.setStale(true);25 this.pubsubViewInstance = viewInstance;26 };27 var getEncodedType = function(contentType) {28 if (contentType.includes("application/json")) {29 return "json";30 } else if (contentType.includes("application/x-www-form-urlencoded")) {31 return "urlencoded";32 } else if (contentType.includes("text/plain")) {33 return "text";34 }35 }36 HttpTransport.prototype = new gc.databind.AbstractPubSubTransport();37 HttpTransport.prototype.connect = function(conn) {38 this.conn = conn;39 let url = this.conn.url.trim();40 // never use proxy, when connecting to localhost41 if (url.indexOf('http://localhost') === 0 || url.indexOf('https://localhost') === 042 || url.indexOf('http://127.0.0.1') === 0 || url.indexOf('https://127.0.0.1') === 0) {43 this.viaCloud = false;44 }45 else {46 this.viaCloud = (url.indexOf('https:') === 0) ? this.useProxy.https : this.useProxy.http;47 }48 this.disconnect();49 this.connected = true;50 if (conn.onConnect) {51 conn.onConnect();52 }53 return '';54 };55 HttpTransport.prototype.disconnect = function() {56 if (this.connected) {57 for ( var key in this.uriMap) {58 if (this.uriMap.hasOwnProperty(key)) {59 window.clearInterval(this.uriMap[key].timerID);60 }61 }62 this.uriMap.clear();63 this.connected = false;64 }65 return '';66 };67 HttpTransport.prototype.setUpRequest = function(req, verb, topic) {68 var error = "";69 try {70 if (this.viaCloud) {71 req.open(verb, myWindow.location.origin + "/gc-http-proxy/", true);72 req.setRequestHeader("ti-gc-http-target",73 encodeURIComponent(this.conn.url));74 req.setRequestHeader("ti-gc-http-uri",75 encodeURIComponent(topic.path));76 if (this.conn.userId != "") {77 req.setRequestHeader("ti-gc-http-user-id",78 encodeURIComponent(this.conn.userId));79 req.setRequestHeader("ti-gc-http-password",80 encodeURIComponent(this.conn.password));81 }82 } else {83 var Base64 = {84 _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",85 encode : function(e) {86 var t = "";87 var n, r, i, s, o, u, a;88 var f = 0;89 e = Base64._utf8_encode(e);90 while (f < e.length) {91 n = e.charCodeAt(f++);92 r = e.charCodeAt(f++);93 i = e.charCodeAt(f++);94 s = n >> 2;95 o = (n & 3) << 4 | r >> 4;96 u = (r & 15) << 2 | i >> 6;97 a = i & 63;98 if (isNaN(r)) {99 u = a = 64100 } else if (isNaN(i)) {101 a = 64102 }103 t = t + this._keyStr.charAt(s)104 + this._keyStr.charAt(o)105 + this._keyStr.charAt(u)106 + this._keyStr.charAt(a)107 }108 return t109 },110 decode : function(e) {111 var t = "";112 var n, r, i;113 var s, o, u, a;114 var f = 0;115 e = e.replace(/[^A-Za-z0-9+/=]/g, "");116 while (f < e.length) {117 s = this._keyStr.indexOf(e.charAt(f++));118 o = this._keyStr.indexOf(e.charAt(f++));119 u = this._keyStr.indexOf(e.charAt(f++));120 a = this._keyStr.indexOf(e.charAt(f++));121 n = s << 2 | o >> 4;122 r = (o & 15) << 4 | u >> 2;123 i = (u & 3) << 6 | a;124 t = t + String.fromCharCode(n);125 if (u != 64) {126 t = t + String.fromCharCode(r)127 }128 if (a != 64) {129 t = t + String.fromCharCode(i)130 }131 }132 t = Base64._utf8_decode(t);133 return t134 },135 _utf8_encode : function(e) {136 e = e.replace(/rn/g, "n");137 var t = "";138 for (var n = 0; n < e.length; n++) {139 var r = e.charCodeAt(n);140 if (r < 128) {141 t += String.fromCharCode(r)142 } else if (r > 127 && r < 2048) {143 t += String.fromCharCode(r >> 6 | 192);144 t += String.fromCharCode(r & 63 | 128)145 } else {146 t += String.fromCharCode(r >> 12 | 224);147 t += String.fromCharCode(r >> 6 & 63 | 128);148 t += String.fromCharCode(r & 63 | 128)149 }150 }151 return t152 },153 _utf8_decode : function(e) {154 var t = "";155 var n = 0;156 var r = c1 = c2 = 0;157 while (n < e.length) {158 r = e.charCodeAt(n);159 if (r < 128) {160 t += String.fromCharCode(r);161 n++162 } else if (r > 191 && r < 224) {163 c2 = e.charCodeAt(n + 1);164 t += String.fromCharCode((r & 31) << 6 | c2165 & 63);166 n += 2167 } else {168 c2 = e.charCodeAt(n + 1);169 c3 = e.charCodeAt(n + 2);170 t += String.fromCharCode((r & 15) << 12171 | (c2 & 63) << 6 | c3 & 63);172 n += 3173 }174 }175 return t176 }177 }178 req.open(verb, this.conn.url + topic.path, true);179 if (this.conn.userId && this.conn.userId != "") {180 var auth = "Basic " + Base64181 .encode(encodeURIComponent(this.conn.userId) + ":"182 + encodeURIComponent(this.conn.password));183 req.setRequestHeader("Authorization", auth);184 }185 }186 } catch (e) {187 error = e;188 }189 return error;190 };191 HttpTransport.prototype.subscribe = function(topic, opt) {192 var error = '';193 if (this.connected) {194 var that = this;195 var uri = {196 url : topic.path197 };198 if ( this.conn.pollInterval !== undefined && this.conn.pollInterval >= 0)199 {200 uri.timerID = window.setInterval(handleTimer,this.conn.pollInterval);201 }202 this.uriMap[topic.name] = uri;203 this.requestOutstanding[topic.name] = false;204 function handleTimer() {205 if (!that.requestOutstanding[topic.name]) {206 var req = new XMLHttpRequest();207 req.onreadystatechange = function() {208 if (req.readyState == XMLHttpRequest.DONE) {209 that.requestOutstanding[topic.name] = false;210 if (req.status == 200) {211 var contentType = req212 .getResponseHeader("Content-type");213 var encodedType = getEncodedType(contentType);214 if (encodedType !== undefined) {215 var msg = {216 destinationName : topic.name,217 type : encodedType,218 payloadString : req.response219 };220 that.conn.onMessageArrived(msg);221 } else {222 that.conn.onFailure("Subscribe URI "223 + topic.name224 + ": Unsupported content type "225 + contentType);226 window.clearInterval(uri.timerID);227 }228 } else {229 that.conn.onFailure("Failed to retrieve '" + that.conn.modelId + '.' + topic.name + "': " + req.status + " - " + req.statusText + " - " + req.responseText)230 }231 }232 };233 error = that.setUpRequest(req, "GET", topic);234 if (error == "") {235 that.requestOutstanding[topic.name] = true;236 try237 {238 req.send();239 } catch (e) {240 error = e;241 }242 }243 }244 }245 246 handleTimer();247 }248 return error;249 };250 HttpTransport.prototype.unsubscribe = function(topic, opt) {251 var error = '';252 if (this.connected) {253 try {254 var uri = this.uriMap[topic.name];255 if (uri !== undefined) {256 window.clearInterval(uri.timerID);257 this.uriMap[topic.name] = undefined;258 }259 } catch (e) {260 error = e;261 }262 ;263 }264 return error;265 };266 HttpTransport.prototype.publish = function(topic, payload, opt) {267 var encodeType = undefined;268 switch(topic.type) {269 case 'json':270 encodeType = 'application/json';271 break;272 case 'urlencoded':273 encodeType = 'application/x-www-form-urlencoded';274 break;275 case 'text':276 encodeType = 'text/plain';277 break;278 }279 if (encodeType !== undefined) {280 var formData = "";281 var req = new XMLHttpRequest();282 req.onreadystatechange = function() {283 if (req.readyState == XMLHttpRequest.DONE && req.status == 200) {284 // alert(req.responseText);285 }286 }287 if (topic.type == "urlencoded") {288 try {289 var data = JSON.parse(payload);290 for ( var key in data) {291 if (data.hasOwnProperty(key)) {292 if (formData != "") {293 formData += "&";294 }295 formData += encodeURIComponent(key),296 formData += "=";297 formData += encodeURIComponent(data[key]);298 }299 }300 } catch (e) {301 return "Publish URI " + topic.name + ": Invalid payload: "302 + e;303 }304 } else {305 formData = payload;306 }307 var error = this.setUpRequest(req, "POST", topic);308 if (error != "") {309 return error;310 }311 req.setRequestHeader("Content-type", encodeType);312 try {313 req.send(formData);314 } catch (e) {315 alert(e);316 }317 } else {318 return "Publish URI " + topic.name + ": Unsupported content type "319 + topic.contentType;320 }321 return "";322 };323 gc.databind.CreateHttpTransport = function(windowObj) {324 myWindow = windowObj;325 let name = (myWindow.location.protocol == 'https:') ? 'hybrid' : 'browser';326 if (name === "browser")327 return new HttpTransport({328 http : false,329 https : false330 });331 else if (name === "cloud")332 return new HttpTransport({333 http : true,334 https : true335 });336 else if (name === "hybrid")337 return new HttpTransport({338 http : true,339 https : false340 });341 return undefined;342 };...

Full Screen

Full Screen

logsink.js

Source:logsink.js Github

copy

Full Screen

...148 }149 }150 if (args.webhook) {151 try {152 transports.push(createHttpTransport(args, fileLogLevel));153 } catch (e) {154 // eslint-disable-next-line no-console155 console.log(`Tried to attach logging to Http at ${args.webhook} but ` +156 `an error occurred: ${e.message}`);157 }158 }159 return transports;160}161async function init (args) {162 // set de facto param passed to timestamp function163 timeZone = args.localTimezone;164 // clean up in case we have initted before since npmlog is a global object165 clear();166 log = createLogger({...

Full Screen

Full Screen

transport.js

Source:transport.js Github

copy

Full Screen

...7function create (app) {8 if (process.env.NODE_ENV === 'development' || process.env.BUHOI_CERTS_PATH) {9 return createHttpsTransport(app)10 } else {11 return createHttpTransport(app)12 }13}14function dispose (transport) {15 if (transport.redirector) {16 return new Promise(17 resolve => transport.redirector.shutdown(18 () => transport.carrier.shutdown(resolve)19 )20 )21 } else {22 return new Promise(resolve => transport.carrier.shutdown(resolve))23 }24}25function createHttpsTransport (app) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var appiumDriver = new AppiumDriver();2var appiumDriver = new AppiumDriver();3var appiumDriver = new AppiumDriver();4var appiumDriver = new AppiumDriver();5var appiumDriver = new AppiumDriver();6var appiumDriver = new AppiumDriver();7var appiumDriver = new AppiumDriver();8var appiumDriver = new AppiumDriver();9var appiumDriver = new AppiumDriver();10var appiumDriver = new AppiumDriver();11var appiumDriver = new AppiumDriver();

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;2var service = new AppiumServiceBuilder()3 .createHttpTransport();4console.log(service);5var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;6var service = new AppiumServiceBuilder()7 .createSession();8console.log(service);9var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;10var service = new AppiumServiceBuilder()11 .createSession();12console.log(service);13var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;14var service = new AppiumServiceBuilder()15 .createSession();16console.log(service);17var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;18var service = new AppiumServiceBuilder()19 .createSession();20console.log(service);21var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;22var service = new AppiumServiceBuilder()23 .createSession();24console.log(service);25var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;26var service = new AppiumServiceBuilder()27 .createSession();28console.log(service);29var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;30var service = new AppiumServiceBuilder()31 .createSession();32console.log(service);33var AppiumServiceBuilder = require('appium').AppiumServiceBuilder;34var service = new AppiumServiceBuilder()35 .createSession();36console.log(service);37var AppiumServiceBuilder = require('app

Full Screen

Using AI Code Generation

copy

Full Screen

1var http = require('http');2var server = http.createServer(function(req, res) {3 res.writeHead(200, {'Content-Type': 'text/plain'});4 res.end('okay');5});6server.listen(3000, '

Full Screen

Using AI Code Generation

copy

Full Screen

1var createHttpTransport = function() {2 var http = require('http');3 var https = require('https');4 var url = require('url');5 var Q = require('q');6 var _ = require('lodash');7 var logger = require('./logger').get('appium');8 var HttpTransport = function() {9 this.requestDefaults = {10 headers: {11 'Content-Type': 'application/json; charset=utf-8'12 }13 };14 };15 HttpTransport.prototype._request = function(method, url, data) {16 var d = Q.defer();17 var parsedUrl = url.parse(url);18 var isHttps = parsedUrl.protocol === 'https:';19 var req = (isHttps ? https : http).request(_.defaults({20 }, this.requestDefaults), function(res) {21 var body = '';22 res.setEncoding('utf8');23 res.on('data', function(chunk) {24 body += chunk;25 });26 res.on('end', function() {27 if (res.statusCode >= 400) {28 if (body) {29 try {30 body = JSON.parse(body);31 } catch (e) {32 }33 }34 d.reject(body);35 } else {36 d.resolve(body);37 }38 });39 });40 req.on('error', function(err) {41 d.reject(err);42 });43 if (data) {44 req.write(JSON.stringify(data));45 }46 req.end();47 return d.promise;48 };49 HttpTransport.prototype.get = function(url) {50 return this._request('GET', url);51 };52 HttpTransport.prototype.post = function(url, data) {53 return this._request('POST', url, data);54 };55 HttpTransport.prototype.delete = function(url) {56 return this._request('DELETE', url);57 };58 return new HttpTransport();59};60var AppiumDriver = function() {61 var logger = require('./logger').get('appium');62 var _ = require('lodash');63 var Q = require('q');64 var url = require('url');65 var createHttpTransport = require('./transport').createHttpTransport;

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