Best JavaScript code snippet using wpt
index.js
Source:index.js
1// Move the mouse across the screen as a sine wave.2const robot = require('robotjs');3// Const returnPoint = {x: 626, y:31};4const pointToRight = {x: 1157, y: 340};5const pointToLeft = {x: 103, y: 365};6const pointToTop = {x: 680, y: 50};7const pointToTopRight = {x: 1012, y: 50};8const pointToTopLeft = {x: 264, y: 50};9const pointToBottom = {x: 680, y: 650};10const pointToBottomRight = {x: 1012, y: 650};11const pointToBottomLeft = {x: 264, y: 650};12const balade2 = [13 {position: {x: 12, y: 20}, tabPoint: [14 {x: 477, y: 268},15 {x: 298, y: 207},16 {x: 626, y: 193},17 {x: 774, y: 207},18 {x: 833, y: 150},19 {x: 743, y: 134}20 ], timeBefore: 3000, timeAfter: 30000, goTo: 'top'},21 {position: {x: 12, y: 19}, tabPoint: [22 {x: 686, y: 551},23 {x: 595, y: 298},24 {x: 665, y: 269},25 {x: 716, y: 149},26 {x: 626, y: 135}27 ], timeBefore: 3000, timeAfter: 30000, goTo: 'top'},28 {position: {x: 12, y: 18}, tabPoint: [29 {x: 565, y: 579},30 {x: 665, y: 596},31 {x: 713, y: 566},32 {x: 686, y: 521},33 {x: 566, y: 492},34 {x: 685, y: 404},35 {x: 775, y: 358},36 {x: 806, y: 315},37 {x: 865, y: 283},38 {x: 894, y: 239},39 {x: 896, y: 207},40 {x: 1015, y: 210}41 ], timeBefore: 500, timeAfter: 50000, goTo: 'right'},42 {position: {x: 13, y: 18}, tabPoint: [43 {x: 355, y: 120},44 {x: 416, y: 121}45 ], timeBefore: 2000, timeAfter: 9000, goTo: 'top'},46 {position: {x: 13, y: 17}, tabPoint: [47 {x: 297, y: 599},48 {x: 296, y: 539},49 {x: 335, y: 389},50 {x: 416, y: 389},51 {x: 385, y: 344},52 {x: 415, y: 300}53 ], timeBefore: 2000, timeAfter: 30000, goTo: 'top'},54 {position: {x: 13, y: 16}, tabPoint: [55 {x: 446, y: 106}56 ], timeBefore: 6000, timeAfter: 9000, goTo: 'top'},57 {position: {x: 13, y: 15}, tabPoint: [58 {x: 536, y: 567},59 {x: 416, y: 598},60 {x: 355, y: 567}61 ], timeBefore: 1500, timeAfter: 13000, goTo: 'left'},62 {position: {x: 12, y: 15}, tabPoint: [63 {x: 955, y: 449},64 {x: 894, y: 449},65 {x: 895, y: 508},66 {x: 745, y: 464},67 {x: 626, y: 464},68 {x: 535, y: 448},69 {x: 505, y: 434},70 {x: 356, y: 359},71 {x: 386, y: 284},72 {x: 326, y: 255},73 {x: 385, y: 225},74 {x: 326, y: 135}75 ], timeBefore: 1500, timeAfter: 50000, goTo: 'top'},76 {position: {x: 12, y: 14}, tabPoint: [77 {x: 326, y: 553},78 {x: 326, y: 494},79 {x: 446, y: 314},80 {x: 537, y: 298},81 {x: 625, y: 196},82 {x: 595, y: 150}83 ], timeBefore: 2000, timeAfter: 25000, goTo: 'top'},84 {position: {x: 12, y: 13}, tabPoint: [85 {x: 534, y: 597},86 {x: 565, y: 432},87 {x: 507, y: 315},88 {x: 445, y: 314},89 {x: 325, y: 285},90 {x: 536, y: 269},91 {x: 505, y: 194},92 {x: 625, y: 165},93 {x: 744, y: 134}94 ], timeBefore: 2500, timeAfter: 45000, goTo: 'topRight'},95 {position: {x: 12, y: 12}, tabPoint: [96 {x: 685, y: 613},97 {x: 596, y: 539},98 {x: 536, y: 569}99 ], timeBefore: 1500, timeAfter: 15000, goTo: 'left'},100 {position: {x: 11, y: 12}, tabPoint: [101 {x: 328, y: 522},102 {x: 447, y: 462}103 ], timeBefore: 6000, timeAfter: 9000, goTo: 'left'},104 {position: {x: 10, y: 12}, tabPoint: [105 {x: 863, y: 522},106 {x: 505, y: 551}107 ], timeBefore: 6000, timeAfter: 10000, goTo: 'left'},108 {position: {x: 9, y: 12}, tabPoint: [109 {x: 536, y: 268},110 {x: 775, y: 597}111 ], timeBefore: 6000, timeAfter: 8000, goTo: 'bottom'},112 {position: {x: 9, y: 13}, tabPoint: [113 {x: 714, y: 151},114 {x: 446, y: 343},115 {x: 476, y: 389}116 ], timeBefore: 1500, timeAfter: 13000, goTo: 'left'},117 {position: {x: 8, y: 13}, tabPoint: [118 {x: 983, y: 431},119 {x: 863, y: 551},120 {x: 745, y: 521}121 ], timeBefore: 1000, timeAfter: 13000, goTo: 'bottom'},122 {position: {x: 8, y: 14}, tabPoint: [123 {x: 775, y: 208},124 {x: 775, y: 386},125 {x: 744, y: 432},126 {x: 556, y: 582},127 {x: 298, y: 537}128 ], timeBefore: 3000, timeAfter: 20000, goTo: 'left'},129 {position: {x: 7, y: 14}, tabPoint: [130 {x: 1014, y: 507},131 {x: 924, y: 612}132 ], timeBefore: 3000, timeAfter: 10000, goTo: 'bottom'},133 {position: {x: 7, y: 15}, tabPoint: [134 {x: 774, y: 209},135 {x: 594, y: 328},136 {x: 715, y: 388},137 {x: 924, y: 522}138 ], timeBefore: 3000, timeAfter: 20000, goTo: 'bottom'},139 {position: {x: 7, y: 16}, tabPoint: [140 {x: 625, y: 283},141 {x: 625, y: 313},142 {x: 744, y: 491}143 ], timeBefore: 3500, timeAfter: 12000, goTo: 'bottom'},144 {position: {x: 7, y: 17}, tabPoint: [145 {x: 893, y: 178},146 {x: 862, y: 194},147 {x: 893, y: 238},148 {x: 655, y: 267},149 {x: 655, y: 297},150 {x: 685, y: 312},151 {x: 773, y: 386},152 {x: 982, y: 491},153 {x: 1042, y: 549},154 {x: 952, y: 564}155 ], timeBefore: 2500, timeAfter: 45000, goTo: 'bottom'},156 {position: {x: 7, y: 18}, tabPoint: [157 {x: 922, y: 253},158 {x: 834, y: 268},159 {x: 893, y: 297}160 ], timeBefore: 4000, timeAfter: 10000, goTo: 'right'},161 {position: {x: 8, y: 18}, tabPoint: [162 {x: 387, y: 313},163 {x: 417, y: 238},164 {x: 893, y: 89},165 {x: 982, y: 105},166 {x: 833, y: 209}167 ], timeBefore: 4000, timeAfter: 22000, goTo: 'bottom'},168 {position: {x: 8, y: 19}, tabPoint: [169 {x: 863, y: 135},170 {x: 922, y: 223}171 ], timeBefore: 4000, timeAfter: 8000, goTo: 'right'},172 {position: {x: 9, y: 19}, tabPoint: [173 {x: 269, y: 224},174 {x: 477, y: 180},175 {x: 389, y: 105},176 {x: 329, y: 135},177 {x: 950, y: 120},178 {x: 922, y: 194}179 ], timeBefore: 1000, timeAfter: 27000, goTo: 'right'},180 {position: {x: 10, y: 19}, tabPoint: [181 {x: 507, y: 255},182 {x: 626, y: 135},183 {x: 1011, y: 210},184 {x: 922, y: 460},185 {x: 952, y: 505}186 ], timeBefore: 6000, timeAfter: 24000, goTo: 'right'},187 {position: {x: 11, y: 19}, tabPoint: [188 {x: 506, y: 373},189 {x: 595, y: 387},190 {x: 625, y: 343},191 {x: 861, y: 462},192 {x: 773, y: 477},193 {x: 773, y: 505},194 {x: 803, y: 550}195 ], timeBefore: 4000, timeAfter: 29000, goTo: 'bottom'},196 {position: {x: 11, y: 20}, tabPoint: [197 {x: 862, y: 134},198 {x: 892, y: 180},199 {x: 952, y: 180},200 {x: 864, y: 253}201 ], timeBefore: 2000, timeAfter: 15000, goTo: 'right'}202];203const findMap = (balade, point) => {204 let res = 0;205 balade.forEach(map => {206 if (map.position.x === point.x && map.position.y === point.y) {207 res = balade.indexOf(map);208 }209 });210 return res;211};212const goToSide = point => {213 robot.moveMouse(point.x, point.y);214 robot.setMouseDelay(3000);215 robot.mouseClick();216};217const firstClickInTab = point => {218 robot.moveMouse(point.x, point.y);219 robot.mouseClick();220 robot.setMouseDelay(100);221};222const lastClickInTab = (point, delay) => {223 robot.moveMouse(point.x, point.y);224 robot.mouseClick();225 robot.setMouseDelay(delay);226};227const toMap = async (tabPoint, timeBefore, timeAfter) => {228 robot.setMouseDelay(timeBefore);229 await tabPoint.forEach(point => {230 if (point === tabPoint[0]) {231 firstClickInTab(point);232 } else if (point === tabPoint[tabPoint.length - 1]) {233 lastClickInTab(point, timeAfter);234 } else {235 robot.moveMouse(point.x, point.y);236 robot.mouseClick();237 }238 });239};240const changeMap = async goTo => {241 switch (goTo) {242 case 'top':243 await goToSide(pointToTop);244 break;245 case 'topRight':246 await goToSide(pointToTopRight);247 break;248 case 'topLeft':249 await goToSide(pointToTopLeft);250 break;251 case 'bottom':252 await goToSide(pointToBottom);253 break;254 case 'bottomRight':255 await goToSide(pointToBottomRight);256 break;257 case 'bottomLeft':258 await goToSide(pointToBottomLeft);259 break;260 case 'right':261 await goToSide(pointToRight);262 break;263 case 'left':264 await goToSide(pointToLeft);265 break;266 default:267 break;268 }269};270const main = async (balade, startPosition = 0) => {271 startPosition = (startPosition === 0) ? startPosition :272 findMap(balade2, startPosition);273 await balade.slice(startPosition, balade.length)274 .reduce(async (promise, map) => {275 await promise;276 console.log('Bot in the map :');277 console.log(map.position);278 await toMap(map.tabPoint, map.timeBefore,279 map.timeAfter).then(async () => {280 await changeMap(map.goTo);281 });282 }, Promise.resolve());283};284if (process.argv[2] === '-m') {285 const startPosition = {x: parseInt(process.argv[3], 10), y:286 parseInt(process.argv[4], 10)};287 main(balade2, startPosition);288} else {289 main(balade2);...
functions.js
Source:functions.js
1var hive = require('@hiveio/hive-js');2const fs = require("fs");3const { builtinModules } = require('module');45678module.exports={9 10 getAccounts:function(user,cb){11 hive.api.getAccounts(user, function(err, response){12 cb(response) 13 14 })15 },16 17 1819 getVotes:function(voter,cb){20 let a=[{}];21 let perm=[];22 let limit=23 hive.api.getAccountHistory(voter, -1, 1,function(err, result) {24 //console.log(result["0"]["0"]);25 //console.log(result["0"]["1"].timestamp);26 27 let currentTime=Date.now();28 // console.log(Date.now()-new Date(result["0"]["1"].timestamp).getTime())29 hive.api.getAccountHistory(voter,(result["0"]["0"]-1), 1000,function(err, result2) {30 //console.log(result2[999][0]);31 //console.log(result2[0][1].timestamp);32 for(let x=0; x<result2.length;x++){33 let voteTime=new Date(result2[x][1].timestamp).getTime();34 if((result2[x][1].op[0]=="effective_comment_vote")&&(currentTime-voteTime<604800000)&&(result2[x][1].op[1].voter=voter)&&(!perm.includes(result2[x][1].op[1].permlink))){35 36 perm.push(result2[x][1].op[1].permlink)37 a.push(38 {39 "timestamp":result2[x][1].timestamp,40 "link": "https://hive.blog/@"+result2[x][1].op[1].author+"/"+result2[x][1].op[1].permlink,41 "voter":result2[x][1].op[1].voter,42 "author":result2[x][1].op[1].author,43 "permlink":result2[x][1].op[1].permlink,44 "weight":result2[x][1].op[1].weight,45 "rshares":result2[x][1].op[1].rshares,46 "total_weight":parseInt(result2[x][1].op[1].total_vote_weight)47 4849 })50 515253 54 }55 56 57 58 }59 60 cb(a)61 62 });63 64 65 });666768 },69 calculateVotes:function(author,permlink,timestamp,rshares,cb){70 let before=0;71 let after=0;72 73 hive.api.getContent(author, permlink, function(err, result) {74 //console.log(err)75 if(err){76 console.log("SHIT, try again")77 cb({78 "curation":0,79 "post_time":-180 })81 82 }83 84 //nice json array sorting algorithm to sort voting time ascending --needed? NO :)85 result.active_votes.sort((a, b) =>new Date(a.time).getTime()-new Date(b.time).getTime());86 // calculate before and after rshares87 88 for(let x=0;x<result.active_votes.length;x++){89 90 if (new Date(result.active_votes[x].time).getTime()<new Date(timestamp).getTime()){91 before=before+result.active_votes[x].rshares92 }93 if (new Date(result.active_votes[x].time).getTime()>new Date(timestamp).getTime()){94 after=after+result.active_votes[x].rshares95 }96 }97 let penalty=0;98 let postTime=new Date(result.created).getTime();99 let voteTime=new Date(timestamp).getTime();100 let timeAfter=(voteTime-postTime)/(1000*60) 101 //define penalty for voting102 if (timeAfter<=1){103 penalty=0104 }105 if ((timeAfter>1)&&(timeAfter<=2)){106 penalty=0.2107 }108 if ((timeAfter>2)&&(timeAfter<=3)){109 penalty=0.4110 }111 if ((timeAfter>3)&&(timeAfter<=4)){112 penalty=0.6113 }114 if ((timeAfter>4)&&(timeAfter<=5)){115 penalty=0.8116 }117 if (timeAfter>5){118 penalty=1119 }120 let ratio=((Math.sqrt(parseFloat(before)+parseFloat(rshares))-Math.sqrt(parseFloat(before)))/Math.sqrt(parseFloat(result.net_rshares)))*penalty121 /*122 console.log("before",before)123 console.log("rshares",rshares)124 console.log("total",result.net_rshares)125 console.log("penalty",penalty)126 console.log("ratio",ratio)127 console.log("pay",parseFloat(result.pending_payout_value.split(" ")[0]))128 */129 let hive_arr = result.pending_payout_value;130 let hivePay = parseFloat(hive_arr.split(" ")[0]);131 let curation=hivePay*ratio*0.5132 133 if(hivePay==0){curation=0}134 cb({135 "curation":curation,136 "post_time":result.created137 })138 139 });140 141 142 },143144 145 146147}148
...
Timer.js
Source:Timer.js
1/*2 * Copyright 2016 Google Inc. All rights reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16'use strict';17var assert = require('chai').assert;18var sinon = require('sinon');19var Timer = require('../../src/Timer');20var now = require('../../src/util/now');21var defer = require('../../src/util/defer');22var wait = require('../wait');23suite('Timer', function() {24 test('start', function(done) {25 var spy = sinon.spy();26 var timer = new Timer({duration: 50});27 timer.addEventListener('timeout', spy);28 var timeBefore = now();29 assert.isFalse(timer.started());30 timer.start();31 assert.isTrue(timer.started());32 wait.untilSpyCalled(spy, function() {33 var timeAfter = now();34 assert.isFalse(timer.started());35 assert.isAtLeast(timeAfter - timeBefore, 50);36 done();37 });38 });39 test('stop', function(done) {40 var spy = sinon.spy();41 var timer = new Timer({duration: 10});42 timer.addEventListener('timeout', spy);43 assert.isFalse(timer.started());44 timer.start();45 assert.isTrue(timer.started());46 timer.stop();47 assert.isFalse(timer.started());48 setTimeout(function() {49 assert.isTrue(spy.notCalled);50 done();51 }, 50);52 });53 test('reset', function(done) {54 var spy = sinon.spy();55 var timer = new Timer({duration: 100});56 timer.addEventListener('timeout', spy);57 var timeBefore = now();58 timer.start();59 setTimeout(function() {60 assert.isTrue(spy.notCalled);61 timer.start();62 }, 50);63 wait.untilSpyCalled(spy, function() {64 var timeAfter = now();65 assert.isFalse(timer.started());66 assert.isAtLeast(timeAfter - timeBefore, 150);67 done();68 });69 });70 test('set duration after start with infinity', function(done) {71 var spy = sinon.spy();72 var timer = new Timer();73 timer.addEventListener('timeout', spy);74 var timeBefore = now();75 timer.start();76 defer(function() {77 timer.setDuration(50);78 });79 wait.untilSpyCalled(spy, function() {80 var timeAfter = now();81 assert.isAtLeast(timeAfter - timeBefore, 50);82 done();83 });84 });85 test('set duration when stopped', function(done) {86 var spy = sinon.spy();87 var timer = new Timer({duration: 50});88 timer.addEventListener('timeout', spy);89 assert.strictEqual(timer.duration(), 50);90 timer.setDuration(100);91 assert.strictEqual(timer.duration(), 100);92 var timeBefore = now();93 timer.start();94 wait.untilSpyCalled(spy, function() {95 var timeAfter = now();96 assert.isAtLeast(timeAfter - timeBefore, 100);97 done();98 });99 });100 test('increase duration when started', function(done) {101 var spy = sinon.spy();102 var timer = new Timer({duration: 50});103 timer.addEventListener('timeout', spy);104 var timeBefore = now();105 timer.start();106 defer(function() {107 timer.setDuration(100);108 });109 wait.untilSpyCalled(spy, function() {110 var timeAfter = now();111 assert.isAtLeast(timeAfter - timeBefore, 100);112 done();113 });114 });115 test('decrease duration when started', function(done) {116 var spy = sinon.spy();117 var timer = new Timer({duration: 100});118 timer.addEventListener('timeout', spy);119 timer.start();120 setTimeout(function() {121 assert.isTrue(spy.notCalled);122 timer.setDuration(10);123 assert.isTrue(spy.calledOnce);124 done();125 }, 50);126 });...
Using AI Code Generation
1var WPT = require('webpagetest');2var wpt = new WPT('API_KEY');3 if (err) return console.log(err);4 console.log(data);5 wpt.timeAfter(data.data.testId, 'loadEventEnd', function(err, data) {6 if (err) return console.log(err);7 console.log(data);8 });9});10{ data:11 { testId: '160825_G8_1a2a2e2f5e7c8a8b9d9a9f9d1f1c1e1f',12 statusText: 'Ok' }13{ data: { time: 1742.6 }, statusCode: 200, statusText: 'Ok' }
Using AI Code Generation
1var wpt = require('wpt.js');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.log(err);4 wpt.timeAfter(data.data.testId, 'loadEventEnd', function(err, data) {5 if (err) return console.log(err);6 console.log(data);7 });8});9{ data: '0.00' }
Using AI Code Generation
1var wpt = require('wpt');2 console.log(data);3});4var wpt = require('wpt');5 console.log(data);6});7var wpt = require('wpt');8wpt.getLocations(function(err, data) {9 console.log(data);10});11var wpt = require('wpt');12wpt.getTesters(function(err, data) {13 console.log(data);14});15var wpt = require('wpt');16 console.log(data);17});18var wpt = require('wpt');19 console.log(data);20});21var wpt = require('wpt');22 console.log(data);23});24var wpt = require('wpt');25 console.log(data);26});27var wpt = require('wpt');28 console.log(data);29});30var wpt = require('wpt');31 console.log(data);32});
Using AI Code Generation
1var wpt = require('webpagetest');2var config = require('./config.json');3var wpt = new WebPageTest(config.wptUrl, config.wptKey);4var url = config.url;5var options = {6 videoParams: {7 }8};9wpt.runTest(url, options, function (err, data) {10 if (err) return console.error(err);11 console.log(data);12 wpt.getTestResults(data.data.testId, function (err, data) {13 if (err) return console.error(err);14 console.log(data);15 });16});
Using AI Code Generation
1var wpt = require('./wpt.js');2var timeAfter = wpt.timeAfter;3 console.log(err, result);4});5var wpt = require('./wpt.js');6var timeBefore = wpt.timeBefore;7 console.log(err, result);8});9var wpt = require('./wpt.js');10var timeBetween = wpt.timeBetween;11 console.log(err, result);12});13var wpt = require('./wpt.js');14var getLocations = wpt.getLocations;15getLocations(function(err, result) {16 console.log(err, result);17});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getTestStatus('150319_4P_4e4e4b3b4d1f4c2e8b1d2b2b0e6e4c6a', function(err, data) {4 if (!err) {5 console.log(data);6 }7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org');10wpt.runTest('www.google.com', function(err, data) {11 if (!err) {12 console.log(data);13 }14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17wpt.runTest('www.google.com', {location: 'ec2-eu-west-1:Chrome'}, function(err, data) {18 if (!err) {19 console.log(data);20 }21});22var wpt = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org');24wpt.runTest('www.google.com', {location: 'ec2-eu-west-1:Chrome', connectivity: 'Cable', mobile: '0'}, function(err, data) {25 if (!err) {26 console.log(data);27 }28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.runTest('www.google.com', {location: 'ec2-eu-west-1:Chrome', connectivity: 'Cable', mobile: '0', label: 'My label'}, function(err, data) {32 if (!err) {33 console.log(data);34 }35});36var wpt = require('webpagetest');37var wpt = new WebPageTest('www.webpagetest.org');38wpt.runTest('www.google.com', {location:
Using AI Code Generation
1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.9e9f3d8e3a3a0a5b8927e8b1e6f7d6b0');3var options = {4};5 if (err) return console.error(err);6 console.log('Test status:', data.statusText);7 wpt.timeAfter(data.data.testId, 'DOMContentLoaded', function(err, data) {8 if (err) return console.error(err);9 console.log(data);10 });11});12var WebPageTest = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org', 'A.9e9f3d8e3a3a0a5b8927e8b1e6f7d6b0');14var options = {15};16 if (err) return console.error(err);17 console.log('Test status:', data.statusText);18 wpt.timeAfter(data.data.testId, 'DOMContentLoaded', function(err, data) {19 if (err) return console.error(err);20 console.log(data);21 });22});23var WebPageTest = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org', 'A.9e9
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!!