Best JavaScript code snippet using wpt
cumulative-layout-shift-all-frames-test.js
Source:cumulative-layout-shift-all-frames-test.js
1/**2 * @license Copyright 2020 The Lighthouse Authors. All Rights Reserved.3 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.04 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.5 */6'use strict';7const CumulativeLayoutShiftAllFrames = require('../../../computed/metrics/cumulative-layout-shift-all-frames.js'); // eslint-disable-line max-len8const missingWeightedClsTrace = require('../../fixtures/traces/frame-metrics-m89.json');9const frameMetricsTrace = require('../../fixtures/traces/frame-metrics-m90.json');10const createTestTrace = require('../../create-test-trace.js');11/* eslint-env jest */12describe('Metrics: CLS All Frames', () => {13 it('should compute value', async () => {14 const context = {computedCache: new Map()};15 const result = await CumulativeLayoutShiftAllFrames.request(frameMetricsTrace, context);16 expect(result.value).toBeCloseTo(0.0276);17 });18 it('should use unweighted score for trace missing weighted score', async () => {19 const context = {computedCache: new Map()};20 const result = await CumulativeLayoutShiftAllFrames.request(missingWeightedClsTrace, context);21 expect(result.value).toBeCloseTo(0.459);22 });23 it('uses weighted_score_delta instead of score', async () => {24 const trace = createTestTrace({timeOrigin: 0, traceEnd: 2000});25 const mainFrame = trace.traceEvents[0].args.frame;26 const childFrame = 'CHILDFRAME';27 const cat = 'loading,rail,devtools.timeline';28 const context = {computedCache: new Map()};29 trace.traceEvents.push(30 /* eslint-disable max-len */31 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: mainFrame, url: 'https://example.com'}}},32 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: childFrame, parent: mainFrame, url: 'https://frame.com'}}},33 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: false}}},34 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 2, weighted_score_delta: 1, is_main_frame: false}}},35 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 3, weighted_score_delta: 1, is_main_frame: false}}}36 /* eslint-enable max-len */37 );38 const result = await CumulativeLayoutShiftAllFrames.request(trace, context);39 expect(result.value).toBe(3);40 });41 it('uses score if weighted_score_delta is unavailable', async () => {42 const trace = createTestTrace({timeOrigin: 0, traceEnd: 2000});43 const mainFrame = trace.traceEvents[0].args.frame;44 const childFrame = 'CHILDFRAME';45 const cat = 'loading,rail,devtools.timeline';46 const context = {computedCache: new Map()};47 trace.traceEvents.push(48 /* eslint-disable max-len */49 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: mainFrame, url: 'https://example.com'}}},50 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: childFrame, parent: mainFrame, url: 'https://frame.com'}}},51 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 1, is_main_frame: false}}},52 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 2, is_main_frame: false}}},53 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 3, is_main_frame: false}}}54 /* eslint-enable max-len */55 );56 const result = await CumulativeLayoutShiftAllFrames.request(trace, context);57 expect(result.value).toBe(6);58 });59 it('ignores had_recent_input for beginning of trace', async () => {60 const trace = createTestTrace({timeOrigin: 0, traceEnd: 2000});61 const mainFrame = trace.traceEvents[0].args.frame;62 const childFrame = 'CHILDFRAME';63 const cat = 'loading,rail,devtools.timeline';64 const context = {computedCache: new Map()};65 trace.traceEvents.push(66 /* eslint-disable max-len */67 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: mainFrame, url: 'https://example.com'}}},68 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: childFrame, parent: mainFrame, url: 'https://frame.com'}}},69 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: true, score: 1, weighted_score_delta: 1, is_main_frame: false}}},70 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: true, score: 1, weighted_score_delta: 1, is_main_frame: false}}},71 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: false}}},72 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: true, score: 2, weighted_score_delta: 1, is_main_frame: false}}},73 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 3, weighted_score_delta: 1, is_main_frame: false}}}74 /* eslint-enable max-len */75 );76 const result = await CumulativeLayoutShiftAllFrames.request(trace, context);77 expect(result.value).toBe(4);78 });79 it('collects layout shift data from main frame and all child frames', async () => {80 const trace = createTestTrace({timeOrigin: 0, traceEnd: 2000});81 const mainFrame = trace.traceEvents[0].args.frame;82 const childFrame = 'CHILDFRAME';83 const cat = 'loading,rail,devtools.timeline';84 const context = {computedCache: new Map()};85 trace.traceEvents.push(86 /* eslint-disable max-len */87 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: mainFrame, url: 'https://example.com'}}},88 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: childFrame, parent: mainFrame, url: 'https://frame.com'}}},89 {name: 'LayoutShift', cat, args: {frame: mainFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: true}}},90 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: false}}},91 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: false}}},92 {name: 'LayoutShift', cat, args: {frame: mainFrame, data: {had_recent_input: true, score: 1, weighted_score_delta: 1, is_main_frame: true}}},93 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: true, score: 1, weighted_score_delta: 1, is_main_frame: false}}}94 /* eslint-enable max-len */95 );96 const result = await CumulativeLayoutShiftAllFrames.request(trace, context);97 expect(result.value).toBe(3);98 });99 it('ignores layout shift data from other tabs', async () => {100 const trace = createTestTrace({timeOrigin: 0, traceEnd: 2000});101 const mainFrame = trace.traceEvents[0].args.frame;102 const childFrame = 'CHILDFRAME';103 const otherMainFrame = 'ANOTHERTABOPEN';104 const cat = 'loading,rail,devtools.timeline';105 const context = {computedCache: new Map()};106 trace.traceEvents.push(107 /* eslint-disable max-len */108 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: mainFrame, url: 'https://example.com'}}},109 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: childFrame, parent: mainFrame, url: 'https://frame.com'}}},110 {name: 'FrameCommittedInBrowser', cat, args: {data: {frame: otherMainFrame, url: 'https://example.com'}}},111 {name: 'LayoutShift', cat, args: {frame: mainFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: true}}},112 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: false}}},113 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: false}}},114 {name: 'LayoutShift', cat, args: {frame: mainFrame, data: {had_recent_input: true, score: 1, weighted_score_delta: 1, is_main_frame: true}}},115 {name: 'LayoutShift', cat, args: {frame: childFrame, data: {had_recent_input: true, score: 1, weighted_score_delta: 1, is_main_frame: false}}},116 {name: 'LayoutShift', cat, args: {frame: otherMainFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: false}}},117 {name: 'LayoutShift', cat, args: {frame: otherMainFrame, data: {had_recent_input: false, score: 1, weighted_score_delta: 1, is_main_frame: false}}}118 /* eslint-enable max-len */119 );120 const result = await CumulativeLayoutShiftAllFrames.request(trace, context);121 expect(result.value).toBe(3);122 });...
zsk011.js
Source:zsk011.js
1function parentReload(closeFlg){2 if (closeFlg == true) {3 var CMD = parent.document.getElementsByName('CMD');4 CMD[0].value = 'posisionSet';56 parentEnable();7 parent.document.forms[0].submit();8 }9}10function posclose(innerflg){1112 clearScreenParent(innerflg);1314 parent.YAHOO.subbox.subPanel.hide();15 parentEnable();16}17function parentReadOnly(){1819 setAllReadOnly(parent.document, true);2021 var childframe = parent.document.getElementsByName('childframe');22 if (childframe != null && childframe.length > 0) {2324 for (i = 0; i < childframe.length; i++) {25 var childdoc = parent.document.getElementsByName(childframe[i].value);26 setAllReadOnly(parent[childframe[i].value].document, true);27 }28 }29}30function parentEnable(){31 setAllReadOnly(parent.document, false);3233 var childframe = parent.document.getElementsByName('childframe');34 if (childframe != null && childframe.length > 0) {3536 for (i = 0; i < childframe.length; i++) {37 var childdoc = parent.document.getElementsByName(childframe[i].value);38 setAllReadOnly(parent[childframe[i].value].document, false);39 }40 }41}4243// o^{^Cxg44function checkStatus() {45 var paramStr = "";46 for(var i = 0; i < document.forms[0].elements.length; i++) {47 var key = document.forms[0].elements[i].name; // p[^L[48 var val = document.forms[0].elements[i].value; // p[^l4950 // vfªWI{bNXÌê¨`FbNÚÌÝo51 if (document.forms[0].elements[i].type == "radio") {52 if (!document.forms[0].elements[i].checked) {53 continue;54 }55 }56 57 // form É ép[^ð¶ñƵÄAµæ¾58 if (key.length > 0 && val.length > 0) {59 if (paramStr.length > 0) paramStr += "&";60 paramStr += (key + "=" + val);61 }62 }63 64 if (paramStr.length > 0) {65 // f[^XVÊM66 $.ajax({67 async: false,68 url:"../zaiseki/zsk011.do",69 type: "post",70 data: paramStr71 }).done(function( data ) {72 // f[^XVª®¹µ½×AEBhEð¶é73 window.opener.document.forms[0].CMD.value='reload';74 window.opener.document.forms[0].submit();75 window.close();76 }).fail(function(data){77 alert('error');78 });79 }80 return false;
...
man111.js
Source:man111.js
1function parentReload(closeFlg){2 if (closeFlg == true) {3 var CMD = parent.document.getElementsByName('CMD');4 CMD[0].value = 'posisionSet';56 parentEnable();7 parent.document.forms[0].submit();8 }9}10function posclose(innerflg){1112 clearScreenParent(innerflg);1314 parent.YAHOO.subbox.subPanel.hide();15 parentEnable();16}17function parentReadOnly(){1819 setAllReadOnly(parent.document, true);2021 var childframe = parent.document.getElementsByName('childframe');22 if (childframe != null && childframe.length > 0) {2324 for (i = 0; i < childframe.length; i++) {25 var childdoc = parent.document.getElementsByName(childframe[i].value);26 setAllReadOnly(parent[childframe[i].value].document, true);27 }28 }29}30function parentEnable(){31 setAllReadOnly(parent.document, false);3233 var childframe = parent.document.getElementsByName('childframe');34 if (childframe != null && childframe.length > 0) {3536 for (i = 0; i < childframe.length; i++) {37 var childdoc = parent.document.getElementsByName(childframe[i].value);38 setAllReadOnly(parent[childframe[i].value].document, false);39 }40 }41}
...
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var test = wpt('www.webpagetest.org', options);5 if (err) return console.error(err);6 test.childFrame(data.data.runs[1].firstView, 0, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10});11var wpt = require('webpagetest');12var options = {13};14var test = wpt('www.webpagetest.org', options);15 if (err) return console.error(err);16 test.childFrame(data.data.runs[1].firstView, 0, function(err, data) {17 if (err) return console.error(err);18 console.log(data);19 });20});21var wpt = require('webpagetest');22var options = {23};24var test = wpt('www.webpagetest.org', options);
Using AI Code Generation
1driver.waitForElementPresent('id=nav', 10000, function(err) {2 if (err) {3 console.log(err);4 return;5 }6 driver.getText('id=nav', function(err, text) {7 console.log(text);8 });9});10driver.waitForElementPresent('id=nav', 10000, function(err) {11 if (err) {12 console.log(err);13 return;14 }15 driver.getText('id=nav', function(err, text) {16 console.log(text);17 });18});19driver.waitForElementPresent('id=nav', 10000, function(err) {20 if (err) {21 console.log(err);22 return;23 }24 driver.getText('id=nav', function(err, text) {25 console.log(text);26 });27});28driver.waitForElementPresent('id=nav', 10000, function(err) {29 if (err) {30 console.log(err);31 return;32 }33 driver.getText('id=nav', function(err, text) {34 console.log(text);35 });36});37driver.waitForElementPresent('id=nav', 10000, function(err) {38 if (err) {39 console.log(err);40 return;41 }42 driver.getText('id=nav', function(err, text) {43 console.log(text);44 });45});46driver.waitForElementPresent('id=nav', 10000, function(err) {47 if (err) {48 console.log(err);49 return;50 }51 driver.getText('id=nav', function(err, text) {52 console.log(text);53 });54});55driver.waitForElementPresent('id=nav', 10000, function(err) {56 if (err) {57 console.log(err);58 return;59 }60 driver.getText('id=nav', function(err, text) {61 console.log(text);62 });63});64driver.waitForElementPresent('id=nav', 10000, function(err) {65 if (err) {66 console.log(err);67 return;68 }69 driver.getText('id=nav', function(err, text) {70 console.log(text);71 });72});73driver.waitForElementPresent('id=nav',
Using AI Code Generation
1var wptHook = require('wptHook').childFrame;2wptHook.childFrame();3var wptHook = require('wptHook');4wptHook.hook();5wptHook.hook();6wptHook.hook();7wptHook.hook();8wptHook.hook();9wptHook.hook();10wptHook.hook();11wptHook.hook();12wptHook.hook();13wptHook.hook();
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4wpt.runTest(options, function(err, data) {5 if (err) return console.error(err);6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data.data.median.firstView.SpeedIndex);9 });10});
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!!