Best JavaScript code snippet using ava
CameraUtils.js
Source:CameraUtils.js
...34 return itowns.CameraUtils.transformCameraToLookAtTarget(35 globeView, camera, p).then(final => final.range);36 }, params);37 assert.ok(Math.abs(result - params.range) / params.range < 0.05);38 page.close();39 await page.close();40 });41 it('should look at coordinate like expected', async function _() {42 const page = await newGlobePage.bind(this)();43 const params = { longitude: 60, latitude: 40 };44 const result = await page.evaluate((p) => {45 const coord = new itowns.Coordinates('EPSG:4326', p.longitude, p.latitude, 0);46 const camera = globeView.camera.camera3D;47 return itowns.CameraUtils.transformCameraToLookAtTarget(48 globeView, camera, { coord }).then(final => final.coord);49 }, params);50 assert.equal(Math.round(result._values[0]), params.longitude);51 assert.equal(Math.round(result._values[1]), params.latitude);52 page.close();53 await page.close();54 });55 it('should tilt like expected', async function _() {56 const page = await newGlobePage.bind(this)();57 const params = { tilt: 50 };58 const result = await page.evaluate((p) => {59 const camera = globeView.camera.camera3D;60 return itowns.CameraUtils.transformCameraToLookAtTarget(61 globeView, camera, p).then(final => final.tilt);62 }, params);63 assert.equal(Math.round(result), params.tilt);64 page.close();65 await page.close();66 });67 it('should heading like expected', async function _() {68 const page = await newGlobePage.bind(this)();69 const params = { heading: 170 };70 const result = await page.evaluate((p) => {71 const camera = globeView.camera.camera3D;72 return itowns.CameraUtils.transformCameraToLookAtTarget(73 globeView, camera, p).then(final => final.heading);74 }, params);75 assert.equal(Math.round(result), params.heading);76 page.close();77 await page.close();78 });79 it('should heading, tilt, range and coordinate like expected', async function _() {80 const page = await newGlobePage.bind(this)();81 const result = await page.evaluate(() => {82 const camera = globeView.camera.camera3D;83 const params = { heading: 17,84 tilt: 44,85 range: 200000,86 longitude: 3,87 latitude: 46,88 coord: new itowns.Coordinates('EPSG:4326', 3, 47, 0) };89 return itowns.CameraUtils.transformCameraToLookAtTarget(90 globeView, camera, params).then(final => ({ params, final }));91 });92 assert.equal(Math.round(result.final.heading), result.params.heading);93 assert.equal(Math.round(result.final.tilt), result.params.tilt);94 assert.equal(Math.round(result.final.coord._values[0]), result.params.coord._values[0]);95 assert.equal(Math.round(result.final.coord._values[1]), result.params.coord._values[1]);96 assert.equal(Math.round(result.final.range / 10000) * 10000, result.params.range);97 page.close();98 await page.close();99 });100 it('should heading, tilt, range and coordinate like expected with animation (500ms)', async function _() {101 const page = await newGlobePage.bind(this)();102 const result = await page.evaluate(() => {103 const params = {104 heading: 17,105 tilt: 44,106 range: 200000,107 longitude: 3,108 latitude: 46,109 coord: new itowns.Coordinates('EPSG:4326', 3, 47, 0),110 time: 500 };111 const camera = globeView.camera.camera3D;112 return itowns.CameraUtils113 .animateCameraToLookAtTarget(globeView, camera, params).then(final =>114 ({ final, params }));115 });116 assert.equal(Math.round(result.final.heading), result.params.heading);117 assert.equal(Math.round(result.final.tilt), result.params.tilt);118 assert.equal(Math.round(result.final.coord._values[0]), result.params.coord._values[0]);119 assert.equal(Math.round(result.final.coord._values[1]), result.params.coord._values[1]);120 assert.equal(Math.round(result.final.range / 1000) * 1000, result.params.range);121 page.close();122 await page.close();123 });...
menu.js
Source:menu.js
1var shouldReloadList = 1;2var currentView;3function openMenu() {4 $(".tooltip").remove();5 $("#loadHome").unbind("click").bind("click", function(event){6 openHome();7 });8 $("#loadCreateEvent").unbind("click").bind("click", function(event){9 10 loadCreateEvent();11 });12 $("#loadEventListPage").unbind("click").bind("click", function(event){13 14 loadEventListPage();15 });16 $("#AddCredentials").unbind("click").bind("click", function(event){17 18 loadAddCredentialPage();19 });20 $("#loadCredentialList").unbind("click").bind("click", function(event){21 22 loadCredentialsListPage();23 });24 25 $("#closeMenu").unbind("click").bind("click", function(event){26 closeMenu();27 });28 $("#loadChangePIN").unbind("click").bind("click", function(event){29 loadChangePIN();30 });31 $("#menu-panel").addClass("menuOpen");32}33function openHome() {34 35 $("#addCredentialMenu").html("");36 37 if(currentView == "homePage") {38 closeMenu();39 return;40 }41 42 currentView = "homePage";43 window.location.href = "#homePage";44 closeMenu();45 46}47function closeMenu() {48 $("#menu-panel").removeClass("menuOpen");49}50function loadCreateEvent() {51 if(currentView == "createEventPage") {52 closeMenu();53 return;54 }55 $("#addCredentialMenu").html("");56 $("#addCredentialMenu").append('<input id="menuAccessibilityBtn" type="image" src="../resources/event.png">');57 $("#addCredentialMenu").unbind("click").bind("click", function(event){loadEventListPage();});58 $( "#createEventPage" ).load( "createEvent.html", function() {59 currentView = "createEventPage";60 window.location.href = "#createEventPage";61 closeMenu();62 });63}64function loadEventListPage() {65 if(currentView == "eventListPage") {66 closeMenu();67 return;68 }69 $("#addCredentialMenu").html("");70 $("#addCredentialMenu").append('<input id="menuAccessibilityBtn" type="image" src="../resources/addevent.png">');71 $("#addCredentialMenu").unbind("click").bind("click", function(event){loadCreateEvent();});72 73 if(shouldReloadList == 1) {74 $( "#eventListPage" ).load("eventlist.html", function() {75 currentView = "eventListPage";76 window.location.href = "#eventListPage";77 closeMenu();78 });79 }80 else {81 window.location.href = "#eventListPage";82 }83 84}85function loadAddCredentialPage() {86 if(currentView == "addCredentialPage") {87 closeMenu();88 return;89 }90 $("#addCredentialMenu").html("");91 $("#addCredentialMenu").append('<input id="menuAccessibilityBtn" type="image" src="../resources/list.png">');92 $("#addCredentialMenu").unbind("click").bind("click", function(event){loadCredentialsListPage();});93 94 $( "#addCredentialPage" ).load("addCredential.html", function() {95 currentView = "addCredentialPage";96 97 window.location.href = "#addCredentialPage";98 closeMenu();99 });100}101function loadCredentialsListPage() {102 if(currentView == "cerdentialsListPage") {103 closeMenu();104 return;105 }106 $( "#cerdentialsListPage" ).html("");107 $("#addCredentialMenu").html("");108 $("#addCredentialMenu").append('<input id="menuAccessibilityBtn" type="image" src="../resources/lock.png">');109 $("#addCredentialMenu").unbind("click").bind("click", function(event){110 $(".tooltip").remove();111 loadAddCredentialPage();112 113 });114 $( "#cerdentialsListPage" ).load("credentialsList.html", function() {115 116 currentView = "cerdentialsListPage";117 window.location.href = "#cerdentialsListPage";118 closeMenu();119 });120}121function loadChangePIN(){122 isResetPin = true;123 closeMenu();124 validateSession(loadCredentialsListPage);...
webexChange.js
Source:webexChange.js
...18 const browser = await puppeteer.launch();19 const page = await browser.newPage();20 // navigate to webex21 await page.goto("https://rensselaer.webex.com/").catch(() => {22 page.close();23 browser.close();24 console.log("Connection error!")25 process.exit(-1);26 });27 // click login button28 await Promise.all([29 page.waitForSelector("#IDToken1"),30 page.click("#guest_signin_split_button-trigger > div > button:nth-child(1)")31 ]).catch(error => {32 page.close();33 browser.close();34 console.log("Failed to click login button!")35 process.exit(-1);36 });37 // enter email38 await page.type("#IDToken1", email).catch(error => {39 page.close();40 browser.close();41 console.log("Failed to type email!")42 process.exit(-1);43 });44 await Promise.all([45 page.waitForSelector("#username"),46 page.click("#IDButton2")47 ]).catch(error => {48 page.close();49 browser.close();50 console.log("Incorrect email!")51 process.exit(-1);52 });53 // login54 await page.type("#username", uname).catch(error => {55 page.close();56 browser.close();57 console.log("Failed to type username!")58 process.exit(-1);59 });60 await page.type("#password", pword).catch(error => {61 page.close();62 browser.close();63 console.log("Failed to type password!")64 process.exit(-1);65 });66 await Promise.all([67 page.waitForSelector("#main_top_menu > div.nav_bar > div.top_nav > div.nav_t"),68 page.click("#homepage > div > div > div > form > button")69 ]).catch(error => {70 page.close();71 browser.close();72 console.log("Incorrect Username or Password!")73 process.exit(-1);74 });75 // nav to profile edit76 await page.goto("https://rensselaer.webex.com/webappng/sites/rensselaer/myprofile/home").catch(error => {77 page.close();78 browser.close();79 console.log("Failed to access namechange page!")80 process.exit(-1);81 });82 // open popup83 const popupPromise = new Promise(x => page.once('popup', x));84 await page.click("#viewMyProfile-changeMyProfile-Button").catch(error => {85 page.close();86 browser.close();87 console.log("Failed to open popup!")88 process.exit(-1);89 });90 const popup = await popupPromise;91 // edit name92 await popup.waitForSelector("body > main > article > section:nth-child(1) > a:nth-child(3)").catch(error => {93 page.close();94 browser.close();95 console.log("Failed to access namechange page!")96 process.exit(-1);97 });98 await Promise.all([99 popup.waitForSelector("body > main > article > section > div.row > div:nth-child(2) > input"),100 popup.click("body > main > article > section:nth-child(1) > a:nth-child(3)")101 ]).catch(error => {102 page.close();103 browser.close();104 console.log("Failed to access namechange page!")105 process.exit(-1);106 });107 await popup.evaluate( (pname) => {document.querySelector("body > main > article > section > div.row > div:nth-child(2) > input").value=pname}, pname).catch(error => {108 page.close();109 browser.close();110 console.log("Failed to submit namechange!")111 process.exit(-1);112 });113 await popup.click("body > main > article > section > div.form-actions > button").catch(error => {114 page.close();115 browser.close();116 console.log("Failed to submit namechange!")117 process.exit(-1);118 });119 await page.close();120 await browser.close();...
index.js
Source:index.js
1import Util from '../../../lib/common/index.js'2var Version = '4.4.0.6'3/**4 * @method pageEndTrack [åé页é¢å
³éäºä»¶]5 * @param {Function} callback åéæ°æ®åçåè°å½æ°6 */7function pageEndTrack (callback) {8 var time = +new Date()9 if (isPageShow === false) {10 /**11 * 页é¢ç¦»å¼æ¶é´ä¸º å
³éæ¶é´-åæ¢tabçæ¶é´+ä¹åtabåæ¢ç¦»å¼çæ¶é´12 */13 pageLeaveTime = time - pageHiddenTime + pageLeaveTime14 }15 /**16 * 页é¢åçæ¶é´ä¸º å½åæ¶é´ - 页é¢æå¼æ¶é´ - 页é¢éèæ¶é´17 */18 var pageStay = Number(time - pageStartTime - pageLeaveTime)19 if (pageStay < 0) {20 pageStay = Number(time - pageStartTime)21 }22 if (window.AnalysysAgent && window.AnalysysAgent.track) {23 window.AnalysysAgent.track('page_close', {24 pageStayTime: pageStay,25 $url: url,26 $title: pageTitle27 // sdkVersion: Version,28 // pageOpenTime: Util.format(new Date(pageOpenTime), 'yyyy-MM-dd hh:mm:ss.SSS')29 })30 Util.paramType(callback) === 'Function' && callback.call(callback, null)31 } else {32 console.log('Analsysy JS SDK not init!')33 }34 createTime()35}36/**37 * åå§ååæ°38 */39/**40 * @method createTime [åå§ååæ°]41 */42function createTime (startTime, title) {43 var time = +new Date()44 pageStartTime = startTime || time45 pageHiddenTime = startTime || time46 pageLeaveTime = 047 isPageShow = true48 url = window.location.href49 pageTitle = arguments.length > 1 ? title : document.title50}51var pageOpenTime = +new Date()52var pageStartTime = pageOpenTime53var pageHiddenTime = pageOpenTime54var pageLeaveTime = 055var isPageShow = true56var url = window.location.href57var pageTitle = document.title58var autoPageClose = true59/**60 * çå¬é¡µé¢æå¼ä¸å
³éäºä»¶61 */62if ('onpageShow' in window) {63 Util.addEvent(window, 'pageShow', function () {64 pageStartTime = pageHiddenTime = +new Date()65 })66 Util.addEvent(window, 'pagehide', function () {67 if (autoPageClose === true) {68 pageEndTrack()69 }70 })71} else {72 Util.addEvent(window, 'load', function () {73 pageStartTime = pageHiddenTime = +new Date()74 })75 Util.addEvent(window, 'beforeunload', function () {76 if (autoPageClose === true) {77 pageEndTrack()78 }79 })80}81/**82 * çå¬ç¦»å¼/è¿åtabä¸æªå
³é页é¢83 */84if ('onvisibilitychange' in document) {85 Util.addEvent(document, 'visibilitychange', function () {86 if (document.hidden) {87 isPageShow = false88 pageHiddenTime = +new Date()89 } else {90 isPageShow = true91 pageLeaveTime = +new Date() - pageHiddenTime + pageLeaveTime92 }93 })94}95function pageCloseInit (obj) {96 if (Util.paramType(obj) === 'Object' && Util.paramType(obj.autoPageClose) === 'Boolean') {97 autoPageClose = obj.autoPageClose98 }99}100window.AnalysysModule = Util.objMerge(window.AnalysysModule || {}, {101 pageClose: {102 Version: Version,103 pageEndTrack: pageEndTrack,104 init: pageCloseInit,105 createTime: createTime106 }107})...
menuTopFunctions.js
Source:menuTopFunctions.js
1function closeAllPages(){2 singletonRockerCommons.setClass('home','');3 singletonRockerCommons.setClass('concepts','');4 singletonRockerCommons.setClass('components','');5 //singletonRockerCommons.setClass('sourcecode','');6 singletonRockerCommons.setClass('about','');7 singletonRockerCommons.setClass('downloads','');8 singletonRockerCommons.hide('root');9 singletonRockerCommons.hide('divConcepts');10 singletonRockerCommons.hide('divComponents');11 singletonRockerCommons.hide('divSourceCode');12 singletonRockerCommons.hide('divAbout');13 singletonRockerCommons.hide('divDownloads');14};15function homePage(){16 closeAllPages();17 singletonRockerCommons.hide('divMenuLeft');18 singletonRockerCommons.setClass('home','active');19 singletonRockerCommons.show('root');20 new RockstarForm('root','http://localhost:4040');21};22function conceptsPage(){23 closeAllPages();24 singletonRockerCommons.hide('divMenuLeft');25 singletonRockerCommons.setClass('concepts','active');26 singletonRockerCommons.show('divConcepts');27};28function sourceCodePage(){29 closeAllPages();30 singletonRockerCommons.hide('divMenuLeft');31 singletonRockerCommons.setClass('sourcecode','active');32 singletonRockerCommons.show('divSourceCode');33};34function aboutPage(){35 closeAllPages();36 singletonRockerCommons.hide('divMenuLeft');37 singletonRockerCommons.setClass('about','active');38 singletonRockerCommons.show('divAbout');39 new AuthorForm('authorRoot');40};41function componentsPage(){42 closeAllPages();43 singletonRockerCommons.show('divMenuLeft');44 singletonRockerCommons.setClass('components','active');45 singletonRockerCommons.show('divComponents');46};47function downloadsPage(){48 closeAllPages();49 singletonRockerCommons.hide('divMenuLeft');50 singletonRockerCommons.setClass('downloads','active');51 singletonRockerCommons.show('divDownloads');...
ouibounce-modal.js
Source:ouibounce-modal.js
1(function () {2 var OuiBounceModalApp = angular.module('OuiBounceModalApp', []);3 4 OuiBounceModalApp.controller('OuiBounceCtrl', function ($scope, $timeout) {5 ouibounce(false, {6 aggressive: true,7 sensitivity: 100,8 callback: function () {9 $('#ouibounce-modal').modal('show');10 mixpanel.track("Showed Page Close Feedback Modal");11 }12 });13 $scope.sendFeedback = function (option, $event) {14 $timeout(function () { 15 $scope.sentFeedback = true;16 }, 300);17 18 $event.preventDefault();19 mixpanel.track("Page Close Feedback", { option: option });20 };21 $scope.otherOptionClicked = function () {22 $scope.otherOptionSelected = true;23 mixpanel.track("Page Close Feedback", { option: 'other' });24 };25 $scope.sendTextFeedback = function (text) {26 $timeout(function () {27 $scope.sentFeedback = true;28 }, 300);29 mixpanel.track("Page Close Feedback Other Text", { feedback: text });30 };31 $scope.noHelp = function () { 32 mixpanel.track("Page Close Feedback No Help");33 };34 });35 OuiBounceModalApp.directive('ouibouncemodal', function () {36 return {37 restrict: 'E',38 scope: {39 optionlist: '='40 },41 templateUrl: '../partials/ouibounce-modal.html',42 controller: 'OuiBounceCtrl'43 };44 });45 ...
Using AI Code Generation
1import test from 'ava';2import puppeteer from 'puppeteer';3test('My first test', async t => {4 const browser = await puppeteer.launch();5 const page = await browser.newPage();6 await page.close();7 await browser.close();8});9import test from 'ava';10import puppeteer from 'puppeteer';11test('My first test', async t => {12 const browser = await puppeteer.launch();13 const page = await browser.newPage();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.close();6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.close();13 await browser.close();14})();15const puppeteer = require('puppeteer');16(async () => {17 const browser = await puppeteer.launch();18 const page = await browser.newPage();19 await page.close();20 await browser.close();21})();22const puppeteer = require('puppeteer');23(async () => {24 const browser = await puppeteer.launch();25 const page = await browser.newPage();26 await page.close();27 await browser.close();28})();29const puppeteer = require('puppeteer');30(async () => {31 const browser = await puppeteer.launch();32 const page = await browser.newPage();33 await page.close();34 await browser.close();35})();36const puppeteer = require('puppeteer');37(async () => {38 const browser = await puppeteer.launch();39 const page = await browser.newPage();40 await page.close();41 await browser.close();42})();43const puppeteer = require('puppeteer');44(async () => {45 const browser = await puppeteer.launch();46 const page = await browser.newPage();47 await page.close();48 await browser.close();49})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await page.close();7 await browser.close();8})();9const puppeteer = require('puppeteer');10(async () => {11 const browser = await puppeteer.launch();12 const page = await browser.newPage();13 await page.screenshot({path: 'example.png'});14 await page.close();15 await browser.close();16})();17const puppeteer = require('puppeteer');18(async () => {19 const browser = await puppeteer.launch();20 const page = await browser.newPage();21 await page.screenshot({path: 'example.png'});22 await page.close();23 await browser.close();24})();25const puppeteer = require('puppeteer');26(async () => {27 const browser = await puppeteer.launch();28 const page = await browser.newPage();29 await page.screenshot({path: 'example.png'});30 await page.close();31 await browser.close();32})();33const puppeteer = require('puppeteer');34(async () => {35 const browser = await puppeteer.launch();36 const page = await browser.newPage();37 await page.screenshot({path: 'example.png'});38 await page.close();39 await browser.close();40})();41const puppeteer = require('puppeteer');42(async () => {43 const browser = await puppeteer.launch();44 const page = await browser.newPage();45 await page.screenshot({path: 'example.png'});46 await page.close();47 await browser.close();48})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4(async () => {5 const browser = await puppeteer.launch();6 const page = await browser.newPage();7 await page.screenshot({path: 'google.png'});8 await page.close();9 await browser.close();10})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4const PDFDocument = require('pdfkit');5const doc = new PDFDocument();6const { promisify } = require('util');7const pipeline = promisify(require('stream').pipeline);8const { exit } = require('process');9(async () => {10 const browser = await puppeteer.launch({11 });12 const page = await browser.newPage();13 await page.waitForSelector('input[title="Search"]', { visible: true });14 await page.type('input[title="Search"]', 'puppeteer');15 await page.keyboard.press('Enter');16 await page.waitForSelector('h3', { visible: true });17 const searchResults = await page.evaluate(() => {18 const searchResults = [];19 const results = document.querySelectorAll('h3');20 results.forEach(result => {21 searchResults.push(result.innerText);22 });23 return searchResults;24 });25 console.log(searchResults);26 await page.screenshot({ path: 'screenshot.png' });27 await page.pdf({ path: 'page.pdf', format: 'A4' });28 await page.close();29 await browser.close();30})();31const puppeteer = require('puppeteer');32const fs = require('fs');33const path = require('path');34const PDFDocument = require('pdfkit');35const doc = new PDFDocument();36const { promisify } = require('util');37const pipeline = promisify(require('stream').pipeline);38const { exit } = require('process');39(async () => {40 const browser = await puppeteer.launch({41 });42 const page = await browser.newPage();43 await page.waitForSelector('input[title="Search"]', { visible: true });44 await page.type('input[title="Search"]', 'puppeteer');45 await page.keyboard.press('Enter');46 await page.waitForSelector('h3', { visible:
Using AI Code Generation
1const test = require('ava');2const puppeteer = require('puppeteer');3test('test', async t => {4 const browser = await puppeteer.launch({headless: false});5 const page = await browser.newPage();6 await page.close();7 await browser.close();8});9const test = require('ava');10const puppeteer = require('puppeteer');11test('test', async t => {12 const browser = await puppeteer.launch({headless: false});13 const page = await browser.newPage();14 await page.close();15 return browser.close();16});17const test = require('ava');18const puppeteer = require('puppeteer');19test('test', async t => {20 const browser = await puppeteer.launch({headless: false});21 const page = await browser.newPage();22 await page.close();23 await browser.close();24});
Using AI Code Generation
1const puppeteer = require('puppeteer');2const page = await browser.newPage();3await page.close();4const puppeteer = require('puppeteer');5const page = await browser.newPage();6await page.reload();7const puppeteer = require('puppeteer');8const page = await browser.newPage();9await page.screenshot({path: 'example.png'});10const puppeteer = require('puppeteer');11const page = await browser.newPage();12await page.select('select#example', 'value');13const puppeteer = require('puppeteer');14const page = await browser.newPage();15await page.setContent('<html><body><div>Content</div></body></html>');16const puppeteer = require('puppeteer');17const page = await browser.newPage();18await page.setCookie(...cookies);19const puppeteer = require('puppeteer');20const page = await browser.newPage();21await page.setJavaScriptEnabled(false);22const puppeteer = require('puppeteer');23const page = await browser.newPage();
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!!