Best JavaScript code snippet using appium-xcuitest-driver
FrameRateMonitorSpec.js
Source:FrameRateMonitorSpec.js
...27 monitor = undefined;28 }29 });3031 function spinWait(milliseconds) {32 /*jshint noempty: false*/33 var endTime = getTimestamp() + milliseconds;34 while (getTimestamp() < endTime) {35 }36 }3738 it('throws when constructed without a scene', function() {39 expect(function() {40 monitor = new FrameRateMonitor();41 }).toThrowDeveloperError();4243 expect(function() {44 monitor = new FrameRateMonitor({});45 }).toThrowDeveloperError();46 });4748 it('can be constructed with just a scene', function() {49 monitor = new FrameRateMonitor({50 scene : scene51 });5253 expect(monitor.samplingWindow).toBe(5.0);54 expect(monitor.quietPeriod).toBe(2.0);55 expect(monitor.warmupPeriod).toBe(5.0);56 expect(monitor.minimumFrameRateDuringWarmup).toBe(4);57 expect(monitor.minimumFrameRateAfterWarmup).toBe(8);58 expect(monitor.scene).toBe(scene);59 expect(monitor.lowFrameRate.numberOfListeners).toBe(0);60 expect(monitor.nominalFrameRate.numberOfListeners).toBe(0);61 });6263 it('honors parameters to the constructor', function() {64 monitor = new FrameRateMonitor({65 scene : scene,66 samplingWindow : 3.0,67 quietPeriod : 1.0,68 warmupPeriod : 6.0,69 minimumFrameRateDuringWarmup : 1,70 minimumFrameRateAfterWarmup : 271 });7273 expect(monitor.samplingWindow).toBe(3.0);74 expect(monitor.quietPeriod).toBe(1.0);75 expect(monitor.warmupPeriod).toBe(6.0);76 expect(monitor.minimumFrameRateDuringWarmup).toBe(1);77 expect(monitor.minimumFrameRateAfterWarmup).toBe(2);78 expect(monitor.scene).toBe(scene);79 });8081 it('raises the lowFrameRate event on low frame rate', function() {82 monitor = new FrameRateMonitor({83 scene : scene,84 quietPeriod : 0.001,85 warmupPeriod : 0.001,86 samplingWindow : 0.001,87 minimumFrameRateDuringWarmup : 1000,88 minimumFrameRateAfterWarmup : 100089 });9091 var spyListener = jasmine.createSpy('listener');92 monitor.lowFrameRate.addEventListener(spyListener);9394 // Rendering once starts the quiet period95 scene.render();9697 // Wait until we're well past the end of the quiet period.98 spinWait(2);99100 // Rendering again records our first sample.101 scene.render();102103 // Wait well over a millisecond, which is the maximum frame time allowed by this instance.104 spinWait(2);105106 // Record our second sample. The monitor should notice that our frame rate is too low.107 scene.render();108109 expect(monitor.lastFramesPerSecond).toBeLessThan(1000);110 expect(spyListener).toHaveBeenCalled();111 });112113 it('does not monitor frame rate while paused', function() {114 monitor = new FrameRateMonitor({115 scene : scene,116 quietPeriod : 0.001,117 warmupPeriod : 0.001,118 samplingWindow : 0.001,119 minimumFrameRateDuringWarmup : 1000,120 minimumFrameRateAfterWarmup : 1000121 });122123 var spyListener = jasmine.createSpy('listener');124 monitor.lowFrameRate.addEventListener(spyListener);125126 // Rendering once starts the quiet period127 scene.render();128129 // Wait until we're well past the end of the quiet period.130 spinWait(2);131132 // Rendering again records our first sample.133 scene.render();134135 monitor.pause();136137 // Wait well over a millisecond, which is the maximum frame time allowed by this instance.138 spinWait(2);139140 // Record our second sample. The monitor would notice that our frame rate is too low,141 // but it's paused.142 scene.render();143144 monitor.unpause();145146 scene.render();147148 expect(spyListener).not.toHaveBeenCalled();149 });150151 it('pausing multiple times requires unpausing multiple times', function() {152 monitor = new FrameRateMonitor({153 scene : scene,154 quietPeriod : 0.001,155 warmupPeriod : 0.001,156 samplingWindow : 0.001,157 minimumFrameRateDuringWarmup : 1000,158 minimumFrameRateAfterWarmup : 1000159 });160161 var spyListener = jasmine.createSpy('listener');162 monitor.lowFrameRate.addEventListener(spyListener);163164 monitor.pause();165 monitor.pause();166 monitor.unpause();167168 // Rendering once starts the quiet period169 scene.render();170171 // Wait until we're well past the end of the quiet period.172 spinWait(2);173174 // Rendering again records our first sample.175 scene.render();176177 // Wait well over a millisecond, which is the maximum frame time allowed by this instance.178 spinWait(2);179180 // Record our second sample. The monitor would notice that our frame rate is too low,181 // but it's paused.182 scene.render();183184 monitor.unpause();185186 scene.render();187188 expect(spyListener).not.toHaveBeenCalled();189 });190191 it('does not report a low frame rate during the quiet period', function() {192 monitor = new FrameRateMonitor({193 scene : scene,194 quietPeriod : 1.0,195 warmupPeriod : 0.001,196 samplingWindow : 0.001,197 minimumFrameRateDuringWarmup : 1000,198 minimumFrameRateAfterWarmup : 1000199 });200201 var spyListener = jasmine.createSpy('listener');202 monitor.lowFrameRate.addEventListener(spyListener);203204 // Rendering once starts the quiet period205 scene.render();206207 // Wait well over a millisecond, which is the maximum frame time allowed by this instance.208 spinWait(2);209210 // Render again. Even though our frame rate is too low, the monitor shouldn't raise the event because we're in the quiet period.211 scene.render();212213 expect(spyListener).not.toHaveBeenCalled();214 });215216 it('the nominalFrameRate event is raised after the warmup period if the frame rate returns to nominal', function() {217 monitor = new FrameRateMonitor({218 scene : scene,219 quietPeriod : 0.001,220 warmupPeriod : 0.001,221 samplingWindow : 0.001,222 minimumFrameRateDuringWarmup : 10,223 minimumFrameRateAfterWarmup : 10224 });225226 var lowListener = jasmine.createSpy('lowFrameRate');227 monitor.lowFrameRate.addEventListener(lowListener);228229 var nominalListener = jasmine.createSpy('nominalFrameRate');230 monitor.nominalFrameRate.addEventListener(nominalListener);231232 // Rendering once starts the quiet period233 scene.render();234235 // Wait until we're well past the end of the quiet period.236 spinWait(2);237238 // Rendering again records our first sample.239 scene.render();240241 // Wait 120 millseconds, which is over the maximum frame time allowed by this instance.242 spinWait(120);243244 // Record our second sample. The monitor should notice that our frame rate is too low.245 scene.render();246247 expect(monitor.lastFramesPerSecond).toBeLessThan(10);248 expect(lowListener).toHaveBeenCalled();249250 // Render as fast as possible for a samplingWindow, quietPeriod, and warmupPeriod.251 var endTime = getTimestamp() + 50;252 while (getTimestamp() < endTime) {253 scene.render();254 }255256 // The nominalFrameRate event should have been raised.
...
PerformanceWatchdogViewModelSpec.js
Source:PerformanceWatchdogViewModelSpec.js
...25 viewModel = undefined;26 }27 FrameRateMonitor.fromScene(scene).destroy();28 });29 function spinWait(milliseconds) {30 /*eslint-disable no-empty*/31 var endTime = getTimestamp() + milliseconds;32 while (getTimestamp() < endTime) {33 }34 /*eslint-enable no-empty*/35 }36 it('throws when constructed without a scene', function() {37 expect(function() {38 viewModel = new PerformanceWatchdogViewModel();39 }).toThrowDeveloperError();40 expect(function() {41 viewModel = new PerformanceWatchdogViewModel({});42 }).toThrowDeveloperError();43 });44 it('can be constructed with just a scene', function() {45 viewModel = new PerformanceWatchdogViewModel({46 scene : scene47 });48 expect(viewModel.lowFrameRateMessage).toBeDefined();49 expect(viewModel.lowFrameRateMessageDismissed).toBe(false);50 expect(viewModel.showingLowFrameRateMessage).toBe(false);51 expect(viewModel.scene).toBe(scene);52 });53 it('honors parameters to the constructor', function() {54 var options = {55 scene : scene,56 lowFrameRateMessage : 'why so slow?'57 };58 viewModel = new PerformanceWatchdogViewModel(options);59 expect(viewModel.lowFrameRateMessage).toBe('why so slow?');60 expect(viewModel.scene).toBe(scene);61 });62 it('shows a message on low frame rate', function() {63 var monitor = FrameRateMonitor.fromScene(scene);64 monitor.quietPeriod = 0.001;65 monitor.warmupPeriod = 0.001;66 monitor.samplingWindow = 0.001;67 monitor.minimumFrameRateDuringWarmup = 1000;68 monitor.minimumFrameRateAfterWarmup = 1000;69 viewModel = new PerformanceWatchdogViewModel({70 scene : scene71 });72 expect(viewModel.showingLowFrameRateMessage).toBe(false);73 // Rendering once starts the quiet period74 scene.render();75 // Wait until we're well past the end of the quiet period.76 spinWait(2);77 // Rendering again records our first sample.78 scene.render();79 // Wait well over a millisecond, which is the maximum frame time allowed by this instance.80 spinWait(2);81 // Record our second sample. The watchdog should notice that our frame rate is too low.82 scene.render();83 expect(viewModel.showingLowFrameRateMessage).toBe(true);84 });85 it('does not report a low frame rate during the queit period', function() {86 var monitor = FrameRateMonitor.fromScene(scene);87 monitor.quietPeriod = 1.0;88 monitor.warmupPeriod = 0.001;89 monitor.samplingWindow = 0.001;90 monitor.minimumFrameRateDuringWarmup = 1000;91 monitor.minimumFrameRateAfterWarmup = 1000;92 viewModel = new PerformanceWatchdogViewModel({93 scene : scene94 });95 // Rendering once starts the quiet period96 scene.render();97 // Wait well over a millisecond, which is the maximum frame time allowed by this instance.98 spinWait(2);99 // Render again. Even though our frame rate is too low, the watchdog shouldn't bark because we're in the quiet period.100 scene.render();101 expect(viewModel.showingLowFrameRateMessage).toBe(false);102 });103 it('the low frame rate message goes away after the warmup period if the frame rate returns to nominal', function() {104 var monitor = FrameRateMonitor.fromScene(scene);105 monitor.quietPeriod = 0.001;106 monitor.warmupPeriod = 0.001;107 monitor.samplingWindow = 0.001;108 monitor.minimumFrameRateDuringWarmup = 10;109 monitor.minimumFrameRateAfterWarmup = 10;110 viewModel = new PerformanceWatchdogViewModel({111 scene : scene112 });113 expect(viewModel.showingLowFrameRateMessage).toBe(false);114 // Rendering once starts the quiet period115 scene.render();116 // Wait until we're well past the end of the quiet period.117 spinWait(2);118 // Rendering again records our first sample.119 scene.render();120 // Wait 120 millseconds, which is over the maximum frame time allowed by this instance.121 spinWait(120);122 // Record our second sample. The watchdog should notice that our frame rate is too low.123 scene.render();124 expect(viewModel.showingLowFrameRateMessage).toBe(true);125 // Render as fast as possible for a samplingWindow, quietPeriod, and warmupPeriod.126 var endTime = getTimestamp() + 50;127 while (getTimestamp() < endTime) {128 scene.render();129 }130 // The low frame rate message should have gone away.131 expect(viewModel.showingLowFrameRateMessage).toBe(false);132 });133 it('does not show the low frame rate message again once it is dismissed', function() {134 var monitor = FrameRateMonitor.fromScene(scene);135 monitor.quietPeriod = 0.001;136 monitor.warmupPeriod = 0.001;137 monitor.samplingWindow = 0.001;138 monitor.minimumFrameRateDuringWarmup = 1000;139 monitor.minimumFrameRateAfterWarmup = 1000;140 viewModel = new PerformanceWatchdogViewModel({141 scene : scene142 });143 expect(viewModel.showingLowFrameRateMessage).toBe(false);144 // Rendering once starts the quiet period145 scene.render();146 // Wait until we're well past the end of the quiet period.147 spinWait(2);148 // Rendering again records our first sample.149 scene.render();150 // Wait well over a millisecond, which is the maximum frame time allowed by this instance.151 spinWait(2);152 // Record our second sample. The watchdog should notice that our frame rate is too low.153 scene.render();154 expect(viewModel.showingLowFrameRateMessage).toBe(true);155 viewModel.dismissMessage();156 // Render several slow frames. The message should not re-appear.157 scene.render();158 spinWait(2);159 scene.render();160 expect(viewModel.showingLowFrameRateMessage).toBe(false);161 });...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.sleep(5000).then(function() {7 driver.executeScript('mobile: spinWait', {duration: 10});8});9var webdriver = require('selenium-webdriver');10var driver = new webdriver.Builder()11 .withCapabilities({12 })13 .build();14driver.sleep(5000).then(function() {15 driver.executeScript('mobile: spinWait', {duration: 10});16});
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var path = require('path');4var fs = require('fs');5var _ = require('underscore');6var spawn = require('child_process').spawn;7var exec = require('child_process').exec;8var spawnSync = require('child_process').spawnSync;9var spawnOpts = {stdio: 'inherit', cwd: process.cwd(), env: process.env, encoding: 'utf8'};10var XCUITEST_TIMEOUT = 60000;11var XCUITEST_POLLING = 1000;12var desired = {13};14var driver = wd.promiseChainRemote('localhost', 4723);15driver.on('status', function (info) {16 console.log(info);17});18driver.on('command', function (meth, path, data) {19 console.log(' > ' + meth, path, data || '');20});21driver.on('http', function (meth, path, data) {22 console.log(' > ' + meth, path, data || '');23});24 .init(desired)25 .setImplicitWaitTimeout(5000)26 .then(function () {27 return driver.execute('mobile: spinWait', {28 });29 })30 .then(function () {31 })32 .fin(function () {33 return driver.quit();34 })35 .done();
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!!