Best JavaScript code snippet using devicefarmer-stf
screen-directive.js
Source:screen-directive.js
...545 function deactivateFinger(index) {546 fingers[index].classList.remove('active')547 }548549 function deactivateFingers() {550 for (var i = 0, l = fingers.length; i < l; ++i) {551 fingers[i].classList.remove('active')552 }553 }554555 function createFinger(index) {556 var el = document.createElement('span')557 el.className = 'finger finger-' + index558 return el559 }560561 function calculateBounds() {562 var el = element[0]563564 screen.bounds.w = el.offsetWidth565 screen.bounds.h = el.offsetHeight566 screen.bounds.x = 0567 screen.bounds.y = 0568569 while (el.offsetParent) {570 screen.bounds.x += el.offsetLeft571 screen.bounds.y += el.offsetTop572 el = el.offsetParent573 }574 }575576 function mouseDownListener(event) {577 var e = event578 if (e.originalEvent) {579 e = e.originalEvent580 }581582 // Skip secondary click583 if (e.which === 3) {584 return585 }586587 e.preventDefault()588589 fakePinch = e.altKey590591 calculateBounds()592 startMousing()593594 var x = e.pageX - screen.bounds.x595 var y = e.pageY - screen.bounds.y596 var pressure = 0.5597 var scaled = scaler.coords(598 screen.bounds.w599 , screen.bounds.h600 , x601 , y602 , screen.rotation603 )604605 control.touchDown(nextSeq(), 0, scaled.xP, scaled.yP, pressure)606607 if (fakePinch) {608 control.touchDown(nextSeq(), 1, 1 - scaled.xP, 1 - scaled.yP,609 pressure)610 }611612 control.touchCommit(nextSeq())613614 activateFinger(0, x, y, pressure)615616 if (fakePinch) {617 activateFinger(1, -e.pageX + screen.bounds.x + screen.bounds.w,618 -e.pageY + screen.bounds.y + screen.bounds.h, pressure)619 }620621 element.bind('mousemove', mouseMoveListener)622 $document.bind('mouseup', mouseUpListener)623 $document.bind('mouseleave', mouseUpListener)624625 if (lastPossiblyBuggyMouseUpEvent &&626 lastPossiblyBuggyMouseUpEvent.timeStamp > e.timeStamp) {627 // We got mouseup before mousedown. See mouseUpBugWorkaroundListener628 // for details.629 mouseUpListener(lastPossiblyBuggyMouseUpEvent)630 }631 else {632 lastPossiblyBuggyMouseUpEvent = null633 }634 }635636 function mouseMoveListener(event) {637 var e = event638 if (e.originalEvent) {639 e = e.originalEvent640 }641642 // Skip secondary click643 if (e.which === 3) {644 return645 }646 e.preventDefault()647648 var addGhostFinger = !fakePinch && e.altKey649 var deleteGhostFinger = fakePinch && !e.altKey650651 fakePinch = e.altKey652653 var x = e.pageX - screen.bounds.x654 var y = e.pageY - screen.bounds.y655 var pressure = 0.5656 var scaled = scaler.coords(657 screen.bounds.w658 , screen.bounds.h659 , x660 , y661 , screen.rotation662 )663664 control.touchMove(nextSeq(), 0, scaled.xP, scaled.yP, pressure)665666 if (addGhostFinger) {667 control.touchDown(nextSeq(), 1, 1 - scaled.xP, 1 - scaled.yP, pressure)668 }669 else if (deleteGhostFinger) {670 control.touchUp(nextSeq(), 1)671 }672 else if (fakePinch) {673 control.touchMove(nextSeq(), 1, 1 - scaled.xP, 1 - scaled.yP, pressure)674 }675676 control.touchCommit(nextSeq())677678 activateFinger(0, x, y, pressure)679680 if (deleteGhostFinger) {681 deactivateFinger(1)682 }683 else if (fakePinch) {684 activateFinger(1, -e.pageX + screen.bounds.x + screen.bounds.w,685 -e.pageY + screen.bounds.y + screen.bounds.h, pressure)686 }687 }688689 function mouseUpListener(event) {690 var e = event691 if (e.originalEvent) {692 e = e.originalEvent693 }694695 // Skip secondary click696 if (e.which === 3) {697 return698 }699 e.preventDefault()700701 control.touchUp(nextSeq(), 0)702703 if (fakePinch) {704 control.touchUp(nextSeq(), 1)705 }706707 control.touchCommit(nextSeq())708709 deactivateFinger(0)710711 if (fakePinch) {712 deactivateFinger(1)713 }714715 stopMousing()716 }717718 /**719 * Do NOT remove under any circumstances. Currently, in the latest720 * Safari (Version 8.0 (10600.1.25)), if an input field is focused721 * while we do a tap click on an MBP trackpad ("Tap to click" in722 * Settings), it sometimes causes the mouseup event to trigger before723 * the mousedown event (but event.timeStamp will be correct). It724 * doesn't happen in any other browser. The following minimal test725 * case triggers the same behavior (although less frequently). Keep726 * tapping and you'll eventually see see two mouseups in a row with727 * the same counter value followed by a mousedown with a new counter728 * value. Also, when the bug happens, the cursor in the input field729 * stops blinking. It may take up to 300 attempts to spot the bug on730 * a MacBook Pro (Retina, 15-inch, Mid 2014).731 *732 * <!doctype html>733 *734 * <div id="touchable"735 * style="width: 100px; height: 100px; background: green"></div>736 * <input id="focusable" type="text" />737 *738 * <script>739 * var touchable = document.getElementById('touchable')740 * , focusable = document.getElementById('focusable')741 * , counter = 0742 *743 * function mousedownListener(e) {744 * counter += 1745 * console.log('mousedown', counter, e, e.timeStamp)746 * e.preventDefault()747 * }748 *749 * function mouseupListener(e) {750 * e.preventDefault()751 * console.log('mouseup', counter, e, e.timeStamp)752 * focusable.focus()753 * }754 *755 * touchable.addEventListener('mousedown', mousedownListener, false)756 * touchable.addEventListener('mouseup', mouseupListener, false)757 * </script>758 *759 * I believe that the bug is caused by some kind of a race condition760 * in Safari. Using a textarea or a focused contenteditable does not761 * get rid of the bug. The bug also happens if the text field is762 * focused manually by the user (not with .focus()).763 *764 * It also doesn't help if you .blur() before .focus().765 *766 * So basically we'll just have to store the event on mouseup and check767 * if we should do the browser's job in the mousedown handler.768 */769 function mouseUpBugWorkaroundListener(e) {770 lastPossiblyBuggyMouseUpEvent = e771 }772773 function startMousing() {774 control.gestureStart(nextSeq())775 input[0].focus()776 }777778 function stopMousing() {779 element.unbind('mousemove', mouseMoveListener)780 $document.unbind('mouseup', mouseUpListener)781 $document.unbind('mouseleave', mouseUpListener)782 deactivateFingers()783 control.gestureStop(nextSeq())784 }785786 function touchStartListener(event) {787 var e = event788 e.preventDefault()789790 //Make it jQuery compatible also791 if (e.originalEvent) {792 e = e.originalEvent793 }794795 calculateBounds()796797 if (e.touches.length === e.changedTouches.length) {798 startTouching()799 }800801 var currentTouches = Object.create(null)802 var i, l803804 for (i = 0, l = e.touches.length; i < l; ++i) {805 currentTouches[e.touches[i].identifier] = 1806 }807808 function maybeLostTouchEnd(id) {809 return !(id in currentTouches)810 }811812 // We might have lost a touchend event due to various edge cases813 // (literally) such as dragging from the bottom of the screen so that814 // the control center appears. If so, let's ask for a reset.815 if (Object.keys(slotted).some(maybeLostTouchEnd)) {816 Object.keys(slotted).forEach(function(id) {817 slots.push(slotted[id])818 delete slotted[id]819 })820 slots.sort().reverse()821 control.touchReset(nextSeq())822 deactivateFingers()823 }824825 if (!slots.length) {826 // This should never happen but who knows...827 throw new Error('Ran out of multitouch slots')828 }829830 for (i = 0, l = e.changedTouches.length; i < l; ++i) {831 var touch = e.changedTouches[i]832 var slot = slots.pop()833 var x = touch.pageX - screen.bounds.x834 var y = touch.pageY - screen.bounds.y835 var pressure = touch.force || 0.5836 var scaled = scaler.coords(837 screen.bounds.w838 , screen.bounds.h839 , x840 , y841 , screen.rotation842 )843844 slotted[touch.identifier] = slot845 control.touchDown(nextSeq(), slot, scaled.xP, scaled.yP, pressure)846 activateFinger(slot, x, y, pressure)847 }848849 element.bind('touchmove', touchMoveListener)850 $document.bind('touchend', touchEndListener)851 $document.bind('touchleave', touchEndListener)852853 control.touchCommit(nextSeq())854 }855856 function touchMoveListener(event) {857 var e = event858 e.preventDefault()859860 if (e.originalEvent) {861 e = e.originalEvent862 }863864 for (var i = 0, l = e.changedTouches.length; i < l; ++i) {865 var touch = e.changedTouches[i]866 var slot = slotted[touch.identifier]867 var x = touch.pageX - screen.bounds.x868 var y = touch.pageY - screen.bounds.y869 var pressure = touch.force || 0.5870 var scaled = scaler.coords(871 screen.bounds.w872 , screen.bounds.h873 , x874 , y875 , screen.rotation876 )877878 control.touchMove(nextSeq(), slot, scaled.xP, scaled.yP, pressure)879 activateFinger(slot, x, y, pressure)880 }881882 control.touchCommit(nextSeq())883 }884885 function touchEndListener(event) {886 var e = event887 if (e.originalEvent) {888 e = e.originalEvent889 }890891 var foundAny = false892893 for (var i = 0, l = e.changedTouches.length; i < l; ++i) {894 var touch = e.changedTouches[i]895 var slot = slotted[touch.identifier]896 if (typeof slot === 'undefined') {897 // We've already disposed of the contact. We may have gotten a898 // touchend event for the same contact twice.899 continue900 }901 delete slotted[touch.identifier]902 slots.push(slot)903 control.touchUp(nextSeq(), slot)904 deactivateFinger(slot)905 foundAny = true906 }907908 if (foundAny) {909 control.touchCommit(nextSeq())910 if (!e.touches.length) {911 stopTouching()912 }913 }914 }915916 function startTouching() {917 control.gestureStart(nextSeq())918 }919920 function stopTouching() {921 element.unbind('touchmove', touchMoveListener)922 $document.unbind('touchend', touchEndListener)923 $document.unbind('touchleave', touchEndListener)924 deactivateFingers()925 control.gestureStop(nextSeq())926 }927928 element.on('touchstart', touchStartListener)929 element.on('mousedown', mouseDownListener)930 element.on('mouseup', mouseUpBugWorkaroundListener)931932 createSlots()933 })()934 }935 }
...
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var stf = require('devicefarmer-stf');3client.deactivateFingers(function (err) {4 if (err) {5 console.log(err);6 }7});8var stf = require('devicefarmer-stf');9var stf = require('devicefarmer-stf');10client.activateFingers(function (err) {11 if (err) {12 console.log(err);13 }14});15var stf = require('devicefarmer-stf');16var stf = require('devicefarmer-stf');17client.deactivateFingers(function (err) {18 if (err) {19 console.log(err);20 }21});22var stf = require('devicefarmer-stf');23var stf = require('devicefarmer-stf');24client.activateFingers(function (err) {25 if (err) {26 console.log(err);27 }28});29var stf = require('devicefarmer-stf');30var stf = require('devicefarmer-stf');31client.deactivateFingers(function (err) {32 if (err) {33 console.log(err);34 }35});36var stf = require('devicefarmer-stf');37var stf = require('devicefarmer-stf');38client.activateFingers(function (err) {39 if (err) {40 console.log(err);41 }42});43var stf = require('devicefarmer-stf');44var stf = require('devicefarmer-stf');45var client = stf.connect("http
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2stfClient.connect().then(function() {3 stfClient.deactivateFingers().then(function() {4 console.log('Fingers deactivated');5 }, function(err) {6 console.log('Error deactivating fingers', err);7 });8}, function(err) {9 console.log('Error connecting to STF', err);10});11var stf = require('devicefarmer-stf-client');12stfClient.connect().then(function() {13 stfClient.activateFingers().then(function() {14 console.log('Fingers activated');15 }, function(err) {16 console.log('Error activating fingers', err);17 });18}, function(err) {19 console.log('Error connecting to STF', err);20});21var stf = require('devicefarmer-stf-client');22stfClient.connect().then(function() {23 stfClient.deactivateFace().then(function() {24 console.log('Face deactivated');25 }, function(err) {26 console.log('Error deactivating face', err);27 });28}, function(err) {29 console.log('Error connecting to STF', err);30});31var stf = require('devicefarmer-stf-client');32stfClient.connect().then(function() {33 stfClient.activateFace().then(function() {34 console.log('Face activated');35 }, function(err) {36 console.log('Error activating face', err);37 });38}, function(err) {39 console.log('Error connecting to STF', err);40});41var stf = require('devicefarmer-stf-client');
Using AI Code Generation
1const stf = require('devicefarmer-stf');2var device = stf.getDevice('device serial');3device.deactivateFingers();4const stf = require('devicefarmer-stf');5var device = stf.getDevice('device serial');6device.activateFingers();7const stf = require('devicefarmer-stf');8var device = stf.getDevice('device serial');9device.rotate('right');10const stf = require('devicefarmer-stf');11var device = stf.getDevice('device serial');12device.setOrientation('right');13const stf = require('devicefarmer-stf');14var device = stf.getDevice('device serial');15device.getOrientation();16const stf = require('devicefarmer-stf');17var device = stf.getDevice('device serial');18device.setGeoLocation('lat', 'long');19const stf = require('devicefarmer-stf');20var device = stf.getDevice('device serial');21device.getGeoLocation();22const stf = require('devicefarmer-stf');23var device = stf.getDevice('device serial');24device.getDisplay();25const stf = require('devicefarmer-stf');26var device = stf.getDevice('device serial');27device.getDisplay();28const stf = require('devicefarmer-stf');29var device = stf.getDevice('device serial');30device.getDisplay();
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var client = new stf.Client();3client.deactivateFingers('deviceid', function(err, res) {4 console.log(err, res);5});6var stf = require('devicefarmer-stf-client');7var client = new stf.Client();8client.activateFingers('deviceid', function(err, res) {9 console.log(err, res);10});11var stf = require('devicefarmer-stf-client');12var client = new stf.Client();13client.getFingerState('deviceid', function(err, res) {14 console.log(err, res);15});16var stf = require('devicefarmer-stf-client');17var client = new stf.Client();18client.getFingerPrintState('deviceid', function(err, res) {19 console.log(err, res);20});21var stf = require('devicefarmer-stf-client');22var client = new stf.Client();23client.getFingerPrintState('deviceid', function(err, res) {24 console.log(err, res);25});26var stf = require('devicefarmer-stf-client');27var client = new stf.Client();28client.getFingerPrintState('deviceid', function(err, res) {29 console.log(err, res);30});31var stf = require('devicefarmer-stf-client');32var client = new stf.Client();33client.getFingerPrintState('deviceid', function(err, res) {34 console.log(err, res);35});36var stf = require('devicefarmer-stf-client');37var client = new stf.Client();38client.getFingerPrintState('deviceid', function(err, res) {39 console.log(err, res);40});
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!!