How to use getDeviceInfo method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

Discovery.js

Source:Discovery.js Github

copy

Full Screen

...146 if(this.removeTimeout) clearTimeout(this.removeTimeout);147 this.removeTimeout = setTimeout(function(){148 this.pairingRef.off('child_added');149 this.pairingRef.off('value');150 this.pairingRef.child(this.getDeviceInfo().deviceID).remove();151 }.bind(this), delayTime);152 }153 function _selectPairMembers(){154 var thisInfo = _.find(this.pairing.candidates, function(candidate){155 return (candidate.deviceID == this.getDeviceInfo().deviceID);156 }.bind(this));157 if(thisInfo){158 this.pairing.pairedMembers = this.pairing.candidates.filter(function(candidate){159 if (candidate.deviceID == this.getDeviceInfo().deviceID) return false;160 if (this.options.method == "code") {161 return (candidate.code && thisInfo.code==candidate.code);162 } else {163 return Math.abs(candidate.serverTime - thisInfo.serverTime) <= this.options.paringTolerance;164 }165 }.bind(this));166 _createRoom.call(this, thisInfo);167 }else{168 // err169 }170 this.pairing.candidates = [];171 }172 function _createRoom(thisInfo){173 this.roomRef = null;174 if(this.pairing.pairedMembers.length == 1){175 // todo roomId indicates connections each device already have , in the room they have communication info176 // todo latter by checking whether they have same roomId determine whether they already connected177 var candidate = this.pairing.pairedMembers[0];178 if(candidate.channelID && thisInfo.channelID) {179 // TODO180 }181 else if((candidate.channelID || thisInfo.channelID) &&182 (! candidate.isHost && ! thisInfo.isHost)){183 if(this.allowMesh){184 _joinChannel.call(this, thisInfo);185 }else{186 var host = candidate.host ? candidate.host: thisInfo.host;187 this.failCallback(host);188 }189 }else{190 _findHost.call(this, thisInfo);191 _createChannel.call(this, thisInfo);192 }193 }else{194 if(this.roomRef) this.failCallback("more then one device is pairing");195 }196 }197 function _joinChannel(thisInfo){198 var id = "";199// var id = Math.min(this.pairing.pairedMembers[0].serverTime, thisInfo.serverTime)+ "ID_ip";200 if(thisInfo.channelID){201 id = this.pairing.pairedMembers[0].deviceID;202 }else{203 id = thisInfo.deviceID;204 }205 this.getDeviceInfo().roomId = id;206 this.roomRef = new Firebase(this.rootUrl + "connected/" + id);207 this.roomRef.onDisconnect().remove();208 if(thisInfo.channelID){209 var info = {};210 info.connectionID = demobo.Utils.guid();211 info.host = this.getDeviceInfo().host;212 info.layers = this.getDeviceInfo().layers;213 info.channelID = this.getDeviceInfo().channelID;214 info.hostInfo = this.getDeviceInfo().hostInfo;215 info = _.compactObject(info);216 this.roomRef.update(info, function(){217 function roomOnValue(nodeData){218 var nodeObj = nodeData.val();219 if (!nodeObj || !nodeObj.guest) return;220 this.roomRef.off('value', this.roomOnValue);221 this.successCallback(nodeObj);222 }223 this.roomOnValue = roomOnValue.bind(this);224 this.roomRef.on('value', this.roomOnValue);225 }.bind(this));226 }else{227 _doGuestStuff.call(this);228 }229 }230 function _createChannel(thisInfo){231 // TODO some time guest do not write data232 var id = "";233// var id = Math.min(this.pairing.pairedMembers[0].serverTime, thisInfo.serverTime)+ "ID_ip";234 if(this.getDeviceInfo().isHost){235 id = this.pairing.pairedMembers[0].deviceID;236 }else{237 id = thisInfo.deviceID;238 }239 this.getDeviceInfo().roomId = id;240 this.roomRef = new Firebase(this.rootUrl + "connected/" + id);241 this.roomRef.onDisconnect().remove();242 if(this.getDeviceInfo().isHost){243 var info = {};244 if(! this.getDeviceInfo().channelID) {245 this.getDeviceInfo().channelID = demobo.Utils.guid();246 }247 info.channelID = this.getDeviceInfo().channelID;248 info.connectionID = demobo.Utils.guid();249 info.host = this.getDeviceInfo().deviceID;250 info.hostInfo = {};251 info.hostInfo["internalIP"] = this.getDeviceInfo().internalIP || "";252 info.hostInfo["userAgent"] = this.getDeviceInfo().userAgent || "";253 this.getDeviceInfo().hostInfo = info.hostInfo;254 info.layers = this.getDeviceInfo().layers;255 info = _.compactObject(info);256 this.roomRef.update(info, function(){257 function roomOnValue(nodeData){258 var nodeObj = nodeData.val();259 if (!nodeObj || !nodeObj.guest) return;260 this.roomRef.off('value', this.roomOnValue);261 this.successCallback(nodeObj);262 }263 this.roomOnValue = roomOnValue.bind(this);264 this.roomRef.on('value', this.roomOnValue);265 }.bind(this));266 }else{267 _doGuestStuff.call(this);268 }269 }270 function _doGuestStuff(){271 function roomOnValue(nodeData){272 var nodeObj = nodeData.val();273 if (!nodeObj) return;274 var layers = nodeObj.layers;275 nodeObj.layers = _.intersection(layers, this.getDeviceInfo().layers);276 nodeObj.guest = this.getDeviceInfo().deviceID;277 this.roomRef.off('value', this.roomOnValue);278 this.getDeviceInfo().host = nodeObj.host;279 this.getDeviceInfo().channelID = nodeObj.channelID;280 this.getDeviceInfo().hostInfo = nodeObj.hostInfo;281 nodeObj = _.compactObject(nodeObj);282 this.roomRef.update(nodeObj);283 this.successCallback(nodeObj);284 };285 this.roomOnValue = roomOnValue.bind(this);286 this.roomRef.on('value',this.roomOnValue);287 }288 function _findHost(thisInfo){289 var candidate = this.pairing.pairedMembers[0];290 if((thisInfo.isHost && !candidate.isHost) || (! thisInfo.isHost && candidate.isHost)){291 return;292 }293 var isThisMobile = this.isMobile();294 var isPairedMobile = this.isAgentMobile(candidate.userAgent);295 if((isPairedMobile && isThisMobile) ||(! isPairedMobile && ! isThisMobile) ){296 this.getDeviceInfo().isHost = thisInfo.serverTime <= candidate.serverTime;297 }else if(isPairedMobile && !isThisMobile){298 this.getDeviceInfo().isHost = true;299 }else if(! isPairedMobile && isThisMobile){300 this.getDeviceInfo().isHost = false;301 }302// this.deviceInfo.isHost = this.isHost;303 }304 function _updateClientInfoTo(ref){305 if(! ref) return;306 var deviceInfoClone = _.compactObject(this.getDeviceInfo());307 deviceInfoClone.serverTime = Firebase.ServerValue.TIMESTAMP;308 var clientInfo = {};309 clientInfo[deviceInfoClone.deviceID] = deviceInfoClone;310 clientInfo = _.compactObject(clientInfo);311 ref.update(clientInfo);312 }313 function _addFirebaseListeners(){314 this.pairingRef.off('child_added');315 this.pairingRef.off('value');316 if (this.options.method=="code" && this.isHost()) {317 this.pairingRef.on('child_added', function(){318 setTimeout(function(){319 this.pairingRef.once('value', function(firebaseNodeData){320 this.onPairHandler(firebaseNodeData);321 _selectPairMembers.call(this);322 }.bind(this));323 }.bind(this), this.options.paringTolerance);324 }.bind(this));325 } else {326 this.pairingRef.once('child_added', function(){327 setTimeout(function(){328 this.pairingRef.once('value', function(firebaseNodeData){329 this.onPairHandler(firebaseNodeData);330 _selectPairMembers.call(this);331 }.bind(this));332 }.bind(this), this.options.paringTolerance);333 }.bind(this));334 }335 }336 Discovery.prototype.getDeviceInfo = function () {337 return this.deviceInfo;338 };339 Discovery.prototype.getDeviceID = function () {340 return this.deviceInfo.deviceID;341 };342 Discovery.prototype.isMobile = function () {343 return navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/);344 };345 Discovery.prototype.isAgentMobile = function (agent) {346 return agent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/);347 };348 Discovery.prototype.getAvailableLayers = function () {349 var layers = ["firebase"];350 layers.unshift("websocket:8010");351 layers.unshift("websocket:80");352 if (typeof webrtcDetectedBrowser != 'undefined' && webrtcDetectedBrowser)353 layers.unshift("webrtc");354 if(this.isMobile()){355 if (typeof Alljoyn != 'undefined')356 layers.unshift("alljoyn");357 }358 return layers;359 };360 Discovery.prototype.isSyncHost = function(){361 return this.options.isSyncHost;362 };363 Discovery.prototype.isHost = function(){364 return this.getDeviceInfo().isHost;365 };366 Discovery.prototype.getIPAddress = function(){367 // TODO if cannot get IP368 return this.getDeviceInfo().internalIP;369 };370 Discovery.prototype.getHostIPAddress = function(){371 // TODO if cannot get IP372 return this.getDeviceInfo().hostInfo.internalIP;373 };374 Discovery.prototype.isServer = function(){375 // TODO if cannot get IP376 return this.getDeviceInfo().hostInfo.internalIP === this.getDeviceInfo().internalIP;377 };378 Discovery.prototype.getRoomID = function () {379 // override this method to add more parameters for hashing in the future380 var id = this.deviceInfo.externalID.replace(/\./g,'dot');381 return id;382 };383 Discovery.prototype.onPairingTrigger = function () {384 _addFirebaseListeners.call(this);385 _updateClientInfoTo.call(this, this.pairingRef);386 if (!this.getDeviceInfo().isHost) _removePairingRef.call(this, this.options.dataKeptTime);387 if (this.onPairing) {388 this.onPairing();389 this.pairingTimeout = setTimeout(this.onTimeout, this.options.timeout);390 }391 };392 //----------------- Start of Bump Pairing Methods -----------------//393 Discovery.prototype.startBumpPairing = function(){394 if (!this.deviceInfo.externalID) return;395 var roomURL = this.pairingUrl + this.getRoomID();396 this.pairingRef = new Firebase(roomURL);397 if (this.isMobile()) {398 _addVolumeButtonListener.call(this);399 // _addBumpListener.call(this);400 }401 else {402 _addSpaceBarListener.call(this);403 }404 };405 Discovery.prototype.endBumpPairing = function(){406 _removePairingRef.call(this, 0);407 if (this.isMobile()) {408 _removeVolumeButtonListener.call(this);409 // _removeBumpListener.call(this);410 }411 else {412 _removeSpaceBarListener.call(this);413 }414 };415 //----------------- End of Bump Pairing Methods -----------------//416 //----------------- Start of Code Pairing Methods -----------------//417 Discovery.prototype.startCodePairing = function(){418 if (!this.deviceInfo.externalID) return;419 var roomURL = this.pairingUrl + this.getRoomID();420 this.pairingRef = new Firebase(roomURL);421 if (this.isMobile()) {422 var code = this.options.code || Math.random().toString(36).substr(2, 4);423 this.pairingRef.on('value', function (allSnapshot){424 allSnapshot.forEach(function (snapshot) {425 if (snapshot.val().code==code)426 snapshot.ref.remove();427 });428 this.enterCode(code);429 }.bind(this));430 }431 };432 Discovery.prototype.endCodePairing = function(){433 _removePairingRef.call(this, 0);434 };435 Discovery.prototype.enterCode = function(code){436 this.deviceInfo.code = code;437 this.onPairingTrigger();438 };439 Discovery.prototype.connectWIFI = function(internalIP) {440 if (!configs.dev) {441 var channelObj = {442 "channelID":"1ae5d720-6a9f-bb3a-24b4-086811a42d7c",443 "connectionID":"a4e79935-ee0f-8766-da06-6c06d510492e",444 "host":"mobile",445 "hostInfo":{446 "internalIP":internalIP447 },448 "layers":["websocket:8020"],449 "guest":"web",450 "roomId":"web"451 };452 demobo.communicationLayer.remove(channelObj);453 this.getDeviceInfo().roomId = channelObj.roomId;454 this.getDeviceInfo().host = channelObj.host;455 this.getDeviceInfo().channelID = channelObj.channelID;456 this.getDeviceInfo().hostInfo = channelObj.hostInfo;457 demobo.communicationLayer.options.timeout = null;458 demobo.communicationLayer.add(channelObj, this.onSuccess, this.onFailure);459 console.log('connectWIFI');460 }461 };462 //----------------- End of Code Pairing Methods -----------------//463 //-----------------------------------------------------464// Discovery.prototype.enableSampleCollect = function(){465// simpleBump.enableSampleCollect();466// };467//468// Discovery.prototype.disableSampleCollect = function(){469// simpleBump.disableSampleCollect();470// };...

Full Screen

Full Screen

device.js

Source:device.js Github

copy

Full Screen

...13 });14 });15 function testBoolean(device, name, vendorsToSkip = []) {16 skip().vendor(...vendorsToSkip).it(name + ' should return a boolean', function (done) {17 let val = cl.getDeviceInfo(device, cl[name.toUpperCase()]);18 assert.isBoolean(val);19 done();20 });21 }22 function testInteger(device, name, vendorsToSkip = []) {23 skip().vendor(...vendorsToSkip).it(name + ' should return an integer', function (done) {24 let val = cl.getDeviceInfo(device, cl[name.toUpperCase()]);25 assert.isNumber(val);26 done();27 });28 }29 function testString(device, name, vendorsToSkip = []) {30 skip().vendor(...vendorsToSkip).it(name + ' should return a string', function (done) {31 let val = cl.getDeviceInfo(device, cl[name.toUpperCase()]);32 assert.isString(val);33 done();34 });35 }36 function testObject(device, name, vendorsToSkip = []) {37 skip().vendor(...vendorsToSkip).it(name + ' should return an object', function () {38 let info = cl.getDeviceInfo(device, cl[name.toUpperCase()]);39 assert.isObject(info);40 });41 }42 function testArray(device, name, vendorsToSkip = []) {43 skip().vendor(...vendorsToSkip).it(name + ' should return an array', function (done) {44 let val = cl.getDeviceInfo(device, cl[name.toUpperCase()]);45 assert.isArray(val);46 done();47 });48 }49 function test64Array(device, name, vendorsToSkip = []) {50 skip().vendor(...vendorsToSkip).it(name + ' should return a 2 integers array', function (done) {51 let val = cl.getDeviceInfo(device, cl[name.toUpperCase()]);52 assert.isArray(val);53 assert.isNumber(val[0]);54 assert.isNumber(val[1]);55 done();56 });57 }58 function testDevice(device) {59 let deviceVendor = cl.getDeviceInfo(device, cl.DEVICE_VENDOR);60 let deviceName = cl.getDeviceInfo(device, cl.DEVICE_NAME);61 describe('#getDeviceInfo() for ' + deviceVendor + ' ' + deviceName, function () {62 testString(device, 'DEVICE_NAME');63 testString(device, 'DEVICE_VENDOR');64 testString(device, 'DEVICE_PROFILE');65 testString(device, 'DEVICE_VERSION');66 testString(device, 'DEVICE_OPENCL_C_VERSION');67 testString(device, 'DEVICE_EXTENSIONS');68 // testString(device, "DEVICE_BUILT_IN_KERNELS");69 // testString(device, "DEVICE_SPIR_VERSIONS");70 testString(device, 'DRIVER_VERSION');71 let ext = cl.getDeviceInfo(device, cl.DEVICE_EXTENSIONS);72 let hasFP16 = ext.toLowerCase().match(/cl_khr_fp16/g);73 let hasFP64 = ext.toLowerCase().match(/cl_khr_fp64/g);74 testObject(device, 'DEVICE_PLATFORM');75 testInteger(device, 'DEVICE_TYPE');76 testInteger(device, 'DEVICE_LOCAL_MEM_TYPE');77 testInteger(device, 'DEVICE_GLOBAL_MEM_CACHE_TYPE');78 testInteger(device, 'DEVICE_EXECUTION_CAPABILITIES');79 testInteger(device, 'DEVICE_QUEUE_PROPERTIES');80 if (hasFP16) testInteger(device, 'DEVICE_HALF_FP_CONFIG');81 testInteger(device, 'DEVICE_SINGLE_FP_CONFIG');82 if (hasFP64) testInteger(device, 'DEVICE_DOUBLE_FP_CONFIG');83 testArray(device, 'DEVICE_MAX_WORK_ITEM_SIZES');84 testBoolean(device, 'DEVICE_AVAILABLE');85 testBoolean(device, 'DEVICE_COMPILER_AVAILABLE');86 testBoolean(device, 'DEVICE_ENDIAN_LITTLE');87 testBoolean(device, 'DEVICE_ERROR_CORRECTION_SUPPORT');88 testBoolean(device, 'DEVICE_HOST_UNIFIED_MEMORY');89 testBoolean(device, 'DEVICE_IMAGE_SUPPORT');90 // testBoolean(device, "DEVICE_LINKER_AVAILABLE");91 // testBoolean(device, "DEVICE_PREFERRED_INTEROP_USER_SYNC");92 // testInteger(device, "DEVICE_IMAGE_PITCH_ALIGNMENT");93 testInteger(device, 'DEVICE_ADDRESS_BITS');94 testInteger(device, 'DEVICE_GLOBAL_MEM_CACHELINE_SIZE');95 testInteger(device, 'DEVICE_MAX_CLOCK_FREQUENCY');96 testInteger(device, 'DEVICE_MAX_COMPUTE_UNITS');97 testInteger(device, 'DEVICE_MAX_CONSTANT_ARGS');98 testInteger(device, 'DEVICE_MAX_READ_IMAGE_ARGS');99 testInteger(device, 'DEVICE_MAX_SAMPLERS');100 testInteger(device, 'DEVICE_MAX_WORK_ITEM_DIMENSIONS');101 testInteger(device, 'DEVICE_MAX_WRITE_IMAGE_ARGS');102 testInteger(device, 'DEVICE_MEM_BASE_ADDR_ALIGN');103 testInteger(device, 'DEVICE_MIN_DATA_TYPE_ALIGN_SIZE');104 testInteger(device, 'DEVICE_NATIVE_VECTOR_WIDTH_CHAR');105 testInteger(device, 'DEVICE_NATIVE_VECTOR_WIDTH_SHORT');106 testInteger(device, 'DEVICE_NATIVE_VECTOR_WIDTH_INT');107 testInteger(device, 'DEVICE_NATIVE_VECTOR_WIDTH_LONG');108 testInteger(device, 'DEVICE_NATIVE_VECTOR_WIDTH_FLOAT');109 testInteger(device, 'DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE');110 testInteger(device, 'DEVICE_NATIVE_VECTOR_WIDTH_HALF');111 testInteger(device, 'DEVICE_PREFERRED_VECTOR_WIDTH_CHAR');112 testInteger(device, 'DEVICE_PREFERRED_VECTOR_WIDTH_SHORT');113 testInteger(device, 'DEVICE_PREFERRED_VECTOR_WIDTH_INT');114 testInteger(device, 'DEVICE_PREFERRED_VECTOR_WIDTH_LONG');115 testInteger(device, 'DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT');116 testInteger(device, 'DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE');117 testInteger(device, 'DEVICE_PREFERRED_VECTOR_WIDTH_HALF');118 testInteger(device, 'DEVICE_VENDOR_ID');119 // testInteger(device, "DEVICE_MAX_GLOBAL_VARIABLE_SIZE");120 // testInteger(device, "DEVICE_MAX_ON_DEVICE_EVENTS");121 // testInteger(device, "DEVICE_MAX_ON_DEVICE_QUEUES");122 testInteger(device, 'DEVICE_REFERENCE_COUNT');123 testInteger(device, 'DEVICE_PARTITION_MAX_SUB_DEVICES');124 test64Array(device, 'DEVICE_GLOBAL_MEM_CACHE_SIZE');125 test64Array(device, 'DEVICE_GLOBAL_MEM_SIZE');126 test64Array(device, 'DEVICE_LOCAL_MEM_SIZE');127 test64Array(device, 'DEVICE_MAX_CONSTANT_BUFFER_SIZE');128 test64Array(device, 'DEVICE_MAX_MEM_ALLOC_SIZE');129 // testInteger(device, "DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE");130 // testInteger(device, "DEVICE_PRINTF_BUFFER_SIZE");131 testInteger(device, 'DEVICE_IMAGE2D_MAX_HEIGHT');132 testInteger(device, 'DEVICE_IMAGE2D_MAX_WIDTH');133 testInteger(device, 'DEVICE_IMAGE3D_MAX_DEPTH');134 testInteger(device, 'DEVICE_IMAGE3D_MAX_HEIGHT');135 testInteger(device, 'DEVICE_IMAGE3D_MAX_WIDTH');136 // testInteger(device, "DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT");137 testInteger(device, 'DEVICE_MAX_PARAMETER_SIZE');138 testInteger(device, 'DEVICE_MAX_WORK_GROUP_SIZE');139 testInteger(device, 'DEVICE_PROFILING_TIMER_RESOLUTION');140 // testInteger(device, "DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT");141 // testInteger(device, "DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT");142 // testInteger(device, "DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT");143 // testInteger(device, "DEVICE_QUEUE_ON_DEVICE_MAX_SIZE");144 // testInteger(device, "DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE");145 testInteger(device, 'DEVICE_IMAGE_MAX_BUFFER_SIZE');146 testInteger(device, 'DEVICE_IMAGE_MAX_ARRAY_SIZE');147 //// negative test cases148 it('should throw cl.INVALID_VALUE with name=-123.56', function () {149 const getInfoBound = cl.getDeviceInfo.bind(cl, device,-123.56);150 expect(getInfoBound).to.throw(cl.INVALID_VALUE.message);151 });152 it('should throw cl.INVALID_VALUE with name=\'a string\'', function () {153 const getInfoBound = cl.getDeviceInfo.bind(cl, device,'a string');154 expect(getInfoBound).to.throw('Argument 1 must be of type `Uint32`');155 });156 it('should throw cl.INVALID_VALUE with name=123456', function () {157 const getInfoBound = cl.getDeviceInfo.bind(cl, device, 123456);158 expect(getInfoBound).to.throw(cl.INVALID_VALUE.message);159 });160 it('should throw cl.INVALID_DEVICE with device = null', function () {161 const getInfoBound = cl.getDeviceInfo.bind(cl, null, 123);162 expect(getInfoBound).to.throw('Argument 0 must be of type `Object`');163 });164 it('should throw cl.INVALID_DEVICE with device = \'a string\'', function () {165 const getInfoBound = cl.getDeviceInfo.bind(cl,'a string', 123);166 expect(getInfoBound).to.throw('Argument 0 must be of type `Object`');167 });168 it('should throw cl.INVALID_DEVICE with device = 123', function () {169 const getInfoBound = cl.getDeviceInfo.bind(cl, 123, 123);170 expect(getInfoBound).to.throw('Argument 0 must be of type `Object`');171 });172 it('should throw cl.INVALID_DEVICE with device = [1, 2, 3]', function () {173 const getInfoBound = cl.getDeviceInfo.bind(cl,[1, 2, 3], 123);174 expect(getInfoBound).to.throw('Argument 0 must be a CL Wrapper.');175 });176 it('should throw cl.INVALID_DEVICE with device = new Array()', function () {177 const getInfoBound = cl.getDeviceInfo.bind(cl,[], 123);178 expect(getInfoBound).to.throw('Argument 0 must be a CL Wrapper.');179 });180 });181 describe('#createSubDevices() for ' + deviceVendor + ' ' + deviceName, function () {182 let num = cl.getDeviceInfo(device, cl.DEVICE_PARTITION_MAX_SUB_DEVICES);183 cl.getDeviceInfo(device, cl.DEVICE_VENDOR);184 if (num > 0)185 {186 skip().device('AMD').os('darwin').it('should return an array of sub-devices', function () {187 let subDevices;188 try {189 cl.createSubDevices(190 device,191 [192 cl.DEVICE_PARTITION_BY_COUNTS,193 3,194 1,195 cl.DEVICE_PARTITION_BY_COUNTS_LIST_END,196 0197 ],198 2199 );200 assert.isArray(subDevices);201 assert.isAbove(subDevices.length, 0);202 } catch (error) {203 if (error.message === cl.DEVICE_PARTITION_FAILED.message) {204 assert.isTrue(true);205 }206 }207 });208 }209 if (num > 0)210 {211 skip().device('AMD').os('darwin').it('should return an array of sub-devices', function () {212 let subDevices;213 try {214 cl.createSubDevices(device, [cl.DEVICE_PARTITION_EQUALLY, 8, 0], 2);215 assert.isArray(subDevices);216 assert.isAbove(subDevices.length, 0);217 } catch (error) {218 if (error.message === cl.DEVICE_PARTITION_FAILED.message) {219 assert.isTrue(true);220 }221 }222 });223 }224 if (num > 0)225 {226 skip().device('AMD').os('darwin').it('should return an array of sub-devices', function () {227 let subDevices;228 try {229 cl.createSubDevices(230 device,231 [232 cl.DEVICE_PARTITION_BY_AFFINITY_DOMAIN,233 cl.DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE,234 0235 ],236 2237 );238 assert.isArray(subDevices);239 assert.isAbove(subDevices.length, 0);240 } catch (error) {241 if (error.message === cl.DEVICE_PARTITION_FAILED.message) {242 assert.isTrue(true);243 }244 }245 });246 }247 it('should throw cl.INVALID_DEVICE with device = null', function () {248 const createBound = cl.createSubDevices.bind(249 cl,250 null,251 [cl.DEVICE_PARTITION_EQUALLY, 8, 0],252 2253 );254 expect(createBound).to.throw('Argument 0 must be of type `Object`');255 });256 it('should throw cl.INVALID_VALUE with properties = null', function () {257 const createBound = cl.createSubDevices.bind(cl, device, null, 2);258 expect(createBound).to.throw('Argument 1 must be of type `Array`');259 });260 });261 describe('#retainDevice() for ' + deviceVendor + ' ' + deviceName, function () {262 it('should throw cl.INVALID_DEVICE if device is not a subdevice', function () {263 const retainBound = cl.retainDevice.bind(cl, device);264 expect(retainBound).to.throw(cl.INVALID_DEVICE.message);265 });266 it('should increase device reference count', function () {267 try {268 let subDevice = cl.createSubDevices(device, cl.DEVICE_PARTITION_BY_COUNTS, 2);269 cl.retainDevice(subDevice);270 let count = cl.getDeviceInfo(subDevice, cl.DEVICE_REFERENCE_COUNT);271 assert.strictEqual(count, 2);272 cl.releaseDevice(subDevice);273 } catch (error) {274 if (error.message === cl.DEVICE_PARTITION_FAILED.message) {275 assert.isTrue(true);276 }277 }278 });279 });280 describe('#releaseDevice() for ' + deviceVendor + ' ' + deviceName, function () {281 it('should throw cl.INVALID_DEVICE if device is not a subdevice', function () {282 const retainBound = cl.releaseDevice.bind(cl, device);283 expect(retainBound).to.throw(cl.INVALID_DEVICE.message);284 });285 it('should decrease device reference count', function () {286 try {287 let subDevice = cl.createSubDevices(device, cl.DEVICE_PARTITION_BY_COUNTS, 2);288 cl.retainDevice(subDevice);289 let count = cl.getDeviceInfo(subDevice, cl.DEVICE_REFERENCE_COUNT);290 assert.strictEqual(count, 2);291 cl.releaseDevice(subDevice);292 count = cl.getDeviceInfo(subDevice, cl.DEVICE_REFERENCE_COUNT);293 assert.strictEqual(count, 1);294 } catch (error) {295 if (error.message === cl.DEVICE_PARTITION_FAILED.message) {296 assert.isTrue(true);297 }298 }299 });300 });301 }302 testDevice(global.MAIN_DEVICE);...

Full Screen

Full Screen

getDeviceInfo.test.js

Source:getDeviceInfo.test.js Github

copy

Full Screen

...30 })31 it('should be able to get the default device info for the initial run', async () => {32 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(false)33 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(false)34 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()35 expect(getScreenshotSizeSpy).toBeCalledWith(IMAGE_STRING)36 expect(global.driver.getWindowSize).toHaveBeenCalled()37 expect(determineIphoneXSeriesSpy).toBeCalledWith(screenData)38 expect(determineLargeIphoneXSeriesSpy).toBeCalledWith(screenData)39 })40 it('should be able to get the default device info for the second run', async () => {41 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(false)42 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(false)43 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()44 expect(getScreenshotSizeSpy).toBeCalledWith(IMAGE_STRING)45 expect(global.driver.getWindowSize).toHaveBeenCalled()46 expect(determineIphoneXSeriesSpy).toBeCalledWith(screenData)47 expect(determineLargeIphoneXSeriesSpy).toBeCalledWith(screenData)48 getScreenshotSizeSpy.mockRestore()49 determineIphoneXSeriesSpy.mockRestore()50 determineLargeIphoneXSeriesSpy.mockRestore()51 global.driver = {52 getWindowSize: jest.fn().mockRestore(),53 }54 // The second run to check that the data is stored in the `DEVICE_INFO` and all methods are not called again55 global.driver = {56 getWindowSize: jest.fn().mockResolvedValue(screenData),57 }58 getScreenshotSizeSpy = jest.spyOn(Utils, 'getScreenshotSize').mockReturnValue({59 width: 1000,60 height: 2000,61 })62 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(false)63 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(false)64 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()65 expect(getScreenshotSizeSpy).not.toHaveBeenCalled()66 expect(global.driver.getWindowSize).not.toHaveBeenCalled()67 expect(determineIphoneXSeriesSpy).not.toHaveBeenCalled()68 expect(determineLargeIphoneXSeriesSpy).not.toHaveBeenCalled()69 })70 it('should be able to get the device info for an iPhone X', async () => {71 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(true)72 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(false)73 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()74 })75 it('should be able to get the device info for an iPhone X Large', async () => {76 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(false)77 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(true)78 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()79 })80 it('should be able to get the device info for a landscape phone', async () => {81 global.driver = {82 capabilities: {},83 getWindowSize: jest.fn().mockResolvedValue({84 width: 1000,85 height: 500,86 }),87 }88 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()89 })90 it('should be able to get the device info an Android phone', async () => {91 global.driver = {92 capabilities: {93 pixelRatio: 2.75,94 statBarHeight: 66,95 viewportRect: { left: 0, top: 66, width: 1000, height: 1802 }96 },97 getWindowSize: jest.fn().mockResolvedValue({98 width: 1000,99 height: 2000,100 }),101 }102 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()103 })...

Full Screen

Full Screen

servicelib.js

Source:servicelib.js Github

copy

Full Screen

...161 }162 })163 };164}165export function getDeviceInfo(code) {166 console.log(code);167 return {168 types: [GETDEVICEINFO, GETDEVICEINFO_SUCCESS, GETDEVICEINFO_FAIL],169 // wechat: client => client.get("/repair/get_repair_record", {170 // urlParams: {171 // "user_id": 1,172 // "state": 1173 // }174 // })175 };176}177178export function returnSearch() {179 return { ...

Full Screen

Full Screen

tracker.js

Source:tracker.js Github

copy

Full Screen

...14 }15 }16 };17 try{18 getDeviceInfo = JSON.parse(MiFiJsInternal.getDeviceInfo());19 }catch(e){}20 getDeviceInfo.productType =cfg.productType||'loan';21 getDeviceInfo.t = new Date().getTime();22 getDeviceInfo.from=getParam('from')||'local';23 getDeviceInfo.source=getParam('source')||'index';24 for(var k in cfg){25 if(k == "pageTitle"){26 getDeviceInfo[k] = encodeURIComponent(cfg[k]);27 }else{28 getDeviceInfo[k] = cfg[k];29 }30 }31 try{32 if (MiFiJsInternal && MiFiJsInternal.recordCountEvent) {...

Full Screen

Full Screen

mobiledetection.service.spec.js

Source:mobiledetection.service.spec.js Github

copy

Full Screen

...14 });15 it('should be registered', () => {16 expect(MobileDetection).toBeDefined();17 });18 describe('Function: getDeviceInfo()', () => {19 it('should detect iOS.', () => {20 $window.navigator = {21 userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13C75 Safari/601.1'22 };23 expect(MobileDetection.getDeviceInfo().os.ios).toBeTruthy();24 expect(MobileDetection.getDeviceInfo().os.mac).toBeTruthy();25 expect(MobileDetection.getDeviceInfo().browser.safari).toBeTruthy();26 });27 it('should detect Safari and not iOS.', () => {28 $window.navigator = {29 userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9'30 };31 expect(MobileDetection.getDeviceInfo().os.ios).toBeFalsy();32 expect(MobileDetection.getDeviceInfo().os.mac).toBeTruthy();33 expect(MobileDetection.getDeviceInfo().browser.safari).toBeTruthy();34 });35 it('should detect chrome.', () => {36 $window.navigator = {37 userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'38 };39 expect(MobileDetection.getDeviceInfo().os.ios).toBeFalsy();40 expect(MobileDetection.getDeviceInfo().os.mac).toBeTruthy();41 expect(MobileDetection.getDeviceInfo().browser.safari).toBeFalsy();42 });43 });44 describe('Function: deepRegex()', () => {45 it('should be defined.', () => {46 expect(MobileDetection.deepRegex).toBeDefined();47 });48 });...

Full Screen

Full Screen

device-info.js

Source:device-info.js Github

copy

Full Screen

...44 // 但是非miui.com结尾的域名下的界面执行window.miui.getDeviceInfo 会报java错误45 if (!window.miui) {46 throw new Error('cannot get window.miui out box of Mi browser, fallback to mock deviceInfo');47 }48 info = JSON.parse(window.miui.getDeviceInfo());49 getDeviceInfo.__INFO__ = info;50 }51 catch (err) {52 console.warn(err);53 if (fallback) {54 getDeviceInfo.__INFO__ = info = mockInfo;55 }56 }57 return getDeviceInfo.__INFO__ || mockInfo;58};...

Full Screen

Full Screen

判断设备类型.js

Source:判断设备类型.js Github

copy

Full Screen

1//判断设备类型 参考项目号FS ORD-270775-T8D9-Express study study-Bain*test* (p67024370)2//Script:3for(var i=1;i<9;i++)4{5 f('HidDevice')[i].set(null);6}7f('HidDevice')['1'].set(GetDeviceInfo().IsDesktop);8f('HidDevice')['2'].set(GetDeviceInfo().IsTouch);9f('HidDevice')['3'].set(GetDeviceInfo().IsTablet);10f('HidDevice')['4'].set(GetDeviceInfo().IsGeneric);11f('HidDevice')['5'].set(GetDeviceInfo().IsMobile);12f('HidDevice')['6'].set(GetDeviceInfo().ScreenResolution);13f('HidDevice')['7'].set(GetDeviceInfo().DeviceType);14f('HidDevice')['8'].set(GetDeviceInfo().DeviceType.toString());15//隐藏题16IsDesktop: 117IsTouch: 218IsTablet: 319IsGeneric: 420IsMobile: 521ScreenResolution: 622DeviceType: 723DeviceType.toString(): 824//Script25if(f('HidDevice')['1'].toString()=='True'){f('Device').set('1');}26if(f('HidDevice')['3'].toString()=='True'){f('Device').set('2');}27if(f('HidDevice')['4'].toString()=='True'){f('Device').set('3');}28if(f('HidDevice')['5'].toString()=='True'){f('Device').set('4');}29//隐藏题30PC/Desktop 131Tablet 232Generic 3...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10driver.getDeviceInfo().then(function(deviceInfo) {11 console.log(deviceInfo);12});13driver.quit();14Method Description driver.get() Loads a new web page in the current browser window. driver.navigate().to() Loads a new web page in the current browser window. driver.navigate().back() Navigates one step backward in the browser history. driver.navigate().forward() Navigates one step forward in the browser history. driver.navigate().refresh() Refreshes the current page. driver.executeScript() Injects a snippet of JavaScript into the page for execution in the context of the currently selected frame. driver.executeAsyncScript() Injects a snippet of JavaScript into the page for execution in the context of

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.getDeviceInfo().then(function (info) {7 console.log(info);8 driver.quit();9});10{ platform: 'LINUX',11 warnings: {},12 platformName: 'Android' }13info: --> GET /wd/hub/session/4d9c7f1c-1e8e-4b2d-bb7c-2b2f8b6a9a9a/device {}14info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"warnings":{},"locationContextEnabled":false,"platformVersion":"4.4","deviceName":"emulator-5554","browserName":"android","platformName":"Android"},"sessionId":"4d9c7f1c-1e8e-4b2d-bb7c-2b2f8b6a9a9a"}15info: <-- GET /wd/hub/session/4d9c7f1c-1e8e-4b2d-bb7c-2b2f8b6a9a9a/device 200 1.047 ms - 429 {"status":0,"value":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var assert = require('assert');3var options = {4 desiredCapabilities: {5 }6};7 .remote(options)8 .init()9 .getDeviceInfo().then(function(deviceInfo) {10 console.log(deviceInfo);11 })12 .end();13{ platform: 'LINUX',14 warnings: {},15 { browserName: 'chrome',16 warnings: {},

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2 withCapabilities({3 build();4driver.sleep(5000).then(function() {5 driver.quit();6});7driver.getDeviceInfo('platformVersion').then(function(platformVersion) {8 console.log("Platform Version: " + platformVersion);9});10var webdriver = require('selenium-webdriver');11 withCapabilities({12 build();13driver.sleep(5000).then(function() {14 driver.quit();15});16driver.getDeviceInfo('platformVersion').then(function(platformVersion) {17 console.log("Platform Version: " + platformVersion);18});19var webdriver = require('selenium-webdriver');20 withCapabilities({21 build();22driver.sleep(5000).then(function() {23 driver.quit();24});25driver.getDeviceInfo('platformVersion').then(function(platformVersion) {26 console.log("Platform Version: " + platformVersion);27});28var webdriver = require('selenium-webdriver');29 withCapabilities({

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.executeScript("mobile: getDeviceInfo", []).then(function (result) {7 console.log(result);8});9driver.quit();10{ platform: 'LINUX',11 warnings: {},12 { platformName: 'Android',13 browserName: 'chrome' },

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.getDeviceInfo().then(function(deviceInfo) {7 console.log(deviceInfo);8});9driver.quit();10{ platform: 'Android',11 warnings: {},12 platformName: 'Android' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var desiredCapabilities = {2};3var driver = wd.promiseChainRemote('localhost', 4723);4driver.init(desiredCapabilities).then(function () {5 return driver.getDeviceInfo();6}).then(function (deviceInfo) {7 console.log(deviceInfo);8}).fin(function () {9 return driver.quit();10}).done();11{ platform: 'LINUX',12 warnings: {},13 { platformName: 'Android',14 app: 'path/to/your.apk' },15 app: 'path/to/your.apk' }16{ platform: 'LINUX',17 warnings: {},18 { platformName: 'Android',19 app: 'path/to/your.apk' },20 deviceTime: '2015-03-26T19:22:52.000Z' }21{ platform: 'LINUX',22 warnings: {},23 { platformName: 'Android',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var driver = wd.promiseChainRemote("localhost", 4723);4var desiredCaps = {5 app: 'C:\Users\Public\Documents\Intel\Intel(R) XDK Emulator\Android\XDKApp.apk',6};7driver.init(desiredCaps).then(function() {8 driver.getDeviceInfo().then(function(deviceInfo) {9 console.log(deviceInfo);10 });11});12appium --app C:\Users\Public\Documents\Intel\Intel(R) XDK Emulator\Android\XDKApp.apk --platform-name Android --platform-version 4.4 --device-name "Android Emulator" --app-package io.cordova.hellocordova --app-activity io.cordova.hellocordova.MainActivity13info: Welcome to Appium v1.3.4 (REV 6f0f6d9c6a8a1a4c94e7d6f2a2d4b4f4a4c4a4a4)

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