How to use waitForEvents method in wpt

Best JavaScript code snippet using wpt

connectivityTest.js

Source:connectivityTest.js Github

copy

Full Screen

...29 test : [function(component) {30 // we assume we start connected31 $A.test.assertTrue($A.clientService.isConnected());32 component.sendRequest();33 this.waitForEvents("SUCCESS")34 }, function(component) {35 this.sendAndWaitForSuccessfulRequest();36 }, function(component) {37 // We received a status change after a successful request, assert that the current status is SUCCESS:38 this.assertActionStatus("SUCCESS");39 $A.test.assertEquals("SUCCESS", component.get("v.eventsFired"));40 // ensure we still think we're connected41 $A.test.assertTrue($A.clientService.isConnected());42 }]43 },44 /**45 * Calling server action on unknown host throws connectionLost event.46 */47 testConnectionLost : {48 test : [function(component) {49 component.sendRequest();50 this.waitForEvents("SUCCESS");51 }, function(component) {52 this.sendAndWaitForFailedRequest();53 }, function(component) {54 // We received a status change after a failed request, assert that the current status is INCOMPLETE:55 this.assertActionStatus("INCOMPLETE");56 $A.test.assertEquals("SUCCESS connectionLost", $A.util.trim(component.get("v.eventsFired")));57 $A.test.assertFalse($A.clientService.isConnected());58 this.tryToConnect();59 // Wait for any status change:60 this.waitForActionStatusChange();61 }, function(component) {62 // connectionLost event is not repeated63 $A.test.assertEquals("SUCCESS connectionLost", $A.util.trim(component.get("v.eventsFired")));64 // still offline65 $A.test.assertFalse($A.clientService.isConnected());66 }]67 },68 /**69 * Test setting connected true while connected does not generate connectionResume event.70 */71 testSetConnectedTrueWhenConnected : {72 test : [function(component) {73 // we assume we start connected74 $A.test.assertTrue($A.clientService.isConnected());75 component.sendRequest();76 this.waitForEvents("SUCCESS");77 }, function(component) {78 // set connected to true should not affect the connected state:79 component.find("setConnectedTrueButton").get("e.press").fire();80 $A.test.assertTrue($A.clientService.isConnected());81 this.sendAndWaitForSuccessfulRequest();82 }, function(component) {83 // We received a status change after a successful request, assert that the current status is SUCCESS:84 this.assertActionStatus("SUCCESS");85 // There should be no events beside the layout change since we started connected:86 $A.test.assertEquals("SUCCESS", $A.util.trim(component.get("v.eventsFired")));87 $A.test.assertTrue($A.clientService.isConnected());88 }]89 },90 /**91 * Test calling setConnected(true) after setConnected(false) should fire an event and vice versa.92 */93 testSetConnectedTrueAfterDisconnect : {94 test : [function(component) {95 // we assume we start connected96 $A.test.assertTrue($A.clientService.isConnected());97 component.sendRequest();98 this.waitForEvents("SUCCESS");99 }, function(component) {100 component.find("setConnectedFalseButton").get("e.press").fire();101 this.waitForEvents("SUCCESS connectionLost")102 }, function(component) {103 component.find("setConnectedTrueButton").get("e.press").fire();104 this.waitForEvents("SUCCESS connectionLost connectionResumed");105 }]106 },107 /**108 * Test setting connected true after reconnecting does not generate connectionResumed event.109 */110 testSetConnectedTrueAfterReconnect : {111 test : [function(component) {112 // we assume we start connected113 $A.test.assertTrue($A.clientService.isConnected());114 component.sendRequest();115 this.waitForEvents("SUCCESS");116 }, function(component) {117 component.find("setConnectedFalseButton").get("e.press").fire();118 this.waitForEvents("SUCCESS connectionLost");119 }, function(component) {120 $A.test.assertFalse($A.clientService.isConnected());121 this.sendAndWaitForFailedRequest();122 }, function(component) {123 // We received a status change after a failed request, assert that the current status is INCOMPLETE:124 this.assertActionStatus("INCOMPLETE");125 $A.test.assertEquals("SUCCESS connectionLost", $A.util.trim(component.get("v.eventsFired")));126 $A.test.assertFalse($A.clientService.isConnected());127 component.find("setConnectedTrueButton").get("e.press").fire();128 this.waitForEvents("SUCCESS connectionLost connectionResumed");129 }, function(component) {130 // We have been set back to connected in the previous step:131 $A.test.assertTrue($A.clientService.isConnected());132 this.sendAndWaitForSuccessfulRequest();133 }, function(component) {134 // We received a status change after a successful request, assert that the current status is SUCCESS:135 this.assertActionStatus("SUCCESS");136 // ensure there are not 2 connectionResumed events generated after invoking setConnected when137 // and then making a successful request:138 $A.test.assertEquals("SUCCESS connectionLost connectionResumed", $A.util.trim(component.get("v.eventsFired")));139 $A.test.assertTrue($A.clientService.isConnected());140 }]141 },142 /**143 * Test setting connected false generates connectionLost event. Subsequent actions will succeed and generate144 * connectionResumed event145 */146 testSetConnectedFalse : {147 test : [function(component) {148 // we assume we start connected149 $A.test.assertTrue($A.clientService.isConnected());150 component.sendRequest();151 this.waitForEvents("SUCCESS");152 }, function(component) {153 component.find("setConnectedFalseButton").get("e.press").fire();154 this.waitForEvents("SUCCESS connectionLost");155 }, function(component) {156 $A.test.assertFalse($A.clientService.isConnected());157 this.sendAndWaitForSuccessfulRequest();158 }, function(component) {159 // We received a status change after a successful request, assert that the current status is SUCCESS:160 this.assertActionStatus("SUCCESS");161 $A.test.assertEquals("SUCCESS connectionLost connectionResumed", $A.util.trim(component.get("v.eventsFired")));162 $A.test.assertTrue($A.clientService.isConnected());163 }]164 },165 /**166 * Test setting connected false after disconnect does not generate connectionLost event.167 */168 testSetConnectedFalseAfterDisconnect : {169 test : [function(component) {170 // we assume we start connected171 $A.test.assertTrue($A.clientService.isConnected());172 component.sendRequest();173 this.waitForEvents("SUCCESS");174 }, function(component) {175 this.sendAndWaitForFailedRequest();176 }, function(component) {177 // We received a status change after a failed request, assert that the current status is INCOMPLETE:178 this.assertActionStatus("INCOMPLETE");179 $A.test.assertEquals("SUCCESS connectionLost", $A.util.trim(component.get("v.eventsFired")));180 $A.test.assertFalse($A.clientService.isConnected());181 }, function(component) {182 component.find("setConnectedFalseButton").get("e.press").fire();183 this.waitForEvents("SUCCESS connectionLost");184 }, function(component) {185 $A.test.assertFalse($A.clientService.isConnected());186 this.sendAndWaitForSuccessfulRequest();187 }, function(component) {188 // We received a status change after a successful request, assert that the current status is SUCCESS:189 this.assertActionStatus("SUCCESS");190 // ensure there are not 2 connectionLost events generated before a resume191 $A.test.assertEquals("SUCCESS connectionLost connectionResumed", $A.util.trim(component.get("v.eventsFired")));192 $A.test.assertTrue($A.clientService.isConnected());193 }]194 },195 /**196 * Test setting connected false then disconnect does not generate connectionLost event.197 */198 testSetConnectedFalseThenDisconnect : {199 test : [function(component) {200 // we assume we start connected201 $A.test.assertTrue($A.clientService.isConnected());202 component.sendRequest();203 this.waitForEvents("SUCCESS");204 }, function(component) {205 component.find("setConnectedFalseButton").get("e.press").fire();206 this.waitForEvents("SUCCESS connectionLost");207 }, function(component) {208 $A.test.assertFalse($A.clientService.isConnected());209 this.sendAndWaitForFailedRequest();210 }, function(component) {211 // We received a status change after a failed request, assert that the current status is INCOMPLETE:212 this.assertActionStatus("INCOMPLETE");213 $A.test.assertEquals("SUCCESS connectionLost", $A.util.trim(component.get("v.eventsFired")));214 $A.test.assertFalse($A.clientService.isConnected());215 }, function(component) {216 this.sendAndWaitForSuccessfulRequest();217 }, function(component) {218 // We received a status change after a successful request, assert that the current status is SUCCESS:219 this.assertActionStatus("SUCCESS");220 // ensure there are not 2 connectionLost events generated before a resume221 $A.test.assertEquals("SUCCESS connectionLost connectionResumed", $A.util.trim(component.get("v.eventsFired")));222 $A.test.assertTrue($A.clientService.isConnected());223 }]224 },225 /**226 * Calling server action succeeds after a prior connection failure.227 */228 testConnectionResumed : {229 test : [function(component) {230 component.sendRequest();231 this.waitForEvents("SUCCESS");232 }, function(component) {233 this.sendAndWaitForFailedRequest();234 }, function(component) {235 // We received a status change after a failed request, assert that the current status is INCOMPLETE:236 this.assertActionStatus("INCOMPLETE");237 $A.test.assertEquals("SUCCESS connectionLost", $A.util.trim(component.get("v.eventsFired")));238 $A.test.assertFalse($A.clientService.isConnected());239 this.sendAndWaitForSuccessfulRequest();240 }, function(component) {241 // We received a status change after a successful request, assert that the current status is SUCCESS:242 this.assertActionStatus("SUCCESS");243 $A.test.assertEquals("SUCCESS connectionLost connectionResumed", $A.util.trim(component.get("v.eventsFired")));244 $A.test.assertTrue($A.clientService.isConnected());245 this.sendAndWaitForSuccessfulRequest();...

Full Screen

Full Screen

OCSPCacheTests.ts

Source:OCSPCacheTests.ts Github

copy

Full Screen

...66 }67 });68 return found;69}70function waitForEvents(eventName: string, eventCount: number, rejectMessage?: string, timeoutMS: number = 5000): Promise<void> {71 return WaitForPromise((): boolean => {72 return findEvent(eventName) === eventCount;73 }, rejectMessage === undefined ? eventName : rejectMessage, timeoutMS);74}75function makeRequest(disableOCSPStapling: boolean = true): Promise<void> {76 return new Promise((resolve: (value: void) => void, reject: (reason: string) => void): void => {77 const testUrl: string = "https://www.microsoft.com/";78 const agent: CertCheckAgent = new CertCheckAgent();79 const testRequest: request.Request = request({80 followRedirect: false,81 url: testUrl82 }, (error: any, response: request.Response, body: any): void => {83 if (error !== null) {84 reject(error);85 } else {86 resolve();87 }88 });89 CertCheckAgent.forceDisableOCSPStapling = disableOCSPStapling;90 testRequest.agent = agent.GetAgent();91 testRequest.end();92 });93}94// https://github.com/chromium/badssl.com/issues/47795test.skip("Test OCSP Revoked", (done: jest.DoneCallback) => {96 // tslint:disable-next-line:no-console97 console.info("Name: Test OCSP Revoked");98 const testUrl: string = "https://revoked.badssl.com/";99 const agent: CertCheckAgent = new CertCheckAgent();100 const testRequest: request.Request = request({101 followRedirect: false,102 url: testUrl103 }, (error: any, response: request.Response, body: any): void => {104 try {105 expect(error).not.toBeUndefined();106 expect(error).not.toBeNull();107 expect(error.toString()).toContain("revoked");108 done();109 } catch (ex) {110 done(ex);111 }112 });113 testRequest.agent = agent.GetAgent();114 testRequest.end();115});116test.skip("Test OCSP Staple", async (done: jest.DoneCallback) => {117 // tslint:disable-next-line:no-console118 console.info("Name: Test OCSP Staple");119 await makeRequest(false);120 await waitForEvents("OCSPStapleReceivedEvent", 1);121 await waitForEvents("OCSPResponseRetrievedEvent", 0);122 done();123});124test.skip("Test OCSP Basic", async (done: jest.DoneCallback) => {125 // tslint:disable-next-line:no-console126 console.info("Name: Test OCSP Basic");127 await makeRequest();128 await waitForEvents("OCSPResponseRetrievedEvent", 1);129 await waitForEvents("OCSPMemoryCacheStoreEvent", 1);130 await waitForEvents("OCSPDiskCacheStoreEvent", 1);131 done();132});133test.skip("Test OCSP 2nd request mem cache hit.", async (done: jest.DoneCallback) => {134 // tslint:disable-next-line:no-console135 console.info("Name: Test OCSP 2nd request mem cache hit.");136 await makeRequest();137 await waitForEvents("OCSPResponseRetrievedEvent", 1);138 await waitForEvents("OCSPMemoryCacheStoreEvent", 1);139 await waitForEvents("OCSPDiskCacheStoreEvent", 1);140 events = [];141 await makeRequest();142 await waitForEvents("OCSPResponseRetrievedEvent", 0);143 await waitForEvents("OCSPMemoryCacheStoreEvent", 0);144 await waitForEvents("OCSPDiskCacheStoreEvent", 0);145 await waitForEvents("OCSPDiskCacheHitEvent", 0);146 await waitForEvents("OCSPMemoryCacheHitEvent", 1);147 done();148});149test.skip("Test OCSP expirey refreshes.", async (done: jest.DoneCallback) => {150 // tslint:disable-next-line:no-console151 console.info("Name: Test OCSP expirey refreshes.");152 await makeRequest();153 await waitForEvents("OCSPResponseRetrievedEvent", 1);154 await waitForEvents("OCSPMemoryCacheStoreEvent", 1);155 await waitForEvents("OCSPDiskCacheStoreEvent", 1);156 events = [];157 CertCheckAgent.testTimeOffset = 1000 * 60 * 60 * 24 * 7.5;158 await makeRequest();159 await waitForEvents("OCSPResponseRetrievedEvent", 1);160 await waitForEvents("OCSPMemoryCacheStoreEvent", 1);161 await waitForEvents("OCSPDiskCacheStoreEvent", 1);162 await waitForEvents("OCSPDiskCacheHitEvent", 0);163 await waitForEvents("OCSPCacheEntryExpiredEvent", 1);164 done();165});166test.skip("Test OCSP expirey approaching refreshes.", async (done: jest.DoneCallback) => {167 // tslint:disable-next-line:no-console168 console.info("Name: Test OCSP expirey approaching refreshes.");169 await makeRequest();170 await waitForEvents("OCSPResponseRetrievedEvent", 1);171 await waitForEvents("OCSPMemoryCacheStoreEvent", 1);172 await waitForEvents("OCSPDiskCacheStoreEvent", 1);173 events = [];174 CertCheckAgent.testTimeOffset = 1000 * 60 * 60 * 24 * 3.5;175 await makeRequest();176 await waitForEvents("OCSPResponseRetrievedEvent", 1);177 await waitForEvents("OCSPMemoryCacheStoreEvent", 1);178 await waitForEvents("OCSPDiskCacheStoreEvent", 1);179 await waitForEvents("OCSPCacheUpdateNeededEvent", 1);180 await waitForEvents("OCSPCacheUpdateCompleteEvent", 1);181 done();182});183test.skip("Test OCSP invalid cert refreshes.", async (done: jest.DoneCallback) => {184 // tslint:disable-next-line:no-console185 console.info("Name: invalid cert refreshes.");186 await makeRequest();187 await waitForEvents("OCSPResponseRetrievedEvent", 1);188 await waitForEvents("OCSPMemoryCacheStoreEvent", 1);189 await waitForEvents("OCSPDiskCacheStoreEvent", 1);190 events = [];191 CertCheckAgent.forceReinitDiskCache();192 const dir: string = path.join(cacheDir, "if-you-need-to-delete-this-open-an-issue-async-disk-cache", "microsoft-cognitiveservices-speech-sdk-cache");193 fs.readdir(dir, (error: NodeJS.ErrnoException, files: string[]): void => {194 files.forEach((value: string, index: number, array: string[]): void => {195 const file: string = path.join(dir, value);196 const content: Buffer = fs.readFileSync(file);197 content.set([2], 7);198 fs.writeFileSync(file, content);199 });200 });201 await makeRequest();202 await waitForEvents("OCSPResponseRetrievedEvent", 1);203 await waitForEvents("OCSPMemoryCacheStoreEvent", 2);204 await waitForEvents("OCSPDiskCacheStoreEvent", 1);205 await waitForEvents("OCSPCacheFetchErrorEvent", 1);206 await waitForEvents("OCSPCacheMissEvent", 1);207 done();...

Full Screen

Full Screen

background-services-events.js

Source:background-services-events.js Github

copy

Full Screen

...16 await dp.BackgroundService.onceRecordingStateChanged();17 dp.BackgroundService.setRecording({shouldRecord: false, service: 'backgroundSync'});18 await dp.BackgroundService.onceRecordingStateChanged();19}20async function waitForEvents(dp, numEvents) {21 const events = [];22 for (let i = 0; i < numEvents; i++)23 events.push(await dp.BackgroundService.onceBackgroundServiceEventReceived());24 return events.map(event => event.params.backgroundServiceEvent).map(event => {25 // Remove the `serviceWorkerRegistrationId` property since it can change.26 delete event.serviceWorkerRegistrationId;27 // Sort the metadata.28 event.eventMetadata = event.eventMetadata.sort(29 (m1, m2) => JSON.stringify(m1) < JSON.stringify(m2) ? -1 : 1);30 return event;31 });32}33(async function(testRunner) {34 var {page, session, dp} = await testRunner.startURL(35 'resources/background-services.html',36 `Tests that the expected events are received.`);37 await session.evaluateAsync('installSW()');38 await setUp(dp);39 testRunner.log('Background Fetch Success:');40 session.evaluate(`sw.backgroundFetch.fetch('my-fetch-success', 'background-fetch.txt')`);41 testRunner.log(await waitForEvents(dp, 5));42 testRunner.log('Background Fetch Failure:');43 session.evaluate(`sw.backgroundFetch.fetch('my-fetch-failure', '/missing/')`);44 testRunner.log(await waitForEvents(dp, 5));45 testRunner.log('Background Sync Success:');46 session.evaluate(`sw.sync.register('background-sync-resolve')`);47 testRunner.log(await waitForEvents(dp, 3));48 testRunner.log('Background Sync Failure:');49 session.evaluate(`sw.sync.register('background-sync-reject')`);50 testRunner.log(await waitForEvents(dp, 3));51 await tearDown(dp);52 testRunner.completeTest();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) console.log(err);4 else console.log(data);5});6{ data: 7 { location: 'Dulles:Chrome',8 [ { firstView: [Object],9 repeatViewDevTools: [Object] } ],

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var waitForEvents = wpt.waitForEvents;3var events = ['onLoad', 'onContentLoad'];4waitForEvents(events, function() {5});6var wpt = require('wpt');7var waitForEvents = wpt.waitForEvents;8var events = ['onLoad', 'onContentLoad'];9waitForEvents(events, function() {10});11var wpt = require('wpt');12var waitForEvents = wpt.waitForEvents;13var events = ['onLoad', 'onContentLoad'];14waitForEvents(events, function() {15});16var wpt = require('wpt');17var waitForEvents = wpt.waitForEvents;18var events = ['onLoad', 'onContentLoad'];19waitForEvents(events, function() {20});21var wpt = require('wpt');22var waitForEvents = wpt.waitForEvents;23var events = ['onLoad', 'onContentLoad'];24waitForEvents(events, function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require('wptdriver');2var driver = new wptDriver({host: 'localhost', port: 8080});3driver.waitForEvents(['load'], function (err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wptDriver = require('wptdriver');11var driver = new wptDriver({host: 'localhost', port: 8080});12driver.waitForEvents(['load'], function (err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wptDriver = require('wptdriver');20var driver = new wptDriver({host: 'localhost', port: 8080});21driver.waitForEvents(['load'], function (err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wptDriver = require('wptdriver');29var driver = new wptDriver({host: 'localhost', port: 8080});30driver.waitForEvents(['load'], function (err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wptDriver = require('wptdriver');38var driver = new wptDriver({host: 'localhost', port: 8080});39driver.waitForEvents(['load'], function (err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wptDriver = require('wptdriver');47var driver = new wptDriver({host: 'localhost', port: 8080});48driver.waitForEvents(['load'], function (err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wptDriver = require('wptdriver');56var driver = new wptDriver({host: 'localhost', port: 8080

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptool = require('wptool');2var wptool = new wptool();3wptool.waitForEvents(function (err, data) {4 console.log(data);5});6{7 "data": {8 }9}10wptool.stop();11var wptool = require('wptool');12var wptool = new wptool();13wptool.fireEvent('event_name', {key: 'value'});14var wptool = require('wptool');15var wptool = new wptool();16wptool.fireEvent('event_name', {key: 'value'}, true);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4wpt.runTest(url, options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log('Test status: ' + data.statusText);9 if (data.statusCode == 200) {10 console.log('Test completed, results available at ' + data.data.userUrl);11 console.log('View the test at ' + data.data.summaryCSV);12 } else if (data.statusCode > 200) {13 console.log('Test failed to complete. Status Text: ' + data.statusText + '. Status Code: ' + data.statusCode);14 }15 }16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require('wptdriver');2wptDriver.waitForEvents(['load'], function() {3 var title = wptDriver.getTitle();4 wptDriver.log(title);5});6var wptDriver = require('wptdriver');7wptDriver.waitForEvents(['click'], function(events) {8 var target = events[0].target;9 wptDriver.log(target);10 wptDriver.click(target);11});12var wptDriver = require('wptdriver');13wptDriver.waitForEvents(['click', 'load'], function(events) {14 var target = events[0].target;15 wptDriver.log(target);16 wptDriver.click(target);17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require('wptdriver');2wptDriver.waitForEvents(function() {3 callback();4});5var wptDriver = {6 waitForEvents: function(callback) {7 }8};9module.exports = wptDriver;

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful