How to use _setContext method in Puppeteer

Best JavaScript code snippet using puppeteer

sitechJson.js

Source:sitechJson.js Github

copy

Full Screen

...33 var context = this._getContext();34 if (!core) return sitechJson(null);35 var path = selector.split(".");36 if (!path || path.length == 0 || core.childNodes.length == 0) {37 this._setContext(core);38 return sitechJson(null);39 }40 var i = 0; 41 do {42 var regMatch = path[i].match(reg);43 path[i] = regMatch ? regMatch[1] : path[i];44 var arrayIndex = regMatch ? regMatch[2] : 0;45 var k = 0;46 if (!context.childNodes || !context.childNodes[k] || !context.childNodes[k].tagName) {47 this._setContext(core);48 return sitechJson(null);49 }5051 do {5253 if (!arrayIndex && !arguments[1]) {54 if (!arguments[2] && context.childNodes[k].tagName == path[i]) {55 break;56 } else if (arguments[2] && context.childNodes[k].tagName == path[i]) {57 if (!path[i + 1]) {58 context.childNodes[k].parent = context;59 tempArr.push(context.childNodes[k]);60 } else break;61 }62 } else if (arrayIndex) {63 if (context.childNodes[k].tagName == path[i]) {64 context.childNodes[k].parent = context;65 tempArr.push(context.childNodes[k]);66 }6768 } else if (!arrayIndex && arguments[1]) {69 if (!arguments[2]) {70 if (context.childNodes[k].tagName == path[i]) {71 var innerJson = sitechJson(context.childNodes[k]);72 if (arguments[1][2].charAt(0) == ">") {73 if (innerJson.deepFind("/" + arguments[1][2].slice(1)).value() == arguments[1][3]) {7475 break;76 }77 } else {78 if (innerJson.find(arguments[1][2]).value() == arguments[1][3]) {79 break;80 }81 }8283 }84 } else {85 if (context.childNodes[k].tagName == path[i]) {86 var innerJson = sitechJson(context.childNodes[k]);87 if (arguments[1][2].charAt(0) == ">") { //±éÀúËùÓÐÏàͬ×Ó½Úµã?ÏÖÔÚĬÈÏÖ»ÓÐÒ»¸ö¸ÃÀàÐ͵Ä×ӽڵ㣬±ÈÈ磬productÏÂÃæÖ»ÓÐÒ»¸öproducttype½Úµã£¬À´¶¨Î»×Ó²úÆ·Êý×é88 if (innerJson.deepFind("/" + arguments[1][2].slice(1)).value() == arguments[1][3]) {8990 context.childNodes[k].parent = context;91 tempArr.push(context.childNodes[k]);92 }93 } else {94 if (innerJson.find(arguments[1][2]).value() == arguments[1][3]) {95 context.childNodes[k].parent = context;96 tempArr.push(context.childNodes[k]);97 }98 }99100 }101 }102 }103104 } while ( typeof context . childNodes [++ k ] != "undefined") ;105 if (tempArr.length) {106 if (arguments[2] && !path[i + 1]) {107 this._setContext(core);108 return tempArr;109 } else {110 if (typeof tempArr[arrayIndex] != "undefined") {111 context = tempArr[arrayIndex];112 } else {113 this._setContext(core);114 return sitechJson(null);115 }116 }117 tempArr = [];118 } else if (typeof context.childNodes[k] == "undefined") {119 this._setContext(core);120 return sitechJson(null);121 } else {122 context.childNodes[k].parent = context;123 context = context.childNodes[k];124125 }126127 } while ( typeof path [++ i ] != "undefined");128129 this._setContext(core);130 return sitechJson(context);131132 },133 deepFind: function(selector) {134135 function search(c) {136 if (!c.tagName || !c.childNodes) return null;137 var tempArr = [];138 for (var l = 0; l < c.childNodes.length; l++) {139140 if (c.childNodes[l].tagName == path[i]) {141 if (!arrayIndex1 && !arguments[1]) {142 c.childNodes[l].parent = c;143 return c.childNodes[l];144 } else {145 if (!arguments[2]) {146 c.childNodes[l].parent = c;147 tempArr.push(c.childNodes[l]);148 } else {149 var deepState = false;150 var innerPath = null;151 if (arguments[2][2].charAt(0) == ">") {152 deepState = true;153 innerPath = ("/" + arguments[2][2].slice(1))154 }155 if (deepState) {156 if (sitechJson(c.childNodes[l]).deepFind(innerPath).value() == arguments[2][3]) {157 c.childNodes[l].parent = c;158 tempArr.push(c.childNodes[l]);159 }160 } else {161 var attrLen = c.childNodes[l] ? c.childNodes[l].childNodes.length: 0;162 for (var nin = 0; nin < attrLen; nin++) {163164 if ((c.childNodes[l].childNodes[nin].tagName == arguments[2][2]) && (c.childNodes[l].childNodes[nin].childNodes && c.childNodes[l].childNodes[nin].childNodes[0] && (c.childNodes[l].childNodes[nin].childNodes[0] == arguments[2][3]))) {165 c.childNodes[l].parent = c;166 tempArr.push(c.childNodes[l]);167 break;168 }169 }170 }171172 }173 }174 } else {175 var inner = search(c.childNodes[l], !!arguments[1], arguments[2]);176 if (inner && ((inner.length != undefined) ? !!inner.length: true)) {177 return inner;178 }179 }180 }181 if (arguments[1]) return tempArr;182 if (typeof tempArr[arrayIndex1] != "undefined") {183 return tempArr[arrayIndex1];184 } else {185 return null186 } //´Ë´¦Ëã·¨»á²úÉú¶ªÊ§Çé¿ö£¬´ý¸Ä½ø187 return null;188189 }190 var core = this._getCore();191 var context = this._getContext();192 var path = selector.match(regSplit);193 var tempArr = [];194 if (!core) return sitechJson(null);195 if (!path || path.length == 0 || core.childNodes.length == 0) {196 this._setContext(core);197 return sitechJson(null);198 }199 var i = 0;200 do {201202 if (path[i].charAt(0) == "." || path[i].charAt(0) != "/") { (path[i].charAt(0) == ".") && (path[i] = path[i].slice(1));203 var tempAttrArray = path[i].match(regAttr);204 if (tempAttrArray) {205 if (!path[i + 1] && arguments[1]) {206 return this.find(tempAttrArray[1], tempAttrArray, true)207 }208 context = this.find(tempAttrArray[1], tempAttrArray)._getContext();209210 if (context == null) {211 this._setContext(core);212 return sitechJson(null);213 }214 this._setContext(context);215216 } else {217 if (!path[i + 1] && arguments[1]) {218 return this.find(path[i], false, true)219 }220 context = this.find(path[i])._getContext();221222 if (context == null) {223 this._setContext(core);224 return sitechJson(null);225 }226 this._setContext(context);227 }228229 } else {230231 path[i] = path[i].slice(1);232 var tempAttrArray1 = path[i].match(regAttr);233 if (tempAttrArray1) {234 path[i] = tempAttrArray1[1];235 var regMatch1 = path[i].match(reg);236 path[i] = regMatch1 ? regMatch1[1] : path[i];237 var arrayIndex1 = regMatch1 ? regMatch1[2] : 0;238 if (!path[i + 1] && arguments[1]) {239 ////////////////////////////////////////////////////240 return search(context, true, tempAttrArray1)241 ///////////////////////////////////////////////////242 }243 var deepState = false;244245 if (tempAttrArray1[2].charAt(0) == ">") {246 deepState = true;247 tempAttrArray1[2] = ("/" + tempAttrArray1[2].slice(1))248 }249 if (arrayIndex1) {250 context = search(context);251 if (!context) {252 this._setContext(core);253 return sitechJson(null);254 }255256 if (deepState) {257 //´Ë´¦ÏȲ»×÷×Ó½Úµã´æÔÚÊý×éÁбíµÄÇé¿ö258 if (sitechJson(context).deepFind(tempAttrArray1[2]).value() == tempAttrArray1[3]) {259260 this._setContext(context);261 }262 } else {263 var attrLen = context ? context.childNodes.length: 0;264 for (var nin = 0; nin < attrLen; nin++) {265266 if ((context.childNodes[nin].tagName == tempAttrArray1[2]) && (context.childNodes[nin].childNodes && context.childNodes[nin].childNodes[0] && (context.childNodes[nin].childNodes[0] == tempAttrArray1[3]))) {267 //attrState = true;268 this._setContext(context);269 break;270 }271 }272 }273 break;274275 }276 var contextArr = search(context, true);277 if (contextArr) {278279 for (var o = 0; o < contextArr.length; o++) {280 context = contextArr[o];281 var attrState = false;282 if (deepState) {283 //´Ë´¦ÏȲ»×÷×Ó½Úµã´æÔÚÊý×éÁбíµÄÇé¿ö284 if (sitechJson(context).deepFind(tempAttrArray1[2]).value() == tempAttrArray1[3]) {285286 attrState = true;287 this._setContext(context);288 }289 } else {290 var attrLen = context ? context.childNodes.length: 0;291 for (var nin = 0; nin < attrLen; nin++) {292293 if ((context.childNodes[nin].tagName == tempAttrArray1[2]) && (context.childNodes[nin].childNodes && context.childNodes[nin].childNodes[0] && (context.childNodes[nin].childNodes[0] == tempAttrArray1[3]))) {294 attrState = true;295 this._setContext(context);296 break;297 }298 }299 }300 if (attrState) {301 break;302 }303 }304 if (!attrState) {305 this._setContext(core);306 return sitechJson(null);307 }308 } else {309 this._setContext(core);310 return sitechJson(null);311 }312 } else {313 var regMatch1 = path[i].match(reg);314 path[i] = regMatch1 ? regMatch1[1] : path[i];315 var arrayIndex1 = regMatch1 ? regMatch1[2] : 0;316317 context = search(context);318 if (!context) {319 this._setContext(core);320 return sitechJson(null);321 }322 this._setContext(context);323 }324325 }326327 } while ( typeof path [++ i ] != "undefined");328 this._setContext(core);329 return sitechJson(context);330 },331 findArr: function(selector) {332 return new sitechJsonArr(this.find(selector, false, true));333 },334 dfindArr: function(selector) {335 return new sitechJsonArr(this.deepFind(selector, true));336 },337 value: function() {338 if (!this._getContext()) return "ûÓÐÑ¡Ôñµ½½Úµã£¬ÎÞ·µ»ØÖµ";339 return (this._getContext().type) ? (typeof this._getContext().childNodes != "undefined" ? this._getContext().childNodes[0] : "") : "½ÚµãÀàÐÍ£¬ÎÞ·µ»ØÖµ";340341 },342 isNull: function() {343 return ! this._getContext();344 },345 set: function(v) {346 var context = this._getContext();347 if (context.type) {348 if (typeof context.childNodes == "undefined") {349 context.childNodes = [];350 }351 context.childNodes[0] = v;352 return true;353 };354 return false;355356 },357358 addTag: function(value, tagName) {359 var context = this._getContext();360 for (var i = 0; i < context.childNodes.length; i++) {361 if (context.childNodes[i].tagName == tagName) {362 var tempObj = {363 "childNodes": [value],364 "tagName": tagName,365 "type": context.childNodes[i].type366 };367 tempObj.parent = context;368 context.childNodes.push(tempObj);369 return true;370 }371 }372 return false;373 },374 addValue: function(v) {375 if (typeof v != "number" || typeof v != "string") return false;376 var context = this._getContext();377 if (context.type) context.childNodes = [v];378379 },380 addNode: function(obj) {381 if(obj&&obj._getContext)382 {383 var objContext = obj._getContext();384 var parentContext = this._getContext();385 if (typeof objContext.tagName != "undefined") {386 if (typeof parentContext.childNodes == "undefined") parentContext.childNodes = [];387 objContext.parent = parentContext;388 parentContext.childNodes.push(objContext);389 return true;390 }391 }392 return false;393394 },395 remove: function() {396 var context = this._getContext();397 if (!context.parent) {398 alert("´Ë½ÚµãûÓйҽӵ½Èκνڵ㣬²»ÄÜɾ³ý½Úµã±¾Éí");399 return false;400 };401 if (!arguments[0]) {402 if (this.isNull() || context.parent.childNodes.length < 1) return false;403 for (var i = 0; i < context.parent.childNodes.length; i++) {404 if (context.parent.childNodes[i] == context) {405 context.parent.childNodes.splice(i, 1);406 this._setContext(null);407 return true;408 }409 }410411 } else {412 context.childNodes = [];413 return true414 }415 return false;416 },417 returnTagName: function() {418 var context = this._getContext();419 if (context) {420 return context.tagName ...

Full Screen

Full Screen

Types.js

Source:Types.js Github

copy

Full Screen

...23 SubType.prototype.hasDefaultPrototype = false;24 return SubType;25};26PrototypedType.prototype._extend = function (name, type) {27 return this._setContext(this.context.add(name, type));28};29PrototypedType.prototype.isSubPrototypeOf = function (type) {30 return type.context.keys().every(function (key) {31 return this.context.has(key) && this.context.top(key).isSubTypeOf(type.context.top(key));32 }, this);33};34PrototypedType.prototype.isSubTypeOf = function (type) {35 return this.isSubCharacterOf(type) && (type.hasDefaultPrototype || this.isSubPrototypeOf(type));36};37PrototypedType.merge = function (type1, type2) {38 if (type1.isSubCharacterOf(type2)) {39 return type2.setContext(type1.context.intersection(type2.context, PrototypedType.merge));40 } else if (type2.isSubCharacterOf(type1)) {41 return type1.setContext(type1.context.intersection(type2.context, PrototypedType.merge));42 } else {43 throw new LambdaTypeError();44 }45};46PrototypedType.prototype.merge = function (type) {47 return PrototypedType.merge(this, type);48};49function UndefinedType() {50 PrototypedType.call(this);51}52exports.UndefinedType = UndefinedType;53extend(PrototypedType, UndefinedType);54UndefinedType.prototype.character = Character.UNDEFINED;55UndefinedType.prototype.toString = function () {56 return 'undefined';57};58UndefinedType.prototype.setContext = function (context) {59 return new (this._setContext(context))();60};61UndefinedType.prototype.extend = function (name, type) {62 return new (this._extend(name, type))();63};64UndefinedType.prototype.isSubCharacterOf = function (type) {65 return Character.UNDEFINED === type.character;66};67UndefinedType.DEFAULT = new UndefinedType();68UndefinedType.prototype.instance = function () {69 return this;70};71UndefinedType.fromContext = function (context) {72 return UndefinedType.DEFAULT.setContext(context);73};74function UnknownType() {75 UndefinedType.call(this);76}77exports.UnknownType = UnknownType;78extend(UndefinedType, UnknownType);79UnknownType.prototype.character = Character.UNKNOWN;80UnknownType.prototype.toString = function () {81 return 'unknown';82};83UnknownType.DEFAULT = new UnknownType();84UnknownType.prototype.isSubCharacterOf = function () {85 return true;86};87UnknownType.prototype.isSubPrototypeOf = function (type) {88 return this.context.keys().every(function (key) {89 if (type.context.has(key)) {90 return this.context.top(key).isSubTypeOf(type.context.top(key));91 } else if (type.is(UnknownType)) {92 return this.context.top(key).isSubTypeOf(UnknownType.DEFAULT);93 } else {94 return false;95 }96 }, this);97};98UnknownType.prototype.isSubTypeOf = function (type) {99 return this.hasDefaultPrototype || this.isSubPrototypeOf(type);100};101UnknownType.prototype.merge = function (type) {102 if (type.is(UnknownType)) {103 return this.setContext(this.context.union(type.context, PrototypedType.merge));104 } else {105 return type.setContext(this.context.intersection(type.context, PrototypedType.merge));106 }107};108function VariableType(name) {109 UndefinedType.call(this);110 this.name = name;111}112exports.VariableType = VariableType;113extend(UndefinedType, VariableType);114VariableType.prototype.toString = function () {115 return this.name;116};117VariableType.prototype.setContext = function (context) {118 return new (this._setContext(context))(this.name);119};120VariableType.prototype.extend = function (name, type) {121 return new (this._extend(name, type))(this.name);122};123VariableType.prototype.isSubCharacterOf = function () {124 // TODO125};126VariableType.prototype.isSubPrototypeOf = function (type) {127 return this.context.keys().every(function (key) {128 if (type.context.has(key)) {129 return this.context.top(key).isSubTypeOf(type.context.top(key));130 } else {131 // TODO132 return false;133 }134 }, this);135};136VariableType.prototype.isSubTypeOf = function (type) {137 return UndefinedType.prototype.isSubTypeOf.call(this, type) &&138 (!type.is(VariableType) || type.name === this.name);139};140VariableType.prototype.merge = function () {141 // TODO142 return UnknownType.DEFAULT;143};144VariableType.prototype.instance = function (name, type) {145 if (this.name !== name) {146 return this;147 } else {148 return type;149 }150};151function ComplexType() {152 UndefinedType.call(this);153}154exports.ComplexType = ComplexType;155extend(UndefinedType, ComplexType);156ComplexType.prototype.character = Character.COMPLEX;157ComplexType.prototype.toString = function () {158 return 'complex';159};160ComplexType.prototype.isSubCharacterOf = function (type) {161 return Character.UNDEFINED === type.character ||162 Character.COMPLEX === type.character;163};164ComplexType.DEFAULT = new ComplexType();165function RealType() {166 ComplexType.call(this);167}168exports.RealType = RealType;169extend(ComplexType, RealType);170RealType.prototype.character = Character.REAL;171RealType.prototype.toString = function () {172 return 'real';173};174RealType.prototype.isSubCharacterOf = function (type) {175 return Character.UNDEFINED === type.character ||176 Character.COMPLEX === type.character ||177 Character.REAL === type.character;178};179RealType.DEFAULT = new RealType();180function IntegerType() {181 RealType.call(this);182}183exports.IntegerType = IntegerType;184extend(RealType, IntegerType);185IntegerType.prototype.character = Character.INTEGER;186IntegerType.prototype.toString = function () {187 return 'integer';188};189IntegerType.prototype.isSubCharacterOf = function (type) {190 return Character.UNDEFINED === type.character ||191 Character.COMPLEX === type.character ||192 Character.REAL === type.character ||193 Character.INTEGER === type.character;194};195IntegerType.DEFAULT = new IntegerType();196function NaturalType() {197 IntegerType.call(this);198}199exports.NaturalType = NaturalType;200extend(IntegerType, NaturalType);201NaturalType.prototype.character = Character.NATURAL;202NaturalType.prototype.toString = function () {203 return 'natural';204};205NaturalType.prototype.isSubCharacterOf = function (type) {206 return Character.UNDEFINED === type.character ||207 Character.COMPLEX === type.character ||208 Character.REAL === type.character ||209 Character.INTEGER === type.character ||210 Character.NATURAL === type.character;211};212NaturalType.DEFAULT = new NaturalType();213function BooleanType() {214 UndefinedType.call(this);215}216exports.BooleanType = BooleanType;217extend(UndefinedType, BooleanType);218BooleanType.prototype.character = Character.BOOLEAN;219BooleanType.prototype.toString = function () {220 return 'boolean';221};222BooleanType.prototype.isSubCharacterOf = function (type) {223 return Character.UNDEFINED === type.character ||224 Character.BOOLEAN === type.character;225};226BooleanType.DEFAULT = new BooleanType();227function IndexedType(inner) {228 UndefinedType.call(this);229 this.inner = inner;230}231exports.IndexedType = IndexedType;232extend(UndefinedType, IndexedType);233function StringType(selfReference) {234 if (selfReference) {235 IndexedType.call(this, this);236 } else {237 IndexedType.call(this, StringType.DEFAULT);238 }239}240exports.StringType = StringType;241extend(IndexedType, StringType);242StringType.prototype.character = Character.STRING;243StringType.prototype.toString = function () {244 return 'string';245};246StringType.prototype.isSubCharacterOf = function (type) {247 return Character.UNDEFINED === type.character ||248 Character.STRING === type.character;249};250StringType.DEFAULT = new StringType(true);251function ListType(inner) {252 IndexedType.call(this, inner);253}254exports.ListType = ListType;255extend(IndexedType, ListType);256ListType.prototype.character = Character.LIST;257ListType.prototype.toString = function () {258 return '(' + this.inner.toString() + ')*';259};260ListType.prototype.setContext = function (context) {261 return new (this._setContext(context))(this.inner);262};263ListType.prototype.extend = function (name, type) {264 return new (this._extend(name, type))(this.inner);265};266ListType.prototype.isSubCharacterOf = function (type) {267 return Character.UNDEFINED === type.character ||268 Character.LIST === type.character;269};270ListType.prototype.isSubTypeOf = function (type) {271 return UndefinedType.prototype.isSubTypeOf.call(this, type) &&272 (!type.is(IndexedType) || this.inner.isSubTypeOf(type.inner));273};274ListType.prototype.instance = function (name, type) {275 return new (this._setContext(this.context))(this.inner.instance(name, type));276};277function LambdaType(left, right) {278 UndefinedType.call(this);279 this.left = left;280 this.right = right;281}282exports.LambdaType = LambdaType;283extend(UndefinedType, LambdaType);284LambdaType.prototype.character = Character.LAMBDA;285LambdaType.prototype.toString = function () {286 return '(' + this.left.toString() + ') => (' + this.right.toString() + ')';287};288LambdaType.prototype.setContext = function (context) {289 return new (this._setContext(context))(this.left, this.right);290};291LambdaType.prototype.extend = function (name, type) {292 return new (this._extend(name, type))(this.left, this.right);293};294LambdaType.prototype.isSubCharacterOf = function (type) {295 return Character.UNDEFINED === type.character ||296 Character.LAMBDA === type.character;297};298LambdaType.prototype.isSubTypeOf = function (type) {299 return UndefinedType.prototype.isSubTypeOf.call(this, type) && (!type.is(LambdaType) ||300 type.left.isSubTypeOf(this.left) && this.right.isSubTypeOf(type.right));301};302LambdaType.prototype.instance = function (name, type) {303 return new (this._setContext(this.context))(this.left.instance(name, type), this.right.instance(name, type));304};305LambdaType.prototype.bind = function (type) {306 if (this.left.is(VariableType)) {307 return this.right.instance(this.left.name, type);308 } else if (type.isSubTypeOf(this.left)) {309 return this.right;310 } else {311 throw new LambdaTypeError();312 }313};314function JSUndefinedType() {315 UndefinedType.call(this);316}317exports.JSUndefinedType = JSUndefinedType;...

Full Screen

Full Screen

PropsManager.js

Source:PropsManager.js Github

copy

Full Screen

...38 }39 _setContext = (newContext) => {40 return this.state.hasOwnContext41 ? this.setState({context: Object.assign(this.state.context, newContext)})42 : this.props.prevContextElement && this.props.prevContextElement._setContext(newContext)43 }44 _getContext = () => {45 return this.state.hasOwnContext46 ? this.state.context47 : this.props.prevContextElement && this.props.prevContextElement._getContext()48 }49 static getDerivedStateFromProps (nextProps, prevState) {50 if (!isObject(nextProps.propsFilters)) return null51 let filteredValues = {}52 each(nextProps.propsFilters, ({path, handler, params}) => {53 const filter = PropsFilters[handler]54 if (!filter) {55 console.warn(`Propfilter: ${handler} does not exists`)56 return...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...57 }58 _getContext(){59 return this._context;60 }61 _setContext(context){62 this._context = {63 name:context.name?context.name:"",64 retries: context.retries?context.retries:0,65 payload:context.payload?context.payload:{},66 response:context.response?context.response:{},67 errors:context.error?context.error:{},68 }69 }70}71async function fetchUsers(){72 if(Math.ceil(Math.random()*100)%2==0){73 console.log("calling 1:Success");74 let users = await get('https://jsonplaceholder.typicode.com/users');75 return users;76 }else{77 console.log("calling 1:Failure");78 throw Error("God Bless America")79 }80 81} 82async function fetchTodos (payload){83 if(Math.ceil(Math.random()*100)%2==0){84 console.log("calling 2:Success");85 return await get(`https://jsonplaceholder.typicode.com/todos?userId=${payload.id}`);86 }else{87 console.log("calling 2:Failure");88 throw Error("God Bless America")89 }90}91function pickRandomItem(items){92 return items[Math.floor(Math.random() * items.length)];93}94TaskExecutorConstants = TaskExecutor.constants();95class WorkflowManager{96 constructor(stack){97 this._stack = stack || [];98 this._index = 0;99 }100 async start(){101 for(let i=this._index;i<=this._stack.length;i++){102 103 let apiManager;104 if(i==0){105 apiManager = await this._stack[i].run();106 }else{107 let payload = await this._stack[i-1].processData();108 apiManager = this._stack[i];109 apiManager.setState(TaskExecutorConstants.PAYLOAD,payload);110 apiManager = await this._stack[i].run();111 }112 113 if(apiManager.getState(TaskExecutorConstants.ERROR)){114 throw new Error(apiManager.getState(TaskExecutorConstants.ERROR))115 console.log(apiManager.getState(TaskExecutorConstants.ERROR))116 // break;117 }118 this._stack[i]= apiManager;119 this._index = this._index+1;120 121 } 122 return true;123 }124 freeze(){125 return {126 wf: {127 index:this._index128 },129 stack: this._stack.map(s => s._getContext()),130 }131 }132 hydrate(context){133 this._index = context.wf.index;134 for(let i=0;i<this._stack.length;i++){135 this._stack[i]._setContext(context.stack[i])136 }137 }138}139let context= null;140let UserManager = new TaskExecutor({}, fetchUsers,pickRandomItem);141let TodoManager = new TaskExecutor({}, fetchTodos);142async function test2(){143 let wf = new WorkflowManager([UserManager,TodoManager]);144 try{145 if(context) wf.hydrate(context)146 let response = await wf.start();147 // if(response) return148 }catch(e){149 context = wf.freeze();...

Full Screen

Full Screen

Touchable.js

Source:Touchable.js Github

copy

Full Screen

...17 if (this.props.isToggler && typeof this.props.onToggle === 'function') {18 this.props.onToggle()19 }20 if (this.props.setContext) {21 this.props._setContext(this.props.setContext)22 }23 if (activeClassName) {24 toggleFocus()25 }26 if (typeof this.props.onPress === 'function') {27 this.props.onPress(this.props.onPressParams || props, params)28 }29 }30 onPressIn = () => {31 const {activeClassName, onPressIn, toggleFocus} = this.props32 if (activeClassName) {33 toggleFocus()34 }35 if (typeof onPressIn === 'function') {36 onPressIn()37 }38 if (Object.keys(this.props).indexOf('setContext:onPressIn') >= 0) {39 this.props._setContext(this.props['setContext:onPressIn'])40 }41 }42 onPressOut = async () => {43 const {activeClassName, onPressOut, toggleFocus} = this.props44 if (activeClassName) {45 toggleFocus()46 }47 if (typeof onPressIn === 'function') {48 onPressOut()49 }50 if (Object.keys(this.props).indexOf('setContext:onPressOut') >= 0) {51 this.props._setContext(this.props['setContext:onPressOut'])52 }53 if (this.props.setStorage) {54 const cb = this.props.debug ? console.warn('save successful') : null55 _isArray(this.props.setStorage) && await Storage.multiSet([this.props.setStorage], () => cb)56 }57 }58 isDisabled = () => {59 const {disabled, loading} = this.props60 if (typeof this.props.isDisabled === 'function') {61 return this.props.isDisabled()62 }63 return loading || disabled64 }65 render () {...

Full Screen

Full Screen

setContext.js

Source:setContext.js Github

copy

Full Screen

...24 */25function setContext(_x, _x2) {26 return _setContext.apply(this, arguments);27}28function _setContext() {29 _setContext = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(req, h) {30 var credentials, context;31 return regeneratorRuntime.wrap(function _callee$(_context) {32 while (1) {33 switch (_context.prev = _context.next) {34 case 0:35 credentials = req.auth.credentials;36 context = {37 path: req.path,38 params: req.params,39 query: req.query,40 payload: req.payload,41 token: credentials != null ? "bearer ".concat(credentials.token) : null,42 host: process.env.VIYA_SERVER...

Full Screen

Full Screen

Refetcher.js

Source:Refetcher.js Github

copy

Full Screen

...28 onPress = (...args) => {29 try {30 const currentVariables = this._getPayload(this.props)31 if (typeof this.props._setContext === 'function' && this.props.setContext) {32 this.props._setContext(this.props.setContext)33 }34 if (typeof this.props.refetch === 'function') {35 this.props.refetch(currentVariables)36 }37 if (typeof this.props.onPress === 'function') {38 this.props.onPress(...args)39 }40 } catch (error) {41 console.error(error)42 }43 }44 render () {45 const {children, variables, ...props} = this.props46 return (...

Full Screen

Full Screen

Layer.js

Source:Layer.js Github

copy

Full Screen

...8 set block(block) {9 this._block = block;10 }11 draw() {12 this._setContext();13 if (!this._block) {14 return;15 }16 this._drawBlock();17 }18 _setContext() {19 if (!this._context) {20 this._context = this._canvas.getContext('2d');21 this._context.imageSmoothingEnabled = true;22 }23 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page._client.send('Page.setDownloadBehavior', {6 });7 await page.click('a[href="/files/example.pdf"]');8 await browser.close();9})();10const puppeteer = require('puppeteer');11(async () => {12 const browser = await puppeteer.launch();13 const page = await browser.newPage();14 await page._client.send('Page.setDownloadBehavior', {15 });16 await page.click('a[href="/files/example.pdf"]');17 await browser.close();18})();19const puppeteer = require('puppeteer');20(async () => {21 const browser = await puppeteer.launch();22 const page = await browser.newPage();23 await page._client.send('Page.setDownloadBehavior', {24 });25 await page.click('a[href="/files/example.pdf"]');26 await browser.close();27})();28const puppeteer = require('puppeteer');29(async () => {30 const browser = await puppeteer.launch();31 const page = await browser.newPage();32 await page._client.send('Page.setDownloadBehavior', {33 });34 await page.click('a[href="/files/example.pdf"]');35 await browser.close();36})();37const puppeteer = require('puppeteer');38(async () => {39 const browser = await puppeteer.launch();40 const page = await browser.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 await page._client.send('Emulation.clearDeviceMetricsOverride');6 await page.setViewport({width: 1024, height: 768});7 await page.screenshot({path: 'google.png'});8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page._setContext({userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'});6 await page.waitFor(1000);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._setExtraHTTPHeaders({14 'Accept-Language': 'en-US,en;q=0.9'15 });16 await page.waitFor(1000);17 await browser.close();18})();19const puppeteer = require('puppeteer');20(async () => {21 const browser = await puppeteer.launch();22 const page = await browser.newPage();23 await page._setGeolocation({latitude: 51.508530, longitude: -0.076132});24 await page.waitFor(1000);25 await browser.close();26})();27const puppeteer = require('puppeteer');28(async () => {29 const browser = await puppeteer.launch();30 const page = await browser.newPage();31 await page._setOfflineMode(true);32 await page.waitFor(1000);33 await browser.close();34})();35const puppeteer = require('puppeteer');36(async () => {37 const browser = await puppeteer.launch();38 const page = await browser.newPage();39 await page._setRequestInterception(true);40 page.on('request', interceptedRequest

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4(async () => {5 const browser = await puppeteer.launch({6 });7 const page = await browser.newPage();8 await page._client.send('Network.clearBrowserCookies');9 await page._client.send('Network.clearBrowserCache');10 await page._client.send('Page.setDownloadBehavior', {11 downloadPath: path.join(__dirname, 'downloads')12 });13 await page.waitFor(1000);14 await page.click('#downloadbutton');15 await page.waitFor(1000);16 fs.readdir(path.join(__dirname, 'downloads'), (err, files) => {17 if (err) {18 console.log(err);19 } else {20 console.log(files);21 }22 });23 await browser.close();24})();25{26 "scripts": {27 },28 "dependencies": {29 }30}31const puppeteer = require('puppeteer');32const fs = require('fs');33const path = require('path');34(async () => {35 const browser = await puppeteer.launch({36 });37 const page = await browser.newPage();38 await page._client.send('

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page._client.send('Emulation.setDeviceMetricsOverride', {6 });7 await page.screenshot({path: 'example.png'});8 await browser.close();9})();

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 Puppeteer 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