How to use this.proxyFunc method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

BaseClass.js

Source:BaseClass.js Github

copy

Full Screen

...65 get instance() {66 return _instance67 }68 get _(){69 return this.proxyFunc('classes', this)70 }71 set _(oTarget) {72 this.applyClass(oTarget)73 };74 applyClass(oTarget, parent, key, decentChain) {75 this._last = oTarget;76 var name = oTarget.name;77 var target = this.targets[name]78 if(!target){79 this.targets[name] = doneProxySymbol;80 // console.info('Apply Instance definition:', oTarget.name)81 if(oTarget.prototype.__declare__) {82 var d = oTarget.prototype.__declare__.call(oTarget, oTarget);83 if(d && d.global === true) {...

Full Screen

Full Screen

protocol-converter.js

Source:protocol-converter.js Github

copy

Full Screen

...96 let response, resBody;97 const timeoutRequestObjects = this.getTimeoutRequestObjects(body);98 log.debug(`Will send the following request bodies to /timeouts: ${JSON.stringify(timeoutRequestObjects)}`);99 for (const timeoutObj of timeoutRequestObjects) {100 [response, resBody] = await this.proxyFunc(url, method, timeoutObj);101 // If we got a non-MJSONWP response, return the result, nothing left to do102 if (this.downstreamProtocol !== MJSONWP) {103 return [response, resBody];104 }105 // If we got an error, return the error right away106 if (response.statusCode >= 400) {107 return [response, resBody];108 }109 // ...Otherwise, continue to the next timeouts call110 }111 return [response, resBody];112 }113 async proxySetWindow (url, method, body) {114 const bodyObj = util.safeJsonParse(body);115 if (_.isPlainObject(bodyObj)) {116 if (this.downstreamProtocol === W3C && _.has(bodyObj, 'name') && !_.has(bodyObj, 'handle')) {117 log.debug(`Copied 'name' value '${bodyObj.name}' to 'handle' as per W3C spec`);118 return await this.proxyFunc(url, method, {119 ...bodyObj,120 handle: bodyObj.name,121 });122 }123 if (this.downstreamProtocol === MJSONWP && _.has(bodyObj, 'handle') && !_.has(bodyObj, 'name')) {124 log.debug(`Copied 'handle' value '${bodyObj.handle}' to 'name' as per JSONWP spec`);125 return await this.proxyFunc(url, method, {126 ...bodyObj,127 name: bodyObj.handle,128 });129 }130 }131 return await this.proxyFunc(url, method, body);132 }133 async proxySetValue (url, method, body) {134 const bodyObj = util.safeJsonParse(body);135 if (_.isPlainObject(bodyObj) && (util.hasValue(bodyObj.text) || util.hasValue(bodyObj.value))) {136 let {text, value} = bodyObj;137 if (util.hasValue(text) && !util.hasValue(value)) {138 value = _.isString(text)139 ? [...text]140 : (_.isArray(text) ? text : []);141 log.debug(`Added 'value' property ${JSON.stringify(value)} to 'setValue' request body`);142 } else if (!util.hasValue(text) && util.hasValue(value)) {143 text = _.isArray(value)144 ? value.join('')145 : (_.isString(value) ? value : '');146 log.debug(`Added 'text' property ${JSON.stringify(text)} to 'setValue' request body`);147 }148 return await this.proxyFunc(url, method, Object.assign({}, bodyObj, {149 text,150 value,151 }));152 }153 return await this.proxyFunc(url, method, body);154 }155 async proxySetFrame (url, method, body) {156 const bodyObj = util.safeJsonParse(body);157 return _.has(bodyObj, 'id') && _.isPlainObject(bodyObj.id)158 ? await this.proxyFunc(url, method, {159 ...bodyObj,160 id: duplicateKeys(bodyObj.id, MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY),161 })162 : await this.proxyFunc(url, method, body);163 }164 async proxyPerformActions (url, method, body) {165 const bodyObj = util.safeJsonParse(body);166 return _.isPlainObject(bodyObj)167 ? await this.proxyFunc(url, method, duplicateKeys(bodyObj, MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY))168 : await this.proxyFunc(url, method, body);169 }170 /**171 * Handle "crossing" endpoints for the case172 * when upstream and downstream drivers operate different protocols173 *174 * @param {string} commandName175 * @param {string} url176 * @param {string} method177 * @param {?string|object} body178 * @returns The proxyfying result as [response, responseBody] tuple179 */180 async convertAndProxy (commandName, url, method, body) {181 if (!this.downstreamProtocol) {182 // Patch calls with GENERIC protocol183 // to preserve the backward compatibility184 const [res, resBodyObj] = await this.proxyFunc(url, method, body);185 return [res, formatStatus(resBodyObj, res.statusCode)];186 }187 // Same url, but different arguments188 switch (commandName) {189 case 'timeouts':190 return await this.proxySetTimeouts(url, method, body);191 case 'setWindow':192 return await this.proxySetWindow(url, method, body);193 case 'setValue':194 return await this.proxySetValue(url, method, body);195 case 'performActions':196 return await this.proxyPerformActions(url, method, body);197 case 'setFrame':198 return await this.proxySetFrame(url, method, body);199 default:200 break;201 }202 // Same arguments, but different URLs203 for (const {commandNames, jsonwpConverter, w3cConverter} of COMMAND_URLS_CONFLICTS) {204 if (!commandNames.includes(commandName)) {205 continue;206 }207 const rewrittenUrl = this.downstreamProtocol === MJSONWP208 ? jsonwpConverter(url)209 : w3cConverter(url);210 if (rewrittenUrl === url) {211 log.debug(`Did not know how to rewrite the original URL '${url}' ` +212 `for ${this.downstreamProtocol} protocol`);213 break;214 }215 log.info(`Rewrote the original URL '${url}' to '${rewrittenUrl}' ` +216 `for ${this.downstreamProtocol} protocol`);217 return await this.proxyFunc(rewrittenUrl, method, body);218 }219 // No matches found. Proceed normally220 return await this.proxyFunc(url, method, body);221 }222}...

Full Screen

Full Screen

cache.js

Source:cache.js Github

copy

Full Screen

1var Item = require('./item'),2 Proxy = require('./proxy'),3 sizeof = require('sizeof');4var popular = function(options){5 if (!(this instanceof popular))6 return new popular(options)7 if (typeof options === 'number')8 options = { maxSize: options }9 if(!options) options = {};10 this._maxAge = Number(options.maxAge);11 this._maxSize = Number(options.maxSize);12 this.reset();13}14popular.prototype.reset = function(){15 this._cache = {};16 this._hitList = [];17 this._topHitList = [];18 this._hits = 0;19 this._misses = 0;20}21popular.prototype.size = function() {22 return this._hitList.length;23}24popular.prototype.hits = function() {25 return this._hits;26}27popular.prototype.misses = function() {28 return this._misses;29}30popular.prototype.hitRate = function() {31 var total = this._hits + this._misses;32 return total ? this._hits / total : 0;33}34popular.prototype.memory = function(pretty) {35 return sizeof.sizeof(this._cache, pretty);36}37popular.prototype.set = function(key, value) {38 // null value can't be cached39 if(value == null) return false;40 if(this._cache.hasOwnProperty(key)){41 track(this, this._cache[key].value(value));42 }else{43 this.ensureSize();44 this._cache[key] = track(this, new Item(key, value));45 }46 return true;47}48popular.prototype.get = function(key) {49 if(!this._cache.hasOwnProperty(key)){50 this._misses++;51 return null;52 }53 var item = this._cache[key];54 // visiting out-dated item is not a hit55 // out-dated item is kept for future cache update.56 if(this.maxAgeEnabled() && item.age() > this._maxAge) return null;57 this._hits++;58 item = track(this, item, true);59 return item.value();60}61popular.prototype.del = function(key) {62 if(!this._cache.hasOwnProperty(key)) return false;63 if((pos = this._hitList.indexOf(key)) >= 0)64 this._hitList.splice(pos, 1);65 if((pos = this._topHitList.indexOf(key)) >= 0)66 this._topHitList.splice(pos, 1);67 delete this._cache[key];68 return true;69}70popular.prototype.clean = function() {71 if(this.maxAgeEnabled()){72 while(this._hitList.length > 073 && this._cache[this._hitList[0]].age() > this._maxAge){74 this.del(this._hitList.shift());75 }76 }77}78popular.prototype.ensureSize = function() {79 if(this._hitList.length >= this._maxSize){80 this.clean();81 }82 while(this._hitList.length >= this._maxSize){83 this.del(this._hitList.shift());;84 }85}86popular.prototype.maxAgeEnabled = function() {87 return this._maxAge >= 0;88}89popular.prototype.proxy = function(proxyFunc) {90 return new Proxy(this, proxyFunc);91}92popular.prototype.recent = function(callback, limit) {93 forEach(this, this._hitList, limit, callback);94}95popular.prototype.popular = function(callback, limit) {96 forEach(this, this._topHitList, limit, callback);97}98function forEach(self, list, limit, callback){99 if(!limit) limit = list.length;100 else limit = Math.min(limit, list.length);101 102 for(var i=1; i<=limit; i++){103 var key = list[list.length-i],104 item = self._cache[key];105 callback(key, item.value(), item.hit());106 }107}108function track(self, item, trackHit) {109 trackAccess(self, item);110 if(trackHit) trackHits(self, item);111 return item;112}113function trackAccess(self, item) {114 var pos = self._hitList.indexOf(item.key());115 if(pos < 0){116 self._hitList.push(item.key());117 }else{118 var records = self._hitList.splice(pos, 1);119 self._hitList.push(records[0]);120 }121}122function trackHits(self, item) {123 var hits = item.hit(true);124 var pos = self._topHitList.indexOf(item.key());125 if(pos < 0){126 self._topHitList.unshift(item.key());127 }else{128 while(pos+1<self._topHitList.length 129 && self._cache[self._topHitList[pos+1]].hit()<hits){130 self._topHitList[pos] = self._topHitList[pos+1];131 pos++;132 }133 self._topHitList[pos] = item.key();134 }135}...

Full Screen

Full Screen

builtin-entries.js

Source:builtin-entries.js Github

copy

Full Screen

1import Entry from "./entry.js"2import OwnProxy from "./own/proxy.js"3import builtinIds from "./builtin-ids.js"4import builtinModules from "./builtin-modules.js"5import instanceOf from "./util/instance-of.js"6import isUpdatableDescriptor from "./util/is-updatable-descriptor.js"7import isUpdatableGet from "./util/is-updatable-get.js"8import maskFunction from "./util/mask-function.js"9import proxyExports from "./util/proxy-exports.js"10import setDeferred from "./util/set-deferred.js"11import shared from "./shared.js"12const FuncHasInstance = Function.prototype[Symbol.hasInstance]13function createEntry(id) {14 const mod = builtinModules[id]15 let exported = mod.exports16 let unwrapped = exported17 const isFunc = typeof unwrapped === "function"18 if (isFunc &&19 id !== "assert") {20 const func = unwrapped21 const { prototype } = func22 const hasInstance = maskFunction(23 function (instance) {24 if ((this === exported ||25 this === proxyFunc) &&26 instance instanceof func) {27 return true28 }29 return instanceOf(instance, this)30 },31 FuncHasInstance32 )33 const proxyFunc = new OwnProxy(func, {34 get(func, name, receiver) {35 if (receiver === exported ||36 receiver === proxyFunc) {37 receiver = func38 }39 const value = Reflect.get(func, name, receiver)40 let newValue = value41 if (name === Symbol.hasInstance) {42 newValue = hasInstance43 } else if (value === func) {44 newValue = exported45 } else if (value === prototype) {46 newValue = proxyProto47 }48 if (newValue !== value &&49 isUpdatableGet(func, name)) {50 return newValue51 }52 return value53 },54 getOwnPropertyDescriptor(func, name) {55 const descriptor = Reflect.getOwnPropertyDescriptor(func, name)56 if (descriptor !== void 0 &&57 descriptor.value === prototype &&58 isUpdatableDescriptor(descriptor)) {59 descriptor.value = proxyProto60 }61 return descriptor62 }63 })64 const proxyProto = new OwnProxy(prototype, {65 get(prototype, name, receiver) {66 if (receiver === proxyProto) {67 receiver = prototype68 }69 const value = Reflect.get(prototype, name, receiver)70 if (value === func &&71 isUpdatableGet(prototype, name)) {72 return exported73 }74 return value75 },76 getOwnPropertyDescriptor(prototype, name) {77 const descriptor = Reflect.getOwnPropertyDescriptor(prototype, name)78 if (descriptor !== void 0 &&79 descriptor.value === func &&80 isUpdatableDescriptor(descriptor)) {81 descriptor.value = exported82 }83 return descriptor84 }85 })86 mod.exports = proxyFunc87 }88 const entry = Entry.get(mod)89 entry.builtin = true90 exported = proxyExports(entry)91 mod.exports = exported92 entry.exports = exported93 if (isFunc &&94 id === "module") {95 unwrapped.prototype.constructor = exported96 }97 entry.loaded()98 return entry99}100const builtinEntries = { __proto__: null }101const cache = shared.memoize.builtinEntries102for (const id of builtinIds) {103 setDeferred(builtinEntries, id, () => {104 const cached = cache.get(id)105 if (cached !== void 0) {106 return cached107 }108 const entry = createEntry(id)109 if (id !== "console" &&110 id !== "module" &&111 id !== "util") {112 cache.set(id, entry)113 }114 return entry115 })116}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = require('./test.js');2var testObj = new test();3testObj.proxyFunc();4var test = function(){5 this.proxyFunc = function(){6 console.log("proxyFunc called");7 }8}9module.exports = test;10Your name to display (optional):11Your name to display (optional):12var test = require('./test.js');13var testObj = new test();14testObj.proxyFunc();

Full Screen

Using AI Code Generation

copy

Full Screen

1var Appium = require('appium');2var appium = new Appium();3appium.startServer();4appium.on('newSession', function (driver) {5driver.proxyFunc = function (cb) {6cb();7};8});9appium.on('command', function (driver, commandName, args) {10});11appium.on('commandComplete', function (driver, commandName, args) {12});13appium.on('quit', function (driver) {14});15appium.on('shutdown', function () {16});17appium.on('error', function (err) {18});19var Appium = require('appium');20var appium = new Appium();21appium.startServer();22appium.on('newSession', function (driver) {23driver.proxyFunc = function (cb) {24cb();25};26});27appium.on('command', function (driver, commandName, args) {28});29appium.on('commandComplete', function (driver, commandName, args) {30});31appium.on('quit', function (driver) {32});33appium.on('shutdown', function () {34});35appium.on('error', function (err) {36});37var Appium = require('appium');38var appium = new Appium();39appium.startServer();40appium.on('newSession', function (driver) {41driver.proxyFunc = function (cb) {42cb();43};44});45appium.on('command', function (driver, commandName, args) {46});47appium.on('commandComplete', function (driver, commandName, args) {48});49appium.on('quit', function (driver) {50});51appium.on('shutdown', function () {52});53appium.on('error', function (err) {54});55var Appium = require('app

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', async () => {3 await driver.proxyFunc('GET', '/test', {test: 'test'});4 });5});6var logs = await driver.proxy('GET', '/logs');7await driver.proxyFunc('GET', '/test', {test: 'test'});8await driver.proxyFunc('GET', '/test', {test: 'test'});9var logs = await driver.proxy('GET', '/logs');

Full Screen

Using AI Code Generation

copy

Full Screen

1import BaseDriver from 'appium-base-driver';2let driver = new BaseDriver({3});4driver.proxyFunc('/session', 'POST', {desiredCapabilities: {}});5driver.proxyCommand('/session', 'POST', {desiredCapabilities: {}});6driver.proxyCommand('/session', 'POST', {desiredCapabilities: {}});7driver.proxyCommand('/session', 'POST', {desiredCapabilities: {}});

Full Screen

Using AI Code Generation

copy

Full Screen

1async proxyFunc (url, method, body) {2 return await this.proxyCommand(url, method, body);3 }4async proxyCommand (url, method, body) {5 return await this.proxyReqRes.proxyCommand(url, method, body);6 }7async proxyCommand (url, method, body) {8 return await this.proxy(url, method, body);9 }10async proxy (url, method, body) {11 return await this.jwpProxy.command(url, method, body);12 }13async command (url, method, body) {14 return await this.proxy(url, method, body);15 }16async proxy (url, method, body) {17 return await this.doJwpProxy(url, method, body);18 }19async doJwpProxy (url, method, body) {20 return await this.doRequest(url, method, body);21 }22async doRequest (url, method, body) {23 return await this.requester.request(url, method, body);24 }25async request (url, method, body) {26 return await this.doRequest(url, method, body);27 }28async doRequest (url, method, body) {29 return await superagent[method](url).send(body);30 }31async request (url, method, body) {32 return await this.doRequest(url, method, body);33 }

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