Best JavaScript code snippet using devicefarmer-stf
control-service.js
Source: control-service.js
...12 function ControlService(target, channel) {13 function sendOneWay(action, data) {14 socket.emit(action, channel, data)15 }16 function sendTwoWay(action, data) {17 var tx = TransactionService.create(target)18 socket.emit(action, channel, tx.channel, data)19 return tx.promise20 }21 function keySender(type, fixedKey) {22 return function(key) {23 if (typeof key === 'string') {24 sendOneWay(type, {25 key: key26 })27 }28 else {29 var mapped = fixedKey || KeycodesMapped[key]30 if (mapped) {31 sendOneWay(type, {32 key: mapped33 })34 }35 }36 }37 }38 this.gestureStart = function(seq) {39 sendOneWay('input.gestureStart', {40 seq: seq41 })42 }43 this.gestureStop = function(seq) {44 sendOneWay('input.gestureStop', {45 seq: seq46 })47 }48 this.touchDown = function(seq, contact, x, y, pressure) {49 sendOneWay('input.touchDown', {50 seq: seq51 , contact: contact52 , x: x53 , y: y54 , pressure: pressure55 })56 }57 this.touchMove = function(seq, contact, x, y, pressure) {58 sendOneWay('input.touchMove', {59 seq: seq60 , contact: contact61 , x: x62 , y: y63 , pressure: pressure64 })65 }66 this.touchUp = function(seq, contact) {67 sendOneWay('input.touchUp', {68 seq: seq69 , contact: contact70 })71 }72 this.touchCommit = function(seq) {73 sendOneWay('input.touchCommit', {74 seq: seq75 })76 }77 this.touchReset = function(seq) {78 sendOneWay('input.touchReset', {79 seq: seq80 })81 }82 this.keyDown = keySender('input.keyDown')83 this.keyUp = keySender('input.keyUp')84 this.keyPress = keySender('input.keyPress')85 this.home = keySender('input.keyPress', 'home')86 this.menu = keySender('input.keyPress', 'menu')87 this.back = keySender('input.keyPress', 'back')88 this.appSwitch = keySender('input.keyPress', 'app_switch')89 this.type = function(text) {90 return sendOneWay('input.type', {91 text: text92 })93 }94 this.paste = function(text) {95 return sendTwoWay('clipboard.paste', {96 text: text97 })98 }99 this.copy = function() {100 return sendTwoWay('clipboard.copy')101 }102 //@TODO: Refactor this please103 var that = this104 this.getClipboardContent = function() {105 that.copy().then(function(result) {106 $rootScope.$apply(function() {107 if (result.success) {108 if (result.lastData) {109 that.clipboardContent = result.lastData110 } else {111 that.clipboardContent = gettext('No clipboard data')112 }113 } else {114 that.clipboardContent = gettext('Error while getting data')115 }116 })117 })118 }119 this.shell = function(command) {120 return sendTwoWay('shell.command', {121 command: command122 , timeout: 10000123 })124 }125 this.identify = function() {126 return sendTwoWay('device.identify')127 }128 this.install = function(options) {129 return sendTwoWay('device.install', options)130 }131 this.uninstall = function(pkg) {132 return sendTwoWay('device.uninstall', {133 packageName: pkg134 })135 }136 this.reboot = function() {137 return sendTwoWay('device.reboot')138 }139 this.rotate = function(rotation, lock) {140 return sendOneWay('display.rotate', {141 rotation: rotation,142 lock: lock143 })144 }145 this.testForward = function(forward) {146 return sendTwoWay('forward.test', {147 targetHost: forward.targetHost148 , targetPort: Number(forward.targetPort)149 })150 }151 this.createForward = function(forward) {152 return sendTwoWay('forward.create', {153 id: forward.id154 , devicePort: Number(forward.devicePort)155 , targetHost: forward.targetHost156 , targetPort: Number(forward.targetPort)157 })158 }159 this.removeForward = function(forward) {160 return sendTwoWay('forward.remove', {161 id: forward.id162 })163 }164 this.startLogcat = function(filters) {165 return sendTwoWay('logcat.start', {166 filters: filters167 })168 }169 this.stopLogcat = function() {170 return sendTwoWay('logcat.stop')171 }172 this.startRemoteConnect = function() {173 return sendTwoWay('connect.start')174 }175 this.stopRemoteConnect = function() {176 return sendTwoWay('connect.stop')177 }178 this.openBrowser = function(url, browser) {179 return sendTwoWay('browser.open', {180 url: url181 , browser: browser ? browser.id : null182 })183 }184 this.clearBrowser = function(browser) {185 return sendTwoWay('browser.clear', {186 browser: browser.id187 })188 }189 this.openStore = function() {190 return sendTwoWay('store.open')191 }192 this.screenshot = function() {193 return sendTwoWay('screen.capture')194 }195 this.fsretrieve = function(file) {196 return sendTwoWay('fs.retrieve', {197 file: file198 })199 }200 this.fslist = function(dir) {201 return sendTwoWay('fs.list', {202 dir: dir203 })204 }205 this.checkAccount = function(type, account) {206 return sendTwoWay('account.check', {207 type: type208 , account: account209 })210 }211 this.removeAccount = function(type, account) {212 return sendTwoWay('account.remove', {213 type: type214 , account: account215 })216 }217 this.addAccountMenu = function() {218 return sendTwoWay('account.addmenu')219 }220 this.addAccount = function(user, password) {221 return sendTwoWay('account.add', {222 user: user223 , password: password224 })225 }226 this.getAccounts = function(type) {227 return sendTwoWay('account.get', {228 type: type229 })230 }231 this.getSdStatus = function() {232 return sendTwoWay('sd.status')233 }234 this.setRingerMode = function(mode) {235 return sendTwoWay('ringer.set', {236 mode: mode237 })238 }239 this.getRingerMode = function() {240 return sendTwoWay('ringer.get')241 }242 this.setWifiEnabled = function(enabled) {243 return sendTwoWay('wifi.set', {244 enabled: enabled245 })246 }247 this.getWifiStatus = function() {248 return sendTwoWay('wifi.get')249 }250 window.cc = this251 }252 controlService.create = function(target, channel) {253 return new ControlService(target, channel)254 }255 return controlService...
Check out the latest blogs from LambdaTest on this topic:
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
Many theoretical descriptions explain the role of the Scrum Master as a vital member of the Scrum team. However, these descriptions do not provide an honest answer to the fundamental question: “What are the day-to-day activities of a Scrum Master?”
With the rising demand for new services and technologies in the IT, manufacturing, healthcare, and financial sector, QA/ DevOps engineering has become the most important part of software companies. Below is a list of some characteristics to look for when interviewing a potential candidate.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!