How to use MultiTargetTransaction method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

transaction-service.js

Source:transaction-service.js Github

copy

Full Screen

...4 var transactionService = {}5 function createChannel() {6 return 'tx.' + uuid.v4()7 }8 function MultiTargetTransaction(targets, options) {9 var pending = Object.create(null)10 var results = []11 var channel = createChannel()12 function doneListener(someChannel, data) {13 if (someChannel === channel) {14 pending[data.source].done(data)15 }16 }17 function progressListener(someChannel, data) {18 if (someChannel === channel) {19 pending[data.source].progress(data)20 }21 }22 function cancelListener(someChannel, data) {23 if (someChannel === channel) {24 Object.keys(pending).forEach(function(source) {25 pending[source].cancel(data)26 })27 }28 }29 socket.on('tx.done', doneListener)30 socket.on('tx.progress', progressListener)31 socket.on('tx.cancel', cancelListener)32 this.channel = channel33 this.results = results34 this.promise = Promise.settle(targets.map(function(target) {35 var result = new options.result(target)36 var pendingResult = new PendingTransactionResult(result)37 pending[options.id ? target[options.id] : target.id] = pendingResult38 results.push(result)39 return pendingResult.promise40 }))41 .finally(function() {42 socket.removeListener('tx.done', doneListener)43 socket.removeListener('tx.progress', progressListener)44 socket.removeListener('tx.cancel', cancelListener)45 socket.emit('tx.cleanup', channel)46 })47 .progressed(function() {48 return results49 })50 .then(function() {51 return results52 })53 }54 function SingleTargetTransaction(target, options) {55 var result = new options.result(target)56 var pending = new PendingTransactionResult(result)57 var channel = createChannel()58 function doneListener(someChannel, data) {59 if (someChannel === channel) {60 pending.done(data)61 }62 }63 function progressListener(someChannel, data) {64 if (someChannel === channel) {65 pending.progress(data)66 }67 }68 function cancelListener(someChannel, data) {69 if (someChannel === channel) {70 pending.cancel(data)71 }72 }73 socket.on('tx.done', doneListener)74 socket.on('tx.progress', progressListener)75 socket.on('tx.cancel', cancelListener)76 this.channel = channel77 this.result = result78 this.results = [result]79 this.promise = pending.promise80 .finally(function() {81 socket.removeListener('tx.done', doneListener)82 socket.removeListener('tx.progress', progressListener)83 socket.removeListener('tx.cancel', cancelListener)84 socket.emit('tx.cleanup', channel)85 })86 .progressed(function() {87 return result88 })89 .then(function() {90 return result91 })92 }93 function PendingTransactionResult(result) {94 var resolver = Promise.defer()95 var seq = 096 var last = Infinity97 var unplaced = []98 function readQueue() {99 var message100 var foundAny = false101 while (seq <= last && (message = unplaced[seq])) {102 unplaced[seq] = undefined103 if (seq === last) {104 result.success = message.success105 if (message.body) {106 result.body = JSON.parse(message.body)107 }108 if (result.success) {109 if (message.data) {110 result.lastData = result.data[seq] = message.data111 }112 resolver.resolve(result)113 }114 else {115 result.lastData = result.error = message.data116 resolver.reject(new TransactionError(result))117 }118 return119 }120 else {121 if (message.progress) {122 result.progress = message.progress123 }124 }125 foundAny = true126 result.lastData = result.data[seq++] = message.data127 }128 if (foundAny) {129 resolver.progress(result)130 }131 }132 this.progress = function(message) {133 unplaced[message.seq] = message134 readQueue()135 }136 this.done = function(message) {137 last = message.seq138 unplaced[message.seq] = message139 readQueue()140 }141 this.cancel = function(message) {142 if (!result.settled) {143 last = message.seq = seq144 unplaced[message.seq] = message145 readQueue()146 }147 }148 this.result = result149 this.promise = resolver.promise.finally(function() {150 result.settled = true151 result.progress = 100152 })153 }154 function TransactionResult(source) {155 this.source = source156 this.settled = false157 this.success = false158 this.progress = 0159 this.error = null160 this.data = []161 this.lastData = null162 this.body = null163 }164 function DeviceTransactionResult(device) {165 TransactionResult.call(this, device)166 this.device = this.source167 }168 DeviceTransactionResult.prototype = Object.create(TransactionResult)169 DeviceTransactionResult.constructor = DeviceTransactionResult170 transactionService.create = function(target, options) {171 if (options && !options.result) {172 options.result = TransactionResult173 }174 if (Array.isArray(target)) {175 return new MultiTargetTransaction(target, options || {176 result: DeviceTransactionResult177 , id: 'serial'178 })179 }180 else {181 return new SingleTargetTransaction(target, options || {182 result: DeviceTransactionResult183 , id: 'serial'184 })185 }186 }187 transactionService.punch = function(channel) {188 var resolver = Promise.defer()189 function punchListener(someChannel) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var client = new stf.Client(api);3client.getDevices().then(function(devices) {4 var device = devices[0];5 device.use().then(function() {6 device.shell('input keyevent 82').then(function() {7 device.shell('input keyevent 3').then(function() {8 device.shell('input keyevent 26').then(function() {9 device.shell('input keyevent 82').then(function() {10 device.shell('input keyevent 3').then(function() {11 device.shell('input keyevent 26').then(function() {12 device.shell('input keyevent 82').then(function() {13 device.shell('input keyevent 3').then(function() {14 device.shell('input keyevent 26').then(function() {15 device.shell('input keyevent 82').then(function() {16 device.shell('input keyevent 3').then(function() {17 device.shell('input keyevent 26').then(function() {18 device.shell('input keyevent 82').then(function() {19 device.shell('input keyevent 3').then(function() {20 device.shell('input keyevent 26').then(function() {21 device.shell('input keyevent 82').then(function() {22 device.shell('input keyevent 3').then(function() {23 device.shell('input keyevent 26').then(function() {24 device.shell('input keyevent 82').then(function() {25 device.shell('input keyevent 3').then(function() {26 device.shell('input keyevent 26').then(function() {27 device.shell('input keyevent 82').then(function() {28 device.shell('input keyevent 3').then(function() {29 device.shell('input keyevent 26').then(function() {30 device.shell('input keyevent 82').then(function() {31 device.shell('input keyevent 3').then(function() {32 device.shell('input keyevent 26').then(function() {33 device.shell('input keyevent 82').then(function() {34 device.shell('input keyevent 3').then(function() {35 device.shell('input keyevent 26').then(function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('devicefarmer-stf-client');2var stf = new client.Stf();3stf.connect("localhost", 7112, function (err, data) {4 if (err) {5 console.log(err);6 return;7 }8 console.log('Connected to STF');9 stf.getDevices(function (err, data) {10 if (err) {11 console.log(err);12 return;13 }14 console.log('Devices received');15 var devices = data.devices;16 var device = devices[0];17 var serial = device.serial;18 var adb = stf.getAdb(serial);19 adb.push('test.mp4', '/sdcard/test.mp4', function (err, data) {20 if (err) {21 console.log(err);22 return;23 }24 console.log('File pushed');25 var transaction = stf.getMultiTargetTransaction();26 transaction.add(serial);27 transaction.start(function (err, data) {28 if (err) {29 console.log(err);30 return;31 }32 console.log('Transaction started');33 if (err) {34 console.log(err);35 return;36 }37 console.log('Video started');38 });39 });40 });41 });42});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('stf-client');2var Promise = require('bluebird');3var fs = require('fs');4var path = require('path');5var util = require('util');6var _ = require('lodash');7var devices = client.getDevices().then(function(devices) {8 return _.filter(devices, function(device) {9 return device.owner === 'group';10 });11});12var serials = devices.then(function(devices) {13 return _.map(devices, function(device) {14 return device.serial;15 });16});17var transaction = client.createMultiTargetTransaction();18serials.each(function(serial) {19 transaction.push({20 params: {21 }22 });23});24transaction.execute().then(function(results) {25 return Promise.map(results, function(result) {26 return result.then(function(result) {27 return {28 };29 });30 });31}).then(function(results) {32 return Promise.map(results, function(result) {33 var filename = util.format(34 );35 var filepath = path.resolve(filename);36 return Promise.promisify(fs.writeFile)(37 ).then(function() {38 return filename;39 });40 });41}).then(function(filenames) {42 console.log('Saved screenshots to', filenames);43}).catch(function(err) {44 console.error('Error:', err.stack);45});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = new stf.Device(client, 'device serial number');3device.connect(function(err) {4 if (err) throw err;5 device.use(function(err, device) {6 if (err) throw err;7 device.shell('i

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('stf-client');2var Promise = require('bluebird');3var client = stf.connect({4});5var device = client.getDevice('deviceid');6var transaction = device.getMultiTargetTransaction();7 .add('shell', ['echo', 'hello'])8 .add('shell', ['echo', 'world'])9 .add('shell', ['echo', 'this is cool'])10 .commit()11 .then(function() {12 console.log('Commands executed');13 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client')2var fs = require('fs')3var path = require('path')4var adbkey = fs.readFileSync(path.resolve(__dirname, 'adbkey'))5var adbkeypub = fs.readFileSync(path.resolve(__dirname, 'adbkey.pub'))6var transaction = fs.readFileSync(path.resolve(__dirname, 'transaction'))7var stfClient = new stf({8})9stfClient.createGroup()10 .then(function (group) {11 group.addDevices([12 .then(function () {13 group.getDevices()14 .then(function (devices) {15 devices.MultiTargetTransaction({16 })17 .then(function (results) {18 console.log(results)19 })20 .catch(function (err) {21 console.log(err)22 })23 })24 .catch(function (err) {25 console.log(err)26 })27 })28 .catch(function (err) {29 console.log(err)30 })31 })32 .catch(function (err) {33 console.log(err)34 })

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = new stf.Device(process.argv[2]);3device.connect().then(function() {4 return device.MultiTargetTransaction([5 {6 },7 {8 }9 ]);10}).then(function() {11 return device.disconnect();12}).then(function() {13 console.log('done');14}).catch(function(err) {15 console.error(err);16});17var stf = require('devicefarmer-stf-client');18var device = new stf.Device(process.argv[2]);19device.connect().then(function() {20 return device.MultiTargetTransaction([21 {22 },23 {24 }25 ]);26}).then(function() {27 return device.disconnect();28}).then(function() {29 console.log('done');30}).catch(function(err) {31 console.error(err);32});33var stf = require('devicefarmer-stf-client');34var device = new stf.Device(process.argv[2]);35device.connect().then(function() {36 return device.MultiTargetTransaction([37 {

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