How to use getGenericDevices method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

devices.js

Source:devices.js Github

copy

Full Screen

...20 return apiutil.filterDevice(req, device)21 })22 })23}24function getGenericDevices(req, res, loadDevices) {25 loadDevices(req.user.groups.subscribed).then(function(devices) {26 filterGenericDevices(req, res, devices)27 })28 .catch(function(err) {29 apiutil.internalError(res, 'Failed to load device list: ', err.stack)30 })31}32function getDeviceFilteredGroups(serial, fields, bookingOnly) {33 return dbapi.getDeviceGroups(serial).then(function(groups) {34 return Promise.map(groups, function(group) {35 return !bookingOnly || !apiutil.isOriginGroup(group.class) ?36 group :37 'filtered'38 })39 .then(function(groups) {40 return _.without(groups, 'filtered').map(function(group) {41 if (fields) {42 return _.pick(apiutil.publishGroup(group), fields.split(','))43 }44 return apiutil.publishGroup(group)45 })46 })47 })48}49function extractStandardizableDevices(devices) {50 return dbapi.getTransientGroups().then(function(groups) {51 return Promise.map(devices, function(device) {52 return Promise.map(groups, function(group) {53 if (group.devices.indexOf(device.serial) > -1) {54 return Promise.reject('booked')55 }56 return true57 })58 .then(function() {59 return device60 })61 .catch(function(err) {62 if (err !== 'booked') {63 throw err64 }65 return err66 })67 })68 .then(function(devices) {69 return _.without(devices, 'booked')70 })71 })72}73function getStandardizableDevices(req, res) {74 dbapi.loadDevicesByOrigin(req.user.groups.subscribed).then(function(devices) {75 extractStandardizableDevices(devices).then(function(devices) {76 filterGenericDevices(req, res, devices)77 })78 })79 .catch(function(err) {80 apiutil.internalError(res, 'Failed to load device list: ', err.stack)81 })82}83function removeDevice(serial, req, res) {84 const presentState = req.swagger.params.present.value85 const bookingState = req.swagger.params.booked.value86 const notesState = req.swagger.params.annotated.value87 const controllingState = req.swagger.params.controlled.value88 const anyPresentState = typeof presentState === 'undefined'89 const anyBookingState = typeof bookingState === 'undefined'90 const anyNotesState = typeof notesState === 'undefined'91 const anyControllingState = typeof controllingState === 'undefined'92 const lock = {}93 function deleteGroupDevice(email, id) {94 const lock = {}95 return dbapi.lockGroupByOwner(email, id).then(function(stats) {96 if (!stats.replaced) {97 return apiutil.lightComputeStats(res, stats)98 }99 const group = lock.group = stats.changes[0].new_val100 if (group.devices.indexOf(serial) > -1) {101 return apiutil.isOriginGroup(group.class) ?102 dbapi.removeOriginGroupDevice(group, serial) :103 dbapi.removeGroupDevices(group, [serial])104 }105 return group106 })107 .finally(function() {108 lockutil.unlockGroup(lock)109 })110 }111 function deleteDeviceInDatabase() {112 function wrappedDeleteDeviceInDatabase() {113 const result = {114 status: false115 , data: 'not deleted'116 }117 return dbapi.loadDeviceBySerial(serial).then(function(device) {118 if (device && device.group.id === device.group.origin) {119 return deleteGroupDevice(device.group.owner.email, device.group.id)120 .then(function(group) {121 if (group !== 'not found') {122 return dbapi.deleteDevice(serial).then(function() {123 result.status = true124 result.data = 'deleted'125 })126 }127 return false128 })129 }130 return false131 })132 .then(function() {133 return result134 })135 }136 return apiutil.setIntervalWrapper(137 wrappedDeleteDeviceInDatabase138 , 10139 , Math.random() * 500 + 50)140 }141 return dbapi.lockDeviceByOrigin(req.user.groups.subscribed, serial).then(function(stats) {142 if (!stats.replaced) {143 return apiutil.lightComputeStats(res, stats)144 }145 const device = lock.device = stats.changes[0].new_val146 if (!anyPresentState && device.present !== presentState ||147 !anyControllingState && (device.owner === null) === controllingState ||148 !anyNotesState &&149 (typeof device.notes !== 'undefined' && device.notes !== '') !== notesState ||150 !anyBookingState && (device.group.id !== device.group.origin && !bookingState ||151 device.group.class === apiutil.STANDARD && bookingState)) {152 return 'unchanged'153 }154 if (device.group.class === apiutil.STANDARD) {155 return deleteDeviceInDatabase()156 }157 return dbapi.getDeviceTransientGroups(serial).then(function(groups) {158 if (groups.length && !anyBookingState && !bookingState) {159 return 'unchanged'160 }161 return Promise.each(groups, function(group) {162 return deleteGroupDevice(group.owner.email, group.id)163 })164 .then(function() {165 if (!groups.length && !anyBookingState && bookingState) {166 return 'unchanged'167 }168 return deleteDeviceInDatabase()169 })170 })171 })172 .finally(function() {173 lockutil.unlockDevice(lock)174 })175}176/* ------------------------------------ PUBLIC FUNCTIONS ------------------------------- */177function getDevices(req, res) {178 const target = req.swagger.params.target.value179 switch(target) {180 case apiutil.BOOKABLE:181 getGenericDevices(req, res, dbapi.loadBookableDevices)182 break183 case apiutil.ORIGIN:184 getGenericDevices(req, res, dbapi.loadDevicesByOrigin)185 break186 case apiutil.STANDARD:187 getGenericDevices(req, res, dbapi.loadStandardDevices)188 break189 case apiutil.STANDARDIZABLE:190 getStandardizableDevices(req, res)191 break192 default:193 getGenericDevices(req, res, dbapi.loadDevices)194 }195}196function getDeviceBySerial(req, res) {197 var serial = req.swagger.params.serial.value198 var fields = req.swagger.params.fields.value199 dbapi.loadDevice(req.user.groups.subscribed, serial)200 .then(function(cursor) {201 cursor.next(function(err, device) {202 if (err) {203 return res.status(404).json({204 success: false205 , description: 'Device not found'206 })207 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('./devicefarmer-stf.js');2devicefarmer.getGenericDevices(function(devices){3 console.log(devices);4});5var request = require('request');6var devicefarmer = {};7devicefarmer.getGenericDevices = function(callback){8 request(url, function(error, response, body){9 if(!error && response.statusCode == 200){10 var devices = JSON.parse(body);11 callback(devices);12 }13 });14}15module.exports = devicefarmer;16[ { id: 1,17 browserVersion: '39.0' },18 { id: 2,19 browserVersion: '39.0' },20 { id: 3,21 browserVersion: '39.0' },22 { id: 4,23 browserVersion: '39.0' },24 { id: 5,

Full Screen

Using AI Code Generation

copy

Full Screen

1var DeviceFarmer = require('devicefarmer-stf-client');2client.getGenericDevices('android', function(err, devices) {3 if (err) {4 console.log(err);5 return;6 }7 console.log(devices);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2var devices = stf.getGenericDevices();3console.log(devices);4[ { serial: '7f9f9b2c',5 display: { width: 1080, height: 1920 },6 remoteAdbUrl: null },7 { serial: '7f9f9b2c',8 display: { width: 1080, height: 1920 },9 remoteAdbUrl: null } ]

Full Screen

Using AI Code Generation

copy

Full Screen

1const DeviceFarmer = require('devicefarmer-stf-api');2const df = new DeviceFarmer();3df.getGenericDevices().then(function (devices) {4 console.log('Devices:', devices);5});6const DeviceFarmer = require('devicefarmer-stf-api');7const df = new DeviceFarmer();8df.getGenericDevices().then(function (devices) {9 console.log('Devices:', devices);10});11const DeviceFarmer = require('devicefarmer-stf-api');12const df = new DeviceFarmer();13df.getGenericDevices().then(function (devices) {14 console.log('Devices:', devices);15});16const DeviceFarmer = require('devicefarmer-stf-api');17const df = new DeviceFarmer();18df.getGenericDevices().then(function (devices) {19 console.log('Devices:', devices);20});21const DeviceFarmer = require('devicefarmer-stf-api');22const df = new DeviceFarmer();23df.getGenericDevices().then(function (devices) {24 console.log('Devices:', devices);25});26const DeviceFarmer = require('devicefarmer-stf-api');27const df = new DeviceFarmer();28df.getGenericDevices().then(function (devices) {29 console.log('Devices:', devices);30});31const DeviceFarmer = require('devicefarmer-stf-api');32const df = new DeviceFarmer();33df.getGenericDevices().then(function (devices) {34 console.log('Devices:', devices);35});36const DeviceFarmer = require('devicefarmer-stf-api');37const df = new DeviceFarmer();38df.getGenericDevices().then(function (devices) {39 console.log('Devices:', devices);40});

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