Best JavaScript code snippet using wpt
templates.js
Source:templates.js
1/**2 * Default list of commands to execute for a PeerConnection test.3 */4var commandsPeerConnection = [5 [6 'PC_LOCAL_GUM',7 function (test) {8 test.pcLocal.getAllUserMedia(function () {9 test.next();10 });11 }12 ],13 [14 'PC_REMOTE_GUM',15 function (test) {16 test.pcRemote.getAllUserMedia(function () {17 test.next();18 });19 }20 ],21 [22 'PC_LOCAL_CHECK_INITIAL_SIGNALINGSTATE',23 function (test) {24 is(test.pcLocal.signalingState, "stable",25 "Initial local signalingState is 'stable'");26 test.next();27 }28 ],29 [30 'PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE',31 function (test) {32 is(test.pcRemote.signalingState, "stable",33 "Initial remote signalingState is 'stable'");34 test.next();35 }36 ],37 [38 'PC_LOCAL_CREATE_OFFER',39 function (test) {40 test.createOffer(test.pcLocal, function () {41 is(test.pcLocal.signalingState, "stable",42 "Local create offer does not change signaling state");43 if (!test.pcRemote) {44 send_message({"offer": test.pcLocal._last_offer,45 "media_constraints": test.pcLocal.constraints});46 }47 test.next();48 });49 }50 ],51 [52 'PC_LOCAL_SET_LOCAL_DESCRIPTION',53 function (test) {54 test.setLocalDescription(test.pcLocal, test.pcLocal._last_offer, function () {55 is(test.pcLocal.signalingState, "have-local-offer",56 "signalingState after local setLocalDescription is 'have-local-offer'");57 test.next();58 });59 }60 ],61 [62 'PC_REMOTE_GET_OFFER',63 function (test) {64 if (test.pcLocal) {65 test._local_offer = test.pcLocal._last_offer;66 test._local_constraints = test.pcLocal.constraints;67 test.next();68 } else {69 wait_for_message().then(function(message) {70 ok("offer" in message, "Got an offer message");71 test._local_offer = new mozRTCSessionDescription(message.offer);72 test._local_constraints = message.media_constraints;73 test.next();74 });75 }76 }77 ],78 [79 'PC_REMOTE_SET_REMOTE_DESCRIPTION',80 function (test) {81 test.setRemoteDescription(test.pcRemote, test._local_offer, function () {82 is(test.pcRemote.signalingState, "have-remote-offer",83 "signalingState after remote setRemoteDescription is 'have-remote-offer'");84 test.next();85 });86 }87 ],88 [89 'PC_REMOTE_CREATE_ANSWER',90 function (test) {91 test.createAnswer(test.pcRemote, function () {92 is(test.pcRemote.signalingState, "have-remote-offer",93 "Remote createAnswer does not change signaling state");94 if (!test.pcLocal) {95 send_message({"answer": test.pcRemote._last_answer,96 "media_constraints": test.pcRemote.constraints});97 }98 test.next();99 });100 }101 ],102 [103 'PC_LOCAL_GET_ANSWER',104 function (test) {105 if (test.pcRemote) {106 test._remote_answer = test.pcRemote._last_answer;107 test._remote_constraints = test.pcRemote.constraints;108 test.next();109 } else {110 wait_for_message().then(function(message) {111 ok("answer" in message, "Got an answer message");112 test._remote_answer = new mozRTCSessionDescription(message.answer);113 test._remote_constraints = message.media_constraints;114 test.next();115 });116 }117 }118 ],119 [120 'PC_LOCAL_SET_REMOTE_DESCRIPTION',121 function (test) {122 test.setRemoteDescription(test.pcLocal, test._remote_answer, function () {123 is(test.pcLocal.signalingState, "stable",124 "signalingState after local setRemoteDescription is 'stable'");125 test.next();126 });127 }128 ],129 [130 'PC_REMOTE_SET_LOCAL_DESCRIPTION',131 function (test) {132 test.setLocalDescription(test.pcRemote, test.pcRemote._last_answer, function () {133 is(test.pcRemote.signalingState, "stable",134 "signalingState after remote setLocalDescription is 'stable'");135 test.next();136 });137 }138 ],139 [140 'PC_LOCAL_CHECK_MEDIA_STREAMS',141 function (test) {142 test.pcLocal.checkMediaStreams(test._remote_constraints);143 test.next();144 }145 ],146 [147 'PC_REMOTE_CHECK_MEDIA_STREAMS',148 function (test) {149 test.pcRemote.checkMediaStreams(test._local_constraints);150 test.next();151 }152 ],153 [154 'PC_LOCAL_CHECK_MEDIA_FLOW_PRESENT',155 function (test) {156 test.pcLocal.checkMediaFlowPresent(function () {157 test.next();158 });159 }160 ],161 [162 'PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT',163 function (test) {164 test.pcRemote.checkMediaFlowPresent(function () {165 test.next();166 });167 }168 ]169];170/**171 * Default list of commands to execute for a Datachannel test.172 */173var commandsDataChannel = [174 [175 'PC_LOCAL_GUM',176 function (test) {177 test.pcLocal.getAllUserMedia(function () {178 test.next();179 });180 }181 ],182 [183 'PC_REMOTE_GUM',184 function (test) {185 test.pcRemote.getAllUserMedia(function () {186 test.next();187 });188 }189 ],190 [191 'PC_CHECK_INITIAL_SIGNALINGSTATE',192 function (test) {193 is(test.pcLocal.signalingState, "stable",194 "Initial local signalingState is stable");195 is(test.pcRemote.signalingState, "stable",196 "Initial remote signalingState is stable");197 test.next();198 }199 ],200 [201 'PC_LOCAL_CREATE_DATA_CHANNEL',202 function (test) {203 var channel = test.pcLocal.createDataChannel({});204 is(channel.binaryType, "blob", channel + " is of binary type 'blob'");205 is(channel.readyState, "connecting", channel + " is in state: 'connecting'");206 is(test.pcLocal.signalingState, "stable",207 "Create datachannel does not change signaling state");208 test.next();209 }210 ],211 [212 'PC_LOCAL_CREATE_OFFER',213 function (test) {214 test.pcLocal.createOffer(function (offer) {215 is(test.pcLocal.signalingState, "stable",216 "Local create offer does not change signaling state");217 ok(offer.sdp.contains("m=application"),218 "m=application is contained in the SDP");219 test.next();220 });221 }222 ],223 [224 'PC_LOCAL_SET_LOCAL_DESCRIPTION',225 function (test) {226 test.setLocalDescription(test.pcLocal, test.pcLocal._last_offer, function () {227 is(test.pcLocal.signalingState, "have-local-offer",228 "signalingState after local setLocalDescription is 'have-local-offer'");229 test.next();230 });231 }232 ],233 [234 'PC_REMOTE_SET_REMOTE_DESCRIPTION',235 function (test) {236 test.setRemoteDescription(test.pcRemote, test.pcLocal._last_offer, function () {237 is(test.pcRemote.signalingState, "have-remote-offer",238 "signalingState after remote setRemoteDescription is 'have-remote-offer'");239 test.next();240 });241 }242 ],243 [244 'PC_REMOTE_CREATE_ANSWER',245 function (test) {246 test.createAnswer(test.pcRemote, function () {247 is(test.pcRemote.signalingState, "have-remote-offer",248 "Remote create offer does not change signaling state");249 test.next();250 });251 }252 ],253 [254 'PC_LOCAL_SET_REMOTE_DESCRIPTION',255 function (test) {256 test.setRemoteDescription(test.pcLocal, test.pcRemote._last_answer, function () {257 is(test.pcLocal.signalingState, "stable",258 "signalingState after local setRemoteDescription is 'stable'");259 test.next();260 });261 }262 ],263 [264 'PC_REMOTE_SET_LOCAL_DESCRIPTION',265 function (test) {266 test.setLocalDescription(test.pcRemote, test.pcRemote._last_answer,267 function (sourceChannel, targetChannel) {268 is(sourceChannel.readyState, "open", test.pcLocal + " is in state: 'open'");269 is(targetChannel.readyState, "open", test.pcRemote + " is in state: 'open'");270 is(test.pcRemote.signalingState, "stable",271 "signalingState after remote setLocalDescription is 'stable'");272 test.next();273 }274 );275 }276 ],277 [278 'PC_LOCAL_CHECK_MEDIA_STREAMS',279 function (test) {280 test.pcLocal.checkMediaStreams(test.pcRemote.constraints);281 test.next();282 }283 ],284 [285 'PC_REMOTE_CHECK_MEDIA_STREAMS',286 function (test) {287 test.pcRemote.checkMediaStreams(test.pcLocal.constraints);288 test.next();289 }290 ],291 [292 'PC_LOCAL_CHECK_MEDIA_FLOW_PRESENT',293 function (test) {294 test.pcLocal.checkMediaFlowPresent(function () {295 test.next();296 });297 }298 ],299 [300 'PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT',301 function (test) {302 test.pcRemote.checkMediaFlowPresent(function () {303 test.next();304 });305 }306 ],307 [308 'SEND_MESSAGE',309 function (test) {310 var message = "Lorem ipsum dolor sit amet";311 test.send(message, function (channel, data) {312 is(data, message, "Message correctly transmitted from pcLocal to pcRemote.");313 test.next();314 });315 }316 ],317 [318 'SEND_BLOB',319 function (test) {320 var contents = ["At vero eos et accusam et justo duo dolores et ea rebum."];321 var blob = new Blob(contents, { "type" : "text/plain" });322 test.send(blob, function (channel, data) {323 ok(data instanceof Blob, "Received data is of instance Blob");324 is(data.size, blob.size, "Received data has the correct size.");325 getBlobContent(data, function (recv_contents) {326 is(recv_contents, contents, "Received data has the correct content.");327 test.next();328 });329 });330 }331 ],332 [333 'CREATE_SECOND_DATA_CHANNEL',334 function (test) {335 test.createDataChannel({ }, function (sourceChannel, targetChannel) {336 is(sourceChannel.readyState, "open", sourceChannel + " is in state: 'open'");337 is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");338 is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'");339 is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");340 test.next();341 });342 }343 ],344 [345 'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL',346 function (test) {347 var channels = test.pcRemote.dataChannels;348 var message = "Lorem ipsum dolor sit amet";349 test.send(message, function (channel, data) {350 is(channels.indexOf(channel), channels.length - 1, "Last channel used");351 is(data, message, "Received message has the correct content.");352 test.next();353 });354 }355 ],356 [357 'SEND_MESSAGE_THROUGH_FIRST_CHANNEL',358 function (test) {359 var message = "Message through 1st channel";360 var options = {361 sourceChannel: test.pcLocal.dataChannels[0],362 targetChannel: test.pcRemote.dataChannels[0]363 };364 test.send(message, function (channel, data) {365 is(test.pcRemote.dataChannels.indexOf(channel), 0, "1st channel used");366 is(data, message, "Received message has the correct content.");367 test.next();368 }, options);369 }370 ],371 [372 'CREATE_NEGOTIATED_DATA_CHANNEL',373 function (test) {374 var options = {negotiated:true, id: 5, protocol:"foo/bar", ordered:false,375 maxRetransmits:500};376 test.createDataChannel(options, function (sourceChannel2, targetChannel2) {377 is(sourceChannel2.readyState, "open", sourceChannel2 + " is in state: 'open'");378 is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");379 is(targetChannel2.binaryType, "blob", targetChannel2 + " is of binary type 'blob'");380 is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");381 if (options.id != undefined) {382 is(sourceChannel2.id, options.id, sourceChannel2 + " id is:" + sourceChannel2.id);383 } else {384 options.id = sourceChannel2.id;385 }386 var reliable = !options.ordered ? false : (options.maxRetransmits || options.maxRetransmitTime);387 is(sourceChannel2.protocol, options.protocol, sourceChannel2 + " protocol is:" + sourceChannel2.protocol);388 is(sourceChannel2.reliable, reliable, sourceChannel2 + " reliable is:" + sourceChannel2.reliable);389/*390 These aren't exposed by IDL yet391 is(sourceChannel2.ordered, options.ordered, sourceChannel2 + " ordered is:" + sourceChannel2.ordered);392 is(sourceChannel2.maxRetransmits, options.maxRetransmits, sourceChannel2 + " maxRetransmits is:" +393 sourceChannel2.maxRetransmits);394 is(sourceChannel2.maxRetransmitTime, options.maxRetransmitTime, sourceChannel2 + " maxRetransmitTime is:" +395 sourceChannel2.maxRetransmitTime);396*/397 is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id);398 is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol);399 is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable);400/*401 These aren't exposed by IDL yet402 is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered);403 is(targetChannel2.maxRetransmits, options.maxRetransmits, targetChannel2 + " maxRetransmits is:" +404 targetChannel2.maxRetransmits);405 is(targetChannel2.maxRetransmitTime, options.maxRetransmitTime, targetChannel2 + " maxRetransmitTime is:" +406 targetChannel2.maxRetransmitTime);407*/408 test.next();409 });410 }411 ],412 [413 'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2',414 function (test) {415 var channels = test.pcRemote.dataChannels;416 var message = "Lorem ipsum dolor sit amet";417 test.send(message, function (channel, data) {418 is(channels.indexOf(channel), channels.length - 1, "Last channel used");419 is(data, message, "Received message has the correct content.");420 test.next();421 });422 }423 ],424 [425 'CLOSE_LAST_OPENED_DATA_CHANNEL2',426 function (test) {427 var channels = test.pcRemote.dataChannels;428 test.closeDataChannel(channels.length - 1, function (channel) {429 is(channel.readyState, "closed", "Channel is in state: 'closed'");430 test.next();431 });432 }433 ],434 [435 'CLOSE_LAST_OPENED_DATA_CHANNEL',436 function (test) {437 var channels = test.pcRemote.dataChannels;438 test.closeDataChannel(channels.length - 1, function (channel) {439 is(channel.readyState, "closed", "Channel is in state: 'closed'");440 test.next();441 });442 }443 ]...
dataChannel.js
Source:dataChannel.js
...130 targetChannel2.maxRetransmitTime);131 */132 });133 },134 function SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2(test) {135 var channels = test.pcRemote.dataChannels;136 var message = "I am the walrus; Goo goo g'joob";137 return test.send(message).then(result => {138 is(channels.indexOf(result.channel), channels.length - 1, "Last channel used");139 is(result.data, message, "Received message has the correct content.");140 });141 }142];143function addInitialDataChannel(chain) {144 chain.insertBefore('PC_LOCAL_CREATE_OFFER', commandsCreateDataChannel);145 chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', commandsWaitForDataChannel);146 chain.removeAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS');147 chain.append(commandsCheckDataChannel);148}
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var request = require('request');4var cheerio = require('cheerio');5page.get((err, resp) => {6 if (err) {7 console.log(err);8 } else {9 var html = resp.html();10 var $ = cheerio.load(html);11 var data = $('.infobox').html();12 fs.writeFile('data.html', data, (err) => {13 if (err) {14 console.log(err);15 } else {16 console.log('File created successfully');17 }18 });19 }20});
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wp.getChannel2(function(err, channel2) {3 if (err) {4 console.log(err);5 } else {6 console.log(channel2);7 }8});9var wptoolkit = require('wptoolkit');10wp.getChannel1(function(err, channel1) {11 if (err) {12 console.log(err);13 } else {14 console.log(channel1);15 }16});17var wptoolkit = require('wptoolkit');18wp.getTags(function(err, tags) {19 if (err) {20 console.log(err);21 } else {22 console.log(tags);23 }24});25var wptoolkit = require('wptoolkit');26wp.getCategories(function(err, categories) {27 if (err) {28 console.log(err);29 } else {30 console.log(categories);31 }32});33var wptoolkit = require('wptoolkit');34wp.getPage(1, function(err, page) {35 if (err) {36 console.log(err);37 } else {38 console.log(page);39 }40});41var wptoolkit = require('wptoolkit');
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp){4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.get(function(err, resp){9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Albert Einstein');13page.get(function(err, resp){14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Albert Einstein');18page.get(function(err, resp){19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Albert Einstein');23page.get(function(err, resp){24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Albert Einstein');28page.get(function(err, resp){29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools.page('Albert Einstein');33page.get(function(err, resp){34 console.log(resp);35});
Using AI Code Generation
1var wptk = require('wptoolkit');2var wp = new wptk();3var channel2 = wp.channel2;4var options = {5 'headers': {6 }7};8channel2.request(options, function(err, response, body) {9 if(err) {10 console.log(err);11 }12 else {13 console.log(body);14 }15});16var wptk = require('wptoolkit');17var wp = new wptk();18var channel3 = wp.channel3;19var options = {20 'headers': {21 }22};23channel3.request(options, function(err, response, body) {24 if(err) {25 console.log(err);26 }27 else {28 console.log(body);29 }30});31Copyright (c) 2013-2015, Aman Verma
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var channel2 = wptoolkit.channel2;3var channel = channel2();4channel.on('test', function (data) {5 console.log(data);6});7channel.trigger('test', 'Hello World');8channel.off('test', function (data) {9 console.log(data);10});
Using AI Code Generation
1var wpt = require('./lib/webpagetest.js');2var options = {3};4var wpt = new wpt(options);5 if (err) return console.log(err);6 console.log(data);7 console.log(data.data.runs[1].firstView.TTFB);8 console.log(data.data.runs[1].firstView.render);9 console.log(data.data.runs[1].firstView.SpeedIndex);10 console.log(data.data.runs[1].firstView.fullyLoaded);11 console.log(data.data.runs[1].firstView.docTime);12 console.log(data.data.runs[1].firstView.bytesInDoc);13 console.log(data.data.runs[1].firstView.requestsDoc);14 console.log(data.data.runs[1].firstView.responses_200);15 console.log(data.data.runs[1].firstView.responses_404);16 console.log(data.data.runs[1].firstView.responses_other);17 console.log(data.data.runs[1].firstView.result);18 console.log(data.data.runs[1].firstView.completed);19 console.log(data.data.runs[1].firstView.loadTime);20 console.log(data.data.runs[1].firstView.TTFB);21 console.log(data.data.runs[1].firstView.bytesOut);22 console.log(data.data.runs[1].firstView.bytesOutDoc);23 console.log(data.data.runs[1].firstView.bytesIn);24 console.log(data.data.runs[1].firstView.requestsFull);25 console.log(data.data.runs[1].firstView.requests);26 console.log(data.data.runs[1].firstView.responses
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('New York City');3page.getSummary(function(err, info) {4 if (err) {5 console.log(err);6 } else {7 console.log(info);8 }9});10page.getInfobox(function(err, info) {11 if (err) {12 console.log(err);13 } else {14 console.log(info);15 }16});17page.getCategories(function(err, info) {18 if (err) {19 console.log(err);20 } else {21 console.log(info);22 }23});24page.getImages(function(err, info) {25 if (err) {26 console.log(err);27 } else {28 console.log(info);29 }30});31page.getReferences(function(err, info) {32 if (err) {33 console.log(err);34 } else {35 console.log(info);36 }37});38page.getLinks(function(err, info) {39 if (err) {40 console.log(err);41 } else {42 console.log(info);43 }44});45page.getCoordinates(function(err, info) {46 if (err) {47 console.log(err);48 } else {49 console.log(info);50 }51});52page.getPageviews(function(err, info) {53 if (err) {54 console.log(err);55 } else {56 console.log(info);57 }58});59page.getRedirects(function(err, info) {60 if (err) {61 console.log(err);62 } else {63 console.log(info);64 }65});66page.getDisambiguation(function(err, info) {67 if (err) {68 console.log(err);69 } else {70 console.log(info);71 }72});73page.getRandom(function(err, info) {74 if (err) {
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!!