How to use requestToken method in wpt

Best JavaScript code snippet using wpt

WorkspaceHelper.js

Source:WorkspaceHelper.js Github

copy

Full Screen

1// Copyright (c) Sitecore Corporation 1999-20172/* jshint unused: vars */3define(["sitecore"], function (Sitecore) {4 var WorkspaceHelper = Sitecore.Definitions.Models.Model.extend({5 getItems: function (callback, itemType, workspaceName, controlFolder, language) {6 var requestToken = this.get("requestToken");7 $.ajax({8 url: "/sitecore/shell/commerce/merchandising/Workspace/GetItems",9 type: "POST",10 headers: requestToken,11 data: {12 itemType: itemType,13 workspaceName: workspaceName,14 controlFolder: controlFolder,15 language: language16 },17 context: this,18 success: function (data) {19 if (typeof (callback) == "function") {20 callback(data);21 }22 }23 });24 },25 getVariants: function (callback, item, workspaceName, controlFolder, language) {26 var requestToken = this.get("requestToken");27 $.ajax({28 url: "/sitecore/shell/commerce/merchandising/Workspace/GetVariantsForProduct",29 type: "POST",30 headers: requestToken,31 data: {32 id: item.itemId,33 workspaceName: workspaceName,34 controlFolder: controlFolder,35 language: language36 },37 context: this,38 success: function (data) {39 if (typeof (callback) == "function") {40 callback(data, item);41 }42 }43 });44 },45 getRelationships: function (callback, item, workspaceName, entityType, controlFolder, language) {46 var requestToken = this.get("requestToken");47 $.ajax({48 url: "/sitecore/shell/commerce/merchandising/Workspace/GetRelationships",49 type: "POST",50 headers: requestToken,51 data: {52 id: item.itemId,53 workspaceName: workspaceName,54 entityType: entityType,55 controlFolder: controlFolder,56 language: language57 },58 context: this,59 success: function (data) {60 if (typeof (callback) == "function") {61 callback(data, item);62 }63 }64 });65 },66 getCount: function (callback) {67 var requestToken = this.get("requestToken");68 $.ajax({69 url: "/sitecore/shell/commerce/merchandising/Workspace/GetTotalCount",70 type: "POST",71 headers: requestToken,72 context: this,73 success: function (data) {74 if (typeof (callback) == "function") {75 callback(data);76 }77 }78 });79 },80 addItems: function (items, callback) {81 var delimitedList = this.buildDelimitedList(items);82 var requestToken = this.get("requestToken");83 $.ajax({84 url: "/sitecore/shell/commerce/merchandising/Workspace/AddItems",85 type: "POST",86 headers: requestToken,87 data: {88 items: delimitedList89 },90 context: this,91 success: function (data) {92 if (typeof (callback) == "function") {93 callback(data);94 }95 }96 });97 },98 removeItems: function (items, callback) {99 var delimitedList = this.buildDelimitedList(items);100 var requestToken = this.get("requestToken");101 $.ajax({102 url: "/sitecore/shell/commerce/merchandising/Workspace/RemoveItems",103 type: "POST",104 headers: requestToken,105 data: {106 items: delimitedList107 },108 context: this,109 success: function (data) {110 if (typeof (callback) == "function") {111 callback(data);112 }113 }114 });115 },116 getWorkspaceLanguages: function (callback, itemType, workspaceName) {117 var requestToken = this.get("requestToken");118 $.ajax({119 url: "/sitecore/shell/commerce/merchandising/Workspace/GetWorkspaceLanguages",120 type: "POST",121 headers: requestToken,122 data: {123 itemType: itemType,124 workspaceName: workspaceName,125 },126 context: this,127 success: function (data) {128 if (typeof (callback) == "function") {129 callback(data);130 }131 }132 });133 },134 removeAll: function (callback) {135 var requestToken = this.get("requestToken");136 $.ajax({137 url: "/sitecore/shell/commerce/merchandising/Workspace/RemoveAllItems",138 type: "POST",139 headers: requestToken,140 context: this,141 success: function (data) {142 if (typeof (callback) == "function") {143 callback(data);144 }145 }146 });147 },148 buildDelimitedList: function (items) {149 var itemList = "";150 if (items && items.length > 0) {151 for (i = 0; i < items.length; i++) {152 itemList += items[i];153 if (i < items.length - 1) {154 itemList += "|";155 }156 }157 }158 return itemList;159 }160 });161 return WorkspaceHelper;...

Full Screen

Full Screen

core.js

Source:core.js Github

copy

Full Screen

1(function($, JSON) {2 'use strict';3 var XBlock;4 function initializeBlockLikes(blockClass, initializer, element, requestToken) {5 var selector;6 requestToken = requestToken || $(element).data('request-token');7 if (requestToken) {8 selector = '.' + blockClass + '[data-request-token="' + requestToken + '"]';9 } else {10 selector = '.' + blockClass;11 }12 return $(element).immediateDescendents(selector).map(function(idx, elem) {13 return initializer(elem, requestToken);14 }).toArray();15 }16 function elementRuntime(element) {17 var $element = $(element),18 runtime = $element.data('runtime-class'),19 version = $element.data('runtime-version'),20 initFnName = $element.data('init');21 if (runtime && version && initFnName) {22 return new window[runtime]['v' + version]();23 } else {24 if (runtime || version || initFnName) {25 console.log(26 'Block ' + $element.outerHTML + ' is missing data-runtime, data-runtime-version or data-init, ' +27 'and can\'t be initialized'28 );29 } // else this XBlock doesn't have a JS init function.30 return null;31 }32 }33 function initArgs(element) {34 var initargs = $(element).children('.xblock-json-init-args').remove().text();35 return initargs ? JSON.parse(initargs) : {};36 }37 /**38 * Construct an XBlock family object from an element. The constructor39 * function is loaded from the 'data-init' attribute of the element.40 * The constructor is called with the arguments 'runtime', 'element',41 * and then all of 'block_args'.42 */43 function constructBlock(element, blockArgs) {44 var block;45 var $element = $(element);46 var runtime = elementRuntime(element);47 blockArgs.unshift(element);48 blockArgs.unshift(runtime);49 if (runtime) {50 block = (function() {51 var initFn = window[$element.data('init')];52 // This create a new constructor that can then apply() the block_args53 // to the initFn.54 function Block() {55 return initFn.apply(this, blockArgs);56 }57 Block.prototype = initFn.prototype;58 return new Block();59 })();60 block.runtime = runtime;61 } else {62 block = {};63 }64 block.element = element;65 block.name = $element.data('name');66 block.type = $element.data('block-type');67 $element.trigger('xblock-initialized');68 $element.data('initialized', true);69 $element.addClass('xblock-initialized');70 return block;71 }72 XBlock = {73 Runtime: {},74 /**75 * Initialize the javascript for a single xblock element, and for all of it's76 * xblock children that match requestToken. If requestToken is omitted, use the77 * data-request-token attribute from element, or use the request-tokens specified on78 * the children themselves.79 */80 initializeBlock: function(element, requestToken) {81 var $element = $(element),82 children, asides;83 requestToken = requestToken || $element.data('request-token');84 children = XBlock.initializeXBlocks($element, requestToken);85 asides = XBlock.initializeXBlockAsides($element, requestToken);86 if (asides) {87 children = children.concat(asides);88 }89 $element.prop('xblock_children', children);90 return constructBlock(element, [initArgs(element)]);91 },92 /**93 * Initialize the javascript for a single xblock aside element that matches requestToken.94 * If requestToken is omitted, use the data-request-token attribute from element, or use95 * the request-tokens specified on the children themselves.96 */97 initializeAside: function(element) {98 var blockUsageId = $(element).data('block-id');99 var blockElement = $(element).siblings('[data-usage-id="' + blockUsageId + '"]')[0];100 return constructBlock(element, [blockElement, initArgs(element)]);101 },102 /**103 * Initialize all XBlocks inside element that were rendered with requestToken.104 * If requestToken is omitted, and element has a 'data-request-token' attribute, use that.105 * If neither is available, then use the request tokens of the immediateDescendent xblocks.106 */107 initializeXBlocks: function(element, requestToken) {108 return initializeBlockLikes('xblock', XBlock.initializeBlock, element, requestToken);109 },110 /**111 * Initialize all XBlockAsides inside element that were rendered with requestToken.112 * If requestToken is omitted, and element has a 'data-request-token' attribute, use that.113 * If neither is available, then use the request tokens of the immediateDescendent xblocks.114 */115 initializeXBlockAsides: function(element, requestToken) {116 return initializeBlockLikes('xblock_asides-v1', XBlock.initializeAside, element, requestToken);117 },118 /**119 * Initialize all XBlock-family blocks inside element that were rendered with requestToken.120 * If requestToken is omitted, and element has a 'data-request-token' attribute, use that.121 * If neither is available, then use the request tokens of the immediateDescendent xblocks.122 */123 initializeBlocks: function(element, requestToken) {124 var asides = XBlock.initializeXBlockAsides(element, requestToken);125 var xblocks = XBlock.initializeXBlocks(element, requestToken);126 if (asides) {127 xblocks = xblocks.concat(asides);128 }129 return xblocks;130 }131 };132 this.XBlock = XBlock;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3client.requestToken(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var client = wpt('www.webpagetest.org');12client.getLocations(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20var client = wpt('www.webpagetest.org');21client.getTesters(function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('webpagetest');29var client = wpt('www.webpagetest.org');30client.getTesters(function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wpt = require('webpagetest');38var client = wpt('www.webpagetest.org');39client.getTesters(function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wpt = require('webpagetest');47var client = wpt('www.webpagetest.org');48client.getTesters(function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wpt = require('webpagetest');56var client = wpt('www.webpagetest.org');57client.getTesters(function(err, data) {58 if (err) {59 console.log(err);60 } else {61 console.log(data);62 }63});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var requestToken = function() {4 wpt.requestToken(function (err, data) {5 if (data.statusCode == 200) {6 return data;7 }8 else {9 return err;10 }11 });12}13var testStatus = function(testId) {14 wpt.testStatus(testId, function (err, data) {15 if (data.statusCode == 200) {16 return data;17 }18 else {19 return err;20 }21 });22}23var getResults = function(testId) {24 wpt.getTestResults(testId, function (err, data) {25 if (data.statusCode == 200) {26 return data;27 }28 else {29 return err;30 }31 });32}33var wpt = require('webpagetest');34var wpt = new WebPageTest('www.webpagetest.org');35var requestToken = function() {36 wpt.requestToken(function (err, data) {37 if (data.statusCode == 200) {38 return data;39 }40 else {41 return err;42 }43 });44}45var testStatus = function(testId) {46 wpt.testStatus(testId, function (err, data) {47 if (data.statusCode == 200) {48 return data;49 }50 else {51 return err;52 }53 });54}55var getResults = function(testId) {56 wpt.getTestResults(testId, function (err, data) {57 if (data.statusCode == 200) {58 return data;59 }60 else {61 return err;62 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.2c3b9d9e1f2g3h4i5j6k7l8m9n0o1p2q3r4s5t6u7v8w9x0y1z2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'A.2c3b9d9e1f2g3h4i5j6k7l8m9n0o1p2q3r4s5t6u7v8w9x0y1z2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org', 'A.2c3b9d9e1f2g3h4i5j6k7l8m9n0o1p2q3r4s5t6u7v8w9x0y1z2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest')('www.webpagetest.org', 'A.1e9d0c2a8f2c3b4c5d6e7f8g9h0i1j2k3');2wpt.requestToken(function(err, data) {3 if (err) {4 console.log('Error: '+err);5 } else {6 console.log('Token: '+data);7 }8});

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