Best JavaScript code snippet using playwright-internal
player-p.js
Source:player-p.js
...212 }213 214 if( s instanceof MyGame.Shaman )215 {216 s.fsm.consumeEvent(s.state);217 this.renderText(s.talk);218 this.fsm.consumeEvent('startstop');219 s.destroy();220 }221 222 223 224 if( s instanceof MyGame.Pickup ){225 this.backpack = s;226 MyGame.counter = 0;227 MyGame.timeout = 120;228 229 s.destroy();230 231 this.fsm.consumeEvent('stop');232 this.fsm.consumeEvent('openBackpack');233 /*this.fsm.consumeEvent('startstop');*/234 } 235 if( s instanceof MyGame.Challenge ){236 if(this.backpack === undefined)237 {238 if(this.facing === 1)239 {240 this.body.velocity.x = 200;241 }else{242 this.body.velocity.x = -200;243 }244 this.renderText('Suche das Bild das dir den Weg weist <br> (weiter mit <span class="button"> Enter </span)');245 this.loseLevel();246 }else if(this.backpack.pictureType !== s.challengetype)247 {248 if(this.facing === 1)249 {250 this.body.velocity.x = 200;251 }else{252 this.body.velocity.x = -200;253 }254 this.renderText('Dein Bild erfüllt nicht das Gesetz:' +s.challengetype + ' <br> <br> <img src="assets/img/Gestaltgesetze/'+this.backpack.picture+'.png" style=""> <br> du bist leider auf dem falschen Weg! <br> Suche ein Tor auf einer anderen Ebene <br>(weiter mit <span class="button"> Enter </span)');255 MyGame.mistakes = MyGame.mistakes +1;256 this.fsm.consumeEvent('startchallenge');257 }258 else{259 this.renderText('Du bist auf dem Richtigen Weg. Dein Bild erfüllt das Gesetz <b> ' + s.challengetype + ' </b> <br> <img src="assets/img/Gestaltgesetze/'+this.backpack.picture+'.png" style=""> <br> (weiter mit <span class="button"> Enter </span)');260 s.destroy();261 this.backpack = undefined; 262 this.fsm.consumeEvent('startstop');263 MyGame.taskTimes.push(MyGame.counter);264 MyGame.counter = 0;265 MyGame.timeout = 999;266 }267 }268 269 };270 MyGame.Player.prototype.updateObject = function()271 {272 273 var game_state = this.game.state.states[this.game.state.current];274 // collide player with tilemap layers that are marked 'solid'275 for( var i = 0; i < game_state.layers.length; i++ )276 {277 var lyr = game_state.layers[i];278 if( lyr.solid )279 this.game.physics.collide( this, lyr );280 }281 // collide with sprites that are 'solid'282 for( i = 0; i < game_state.groups.length; i++ )283 {284 this.game.physics.collide( this, game_state.groups[i], this.spriteCollisionCallback, null, this );285 }286 287 // handle input288 var left = this.game.input.keyboard.isDown( MyGame.KEY_L ); 289 var right = this.game.input.keyboard.isDown( MyGame.KEY_R ); 290 var run = this.game.input.keyboard.isDown( MyGame.KEY_RUN );291 var jump = this.game.input.keyboard.isDown( MyGame.KEY_JUMP ); 292 var jump2 = this.game.input.keyboard.isDown( MyGame.KEY_JUMP2 ); 293 var openBackpack = this.game.input.keyboard.isDown( MyGame.KEY_BACKPACK ); 294 var showMap = this.game.input.keyboard.isDown( MyGame.KEY_MAP ); 295 var action = this.game.input.keyboard.isDown( MyGame.KEY_ACTION ); 296 var reset = this.game.input.keyboard.isDown( MyGame.KEY_RESET ); 297 var q1 = this.game.input.keyboard.isDown( MyGame.KEY_Q1 ); 298 var q2 = this.game.input.keyboard.isDown( MyGame.KEY_Q2 ); 299 var state = this.fsm.getState();300 if (reset){this.loseLevel();}301 if(MyGame.globalcounter > 600 && MyGame.midtest || MyGame.levelinfo === "Level-7" && MyGame.midtest || q1)302 {303 var midQuestionTrigger = $.grep(game_state.triggers, function(n){304 return(n.name === "Midquestions") 305 });306 MyGame.timeout = 999;307 midQuestionTrigger[0].activate();308 MyGame.midtest = false;309 }310 if(MyGame.globalcounter > 1200 || q2)311 {312 var endQuestionTrigger = $.grep(game_state.triggers, function(n){313 return(n.name === "Endtrigger") 314 });315 MyGame.timeout = 999;316 endQuestionTrigger[0].activate();317 }318 if ( reset ){this.loseLevel();}319 if ( (MyGame.counter > MyGame.timeout )){320 MyGame.counter = 0;321 this.renderText('Du warst leider zu langsam <br> Das Bild kehrt an seinen Schrein zurück!');322 this.loseLevel();323 }324 switch( state )325 {326 327 case 'walking':328 329 if( jump || jump2)330 {331 this.fsm.consumeEvent( 'jump' );332 } 333 else if( left && run)334 {335 if(this.body.blocked.left && !this.body.blocked.down)336 {337 this.fsm.consumeEvent( 'startwalljump' );338 }else{ 339 if(this.waitTime(this.soundtimer, 355))340 {341 this.playSound(this.noise);342 } 343 this.jump_increment = 450;344 this.walk_velocity = 230;345 this.animations.play('run');346 this.goLeft();347 }348 }349 else if( right && run )350 {351 if(this.body.blocked.right && !this.body.blocked.down)352 {353 this.fsm.consumeEvent( 'startwalljump' );354 }else{ 355 this.animations.play( 'run' );356 if(this.waitTime(this.soundtimer, 355))357 {358 this.playSound(this.noise);359 } 360 this.jump_increment = 450;361 this.walk_velocity = 230;362 this.goRight();363 }364 }365 else if( left )366 {367 this.animations.play( 'left' );368 if(this.waitTime(this.soundtimer, 420))369 {370 this.playSound(this.noise);371 }372 if(this.body.blocked.left && !this.body.blocked.down)373 {374 this.fsm.consumeEvent( 'startwalljump' );375 }else{ 376 this.jump_increment = 350;377 this.walk_velocity = 110;378 this.goLeft();379 }380 }381 else if( right )382 {383 this.animations.play( 'right' );384 if(this.waitTime(this.soundtimer, 420))385 {386 this.playSound(this.noise);387 }388 if(this.body.blocked.right && !this.body.blocked.down)389 {390 this.fsm.consumeEvent( 'startwalljump' );391 }else{ 392 this.jump_increment = 350;393 this.walk_velocity = 110;394 this.goRight();395 }396 }397 else398 {399 this.fsm.consumeEvent( 'stop' );400 }401 402 break;403 case 'jumping':404 case 'falling':405 // reset horizontal velocity406 this.body.velocity.x = 0;407 // land?408 if( this.body.touching.down || this.body.blocked.down )409 {410 this.fsm.consumeEvent( 'land' );411 }412 // can move side to side413 if( left )414 if(this.body.blocked.left)415 {416 this.fsm.consumeEvent('startwalljump');417 }else{418 this.airborneLeft();419 420 }421 else if( right )422 if(this.body.blocked.right)423 {424 this.fsm.consumeEvent('startwalljump');425 }else{426 this.airborneRight();427 428 }429 break;430 case 'walljump':431 // reset horizontal velocity432 this.jump_increment = 450433 this.body.velocity.x = 0;434 this.body.velocity.y = 30;435 this.body.gravity.y = 1000; 436 this.frame = 33; 437 // land?438 if((jump && right && left )||(jump2 && right && left ) ){439 break;440 }441 else if( jump && right || (jump2 && right )) 442 {443 if(this.facing === 1)444 {445 this.jump_increment = 450;446 this.walk_velocity = 230;447 this.jump();448 this.fsm.consumeEvent('jump');449 break;450 }451 }else if( (jump && left) || (jump2 && left )) 452 {453 if(this.facing === 2 )454 {455 this.jump_increment = 450;456 this.walk_velocity = 230;457 this.jump();458 this.fsm.consumeEvent('jump');459 break;460 }461 }462 else if( left )463 { 464 if(this.facing === 1 ){465 this.walk_velocity = 0;466 this.body.velocity.y = 20; 467 }else{468 this.jump_increment = 450;469 this.walk_velocity = 230;470 this.airborneRight();471 this.fsm.consumeEvent('jump');472 } 473 break;474 } 475 else if( right )476 { 477 if(this.facing === 2 ){478 this.walk_velocity = 0;479 this.body.velocity.y = 20; 480 }else{481 this.jump_increment = 450;482 this.walk_velocity = 230;483 this.airborneLeft();484 this.fsm.consumeEvent('jump');485 } 486 break;487 }488 else{489 490 this.fsm.consumeEvent('stop');491 break;492 }493 break;494 case 'idle':495 // reset horizontal velocity496 this.body.velocity.x = 0;497 this.walk_velocity = 110;498 this.jump_increment = 350;499 this.body.gravity.y = 1000;500 // can walk or jump501 if( jump || jump2)502 this.fsm.consumeEvent( 'jump' );503 504 else if( left )505 {506 this.facing = Phaser.LEFT;507 this.fsm.consumeEvent( 'left' );508 }509 else if( right )510 {511 this.facing = Phaser.RIGHT;512 this.fsm.consumeEvent( 'right' );513 }514 else if ( openBackpack )515 {516 this.fsm.consumeEvent( 'openBackpack' );517 }518 519 else if ( showMap )520 {521 this.fsm.consumeEvent( 'showMap' );522 }523 524 break;525 case 'openBackpack':526 527 this.fsm.consumeEvent( 'closeBackpack' );528 break;529 530 case 'showMap':531 532 this.fsm.consumeEvent( 'closeMap' );533 break;534 case 'challenge':535 if(this.waitTime(this.timer, 400))536 {537 this.fsm.consumeEvent('startstop');538 539 }540 break;541 case 'stunned':542 if(this.waitTime(this.timer, 800))543 {544 this.fsm.consumeEvent('recover');545 }546 break;547 case 'stop':548 if( action )549 {550 $('#text').slideUp(500); 551 this.fsm.consumeEvent('end');552 }553 break;554 default:555 break;556 }557 };558 MyGame.Player.prototype.openBackpack = function()559 {560 var content = "Der Rucksack ist Leer (weiter mit <span class='button'> Enter </span>)"561 if (this.backpack !== undefined)562 {563 content = '<img src="assets/img/Gestaltgesetze/'+this.backpack.picture+'.png" style=""> <br> (weiter mit <span class="button"> Enter </span>)' 564 }565 $('#text').html(content);566 $('#text').slideDown(500);567 };568 MyGame.Player.prototype.showMap = function()569 {570 var content = '<img src="assets/img/map.png" style=""> <br> (weiter mit <span class="button"> Enter </span>)' 571 $('#text').html(content);572 $('#text').slideDown(500);573 };574 MyGame.Player.prototype.challenge = function()575 {576 this.timer = this.time.now;577 };578 MyGame.Player.prototype.washit = function()579 {580 this.timer = this.time.now;581 }; 582 MyGame.Player.prototype.stop = function()583 {584 this.body.velocity.x = 0;585 };586 MyGame.Player.prototype.hit = function()587 {588 // can't be hit while already stunned589 if( this.fsm.getState() != 'stunned' )590 {591 this.fsm.consumeEvent( 'hit' );592 //this.live= this.live -1;593 MyGame.hits = MyGame.hits +1;594 $('#live').html('Energie: ' + this.live);595 }596 if( this.body.touching.right )597 {598 this.body.velocity.x = -150;599 this.body.touching.right = false;600 }601 else if( this.body.touching.left )602 {603 this.body.velocity.x = 150;604 this.body.touching.left = false;605 }606 if( this.body.touching.down )607 {608 this.body.velocity.y = -350;609 this.body.touching.down = false;610 }611 else if( this.body.touching.up )612 {613 if(this.facing === 1){614 this.body.velocity.x = 300;615 }else{616 this.body.velocity.x = -300;617 }618 this.body.touching.up = false;619 }620 };621 MyGame.Player.prototype.idle = function()622 {623 this.animations.stop();624 this.frame = 36;625 if( this.facing == Phaser.LEFT )626 {627 this.scale.x = -1;628 }629 else630 {631 this.scale.x = 1;632 }633 };634 MyGame.Player.prototype.walking = function()635 {636 if( this.facing == Phaser.LEFT )637 {638 this.walkLeft();639 }640 else641 {642 this.walkRight();643 }644 };645 MyGame.Player.prototype.jumping = function()646 {647 this.jump();648 };649 MyGame.Player.prototype.walljump = function()650 {651 this.animations.stop();652 this.frame = 33;653 }654 MyGame.Player.prototype.falling = function()655 {656 this.frame = 33;657 };658 MyGame.Player.prototype.recovering = function() 659 {660 this.timer = this.time.now;661 this.fsm.consumeEvent( 'recover' );662 };663 MyGame.Player.prototype.stunned = function() 664 {665 // start timer666 this.timer = this.time.now;667 this.frame = 3;668 if( this.facing == Phaser.LEFT )669 {670 this.scale.x = -1;671 }672 else673 {674 this.scale.x = 1;675 }...
player-n.js
Source:player-n.js
...212 }213 214 if( s instanceof MyGame.Shaman )215 {216 s.fsm.consumeEvent(s.state);217 this.renderText(s.talk);218 this.fsm.consumeEvent('startstop');219 s.destroy();220 }221 222 223 224 if( s instanceof MyGame.Pickup ){225 this.backpack = s;226 MyGame.timeout = 120;227 228 s.destroy();229 230 this.fsm.consumeEvent('stop');231 this.fsm.consumeEvent('openBackpack');232 /*this.fsm.consumeEvent('startstop');*/233 } 234 if( s instanceof MyGame.Challenge ){235 if(this.backpack === undefined)236 {237 if(this.facing === 1)238 {239 this.body.velocity.x = 200;240 }else{241 this.body.velocity.x = -200;242 }243 this.renderText('Suche das Bild das dir den Weg weist <br> (weiter mit <span class="button"> Enter </span)');244 this.loseLevel();245 }else if(this.backpack.pictureType !== s.challengetype)246 {247 if(this.facing === 1)248 {249 this.body.velocity.x = 200;250 }else{251 this.body.velocity.x = -200;252 }253 this.renderText('Dein Bild erfüllt nicht das Gesetz:' +s.challengetype + ' <br> <br> <img src="assets/img/Gestaltgesetze/'+this.backpack.picture+'.png" style=""> <br> du bist leider auf dem falschen Weg! <br> Suche ein Tor auf einer anderen Ebene <br> (weiter mit <span class="button"> Enter </span)');254 MyGame.mistakes = MyGame.mistakes +1;255 this.fsm.consumeEvent('startchallenge');256 }257 else{258 this.renderText('Du bist auf dem Richtigen Weg. Dein Bild erfüllt das Gesetz <b> ' + s.challengetype + ' </b> <br> <img src="assets/img/Gestaltgesetze/'+this.backpack.picture+'.png" style=""> <br> (weiter mit <span class="button"> Enter </span)');259 s.destroy();260 this.backpack = undefined; 261 this.fsm.consumeEvent('startstop');262 MyGame.taskTimes.push(MyGame.timeout);263 MyGame.timeout = 999;264 }265 }266 267 };268// Update269 MyGame.Player.prototype.updateObject = function()270 {271 272 273 var game_state = this.game.state.states[this.game.state.current];274 // collide player with tilemap layers that are marked 'solid'275 for( var i = 0; i < game_state.layers.length; i++ )276 {277 var lyr = game_state.layers[i];278 if( lyr.solid )279 this.game.physics.collide( this, lyr );280 }281 // collide with sprites that are 'solid'282 for( i = 0; i < game_state.groups.length; i++ )283 {284 this.game.physics.collide( this, game_state.groups[i], this.spriteCollisionCallback, null, this );285 }286 // handle input287 var left = this.game.input.keyboard.isDown( MyGame.KEY_L ); 288 var right = this.game.input.keyboard.isDown( MyGame.KEY_R ); 289 var run = this.game.input.keyboard.isDown( MyGame.KEY_RUN );290 var jump = this.game.input.keyboard.isDown( MyGame.KEY_JUMP ); 291 var jump2 = this.game.input.keyboard.isDown( MyGame.KEY_JUMP2 ); 292 var openBackpack = this.game.input.keyboard.isDown( MyGame.KEY_BACKPACK ); 293 var showMap = this.game.input.keyboard.isDown( MyGame.KEY_MAP ); 294 var action = this.game.input.keyboard.isDown( MyGame.KEY_ACTION ); 295 var reset = this.game.input.keyboard.isDown( MyGame.KEY_RESET ); 296 var q1 = this.game.input.keyboard.isDown( MyGame.KEY_Q1 ); 297 var q2 = this.game.input.keyboard.isDown( MyGame.KEY_Q2 ); 298 var state = this.fsm.getState();299 if (reset){this.loseLevel();}300 if(MyGame.globalcounter > 600 && MyGame.midtest || MyGame.levelinfo === "Level-7" && MyGame.midtest || q1)301 {302 var midQuestionTrigger = $.grep(game_state.triggers, function(n){303 return(n.name === "Midquestions") 304 });305 MyGame.timeout = 999;306 midQuestionTrigger[0].activate();307 MyGame.midtest = false;308 }309 if(MyGame.globalcounter > 1200 || q2)310 {311 var endQuestionTrigger = $.grep(game_state.triggers, function(n){312 return(n.name === "Endtrigger") 313 });314 MyGame.timeout = 999;315 endQuestionTrigger[0].activate();316 }317 if(MyGame.counter > MyGame.timeout){318 this.renderText('Du warst leider zu langsam <br> Das Bild kehrt an seinen Schrein zurück!')319 this.loseLevel(); 320 }321 if ( reset ){this.loseLevel();}322 switch( state )323 {324 325 case 'walking':326 327 if( jump || jump2)328 {329 this.fsm.consumeEvent( 'jump' );330 } 331 else if( left && run)332 {333 if(this.body.blocked.left && !this.body.blocked.down)334 {335 this.fsm.consumeEvent( 'startwalljump' );336 }else{ 337 if(this.waitTime(this.soundtimer, 355))338 {339 this.playSound(this.noise);340 } 341 this.jump_increment = 450;342 this.walk_velocity = 230;343 this.animations.play('run');344 this.goLeft();345 }346 }347 else if( right && run )348 {349 if(this.body.blocked.right && !this.body.blocked.down)350 {351 this.fsm.consumeEvent( 'startwalljump' );352 }else{ 353 this.animations.play( 'run' );354 if(this.waitTime(this.soundtimer, 355))355 {356 this.playSound(this.noise);357 } 358 this.jump_increment = 450;359 this.walk_velocity = 230;360 this.goRight();361 }362 }363 else if( left )364 {365 this.animations.play( 'left' );366 if(this.waitTime(this.soundtimer, 420))367 {368 this.playSound(this.noise);369 }370 if(this.body.blocked.left && !this.body.blocked.down)371 {372 this.fsm.consumeEvent( 'startwalljump' );373 }else{ 374 this.jump_increment = 350;375 this.walk_velocity = 110;376 this.goLeft();377 }378 }379 else if( right )380 {381 this.animations.play( 'right' );382 if(this.waitTime(this.soundtimer, 420))383 {384 this.playSound(this.noise);385 }386 if(this.body.blocked.right && !this.body.blocked.down)387 {388 this.fsm.consumeEvent( 'startwalljump' );389 }else{ 390 this.jump_increment = 350;391 this.walk_velocity = 110;392 this.goRight();393 }394 }395 else396 {397 this.fsm.consumeEvent( 'stop' );398 }399 400 break;401 case 'jumping':402 case 'falling':403 // reset horizontal velocity404 this.body.velocity.x = 0;405 // land?406 if( this.body.touching.down || this.body.blocked.down )407 {408 this.fsm.consumeEvent( 'land' );409 }410 // can move side to side411 if( left )412 if(this.body.blocked.left)413 {414 this.fsm.consumeEvent('startwalljump');415 }else{416 this.airborneLeft();417 418 }419 else if( right )420 if(this.body.blocked.right)421 {422 this.fsm.consumeEvent('startwalljump');423 }else{424 this.airborneRight();425 426 }427 break;428 case 'walljump':429 // reset horizontal velocity430 this.jump_increment = 450431 this.body.velocity.x = 0;432 this.body.velocity.y = 30;433 this.body.gravity.y = 1000; 434 this.frame = 33; 435 // land?436 if((jump && right && left )||(jump2 && right && left ) ){437 break;438 }439 else if( jump && right || (jump2 && right )) 440 {441 if(this.facing === 1)442 {443 this.jump_increment = 450;444 this.walk_velocity = 230;445 this.jump();446 this.fsm.consumeEvent('jump');447 break;448 }449 }else if( (jump && left) || (jump2 && left )) 450 {451 if(this.facing === 2 )452 {453 this.jump_increment = 450;454 this.walk_velocity = 230;455 this.jump();456 this.fsm.consumeEvent('jump');457 break;458 }459 }460 else if( left )461 { 462 if(this.facing === 1 ){463 this.walk_velocity = 0;464 this.body.velocity.y = 20; 465 }else{466 this.jump_increment = 450;467 this.walk_velocity = 230;468 this.airborneRight();469 this.fsm.consumeEvent('jump');470 } 471 break;472 } 473 else if( right )474 { 475 if(this.facing === 2 ){476 this.walk_velocity = 0;477 this.body.velocity.y = 20; 478 }else{479 this.jump_increment = 450;480 this.walk_velocity = 230;481 this.airborneLeft();482 this.fsm.consumeEvent('jump');483 } 484 break;485 }486 else{487 488 this.fsm.consumeEvent('stop');489 break;490 }491 break;492 case 'idle':493 // reset horizontal velocity494 this.body.velocity.x = 0;495 this.walk_velocity = 110;496 this.jump_increment = 350;497 this.body.gravity.y = 1000;498 // can walk or jump499 if( jump || jump2)500 this.fsm.consumeEvent( 'jump' );501 502 else if( left )503 {504 this.facing = Phaser.LEFT;505 this.fsm.consumeEvent( 'left' );506 }507 else if( right )508 {509 this.facing = Phaser.RIGHT;510 this.fsm.consumeEvent( 'right' );511 }512 else if ( openBackpack )513 {514 this.fsm.consumeEvent( 'openBackpack' );515 }516 517 else if ( showMap )518 {519 this.fsm.consumeEvent( 'showMap' );520 }521 522 break;523 case 'openBackpack':524 525 this.fsm.consumeEvent( 'closeBackpack' );526 break;527 case 'showMap':528 529 this.fsm.consumeEvent( 'closeMap' );530 break;531 case 'challenge':532 if(this.waitTime(this.timer, 400))533 {534 this.fsm.consumeEvent('startstop');535 536 }537 break;538 case 'stunned':539 if(this.waitTime(this.timer, 800))540 {541 this.fsm.consumeEvent('recover');542 }543 break;544 case 'stop':545 if( action )546 {547 $('#text').slideUp(500); 548 this.fsm.consumeEvent('end');549 }550 break;551 default:552 break;553 }554 };555 MyGame.Player.prototype.openBackpack = function()556 {557 var content = "Der Rucksack ist Leer (weiter mit <span class='button'> Enter </span>)"558 if (this.backpack !== undefined)559 {560 content = '<img src="assets/img/Gestaltgesetze/'+this.backpack.picture+'.png" style=""> <br> (weiter mit<span class="button"> Enter </span>)' 561 }562 $('#text').html(content);563 $('#text').slideDown(500);564 };565 MyGame.Player.prototype.showMap = function()566 {567 var content = '<img src="assets/img/map.png" style=""> <br> (weiter mit <span class="button"> Enter </span>)' 568 $('#text').html(content);569 $('#text').slideDown(500);570 };571 MyGame.Player.prototype.challenge = function()572 {573 this.timer = this.time.now;574 };575 MyGame.Player.prototype.washit = function()576 {577 this.timer = this.time.now;578 }; 579 MyGame.Player.prototype.stop = function()580 {581 this.body.velocity.x = 0;582 };583 MyGame.Player.prototype.hit = function()584 {585 // can't be hit while already stunned586 if( this.fsm.getState() != 'stunned' )587 {588 this.fsm.consumeEvent( 'hit' );589 //this.live= this.live -1;590 MyGame.hits = MyGame.hits +1;591 $('#live').html('Energie: ' + this.live);592 }593 if( this.body.touching.right )594 {595 this.body.velocity.x = -150;596 this.body.touching.right = false;597 }598 else if( this.body.touching.left )599 {600 this.body.velocity.x = 150;601 this.body.touching.left = false;602 }603 if( this.body.touching.down )604 {605 this.body.velocity.y = -350;606 this.body.touching.down = false;607 }608 else if( this.body.touching.up )609 {610 if(this.facing === 1){611 this.body.velocity.x = 300;612 }else{613 this.body.velocity.x = -300;614 }615 this.body.touching.up = false;616 }617 };618 MyGame.Player.prototype.idle = function()619 {620 this.animations.stop();621 this.frame = 36;622 if( this.facing == Phaser.LEFT )623 {624 this.scale.x = -1;625 }626 else627 {628 this.scale.x = 1;629 }630 };631 MyGame.Player.prototype.walking = function()632 {633 if( this.facing == Phaser.LEFT )634 {635 this.walkLeft();636 }637 else638 {639 this.walkRight();640 }641 };642 MyGame.Player.prototype.jumping = function()643 {644 this.jump();645 };646 MyGame.Player.prototype.walljump = function()647 {648 this.animations.stop();649 this.frame = 33;650 }651 MyGame.Player.prototype.falling = function()652 {653 this.frame = 33;654 };655 MyGame.Player.prototype.recovering = function() 656 {657 this.timer = this.time.now;658 this.fsm.consumeEvent( 'recover' );659 };660 MyGame.Player.prototype.stunned = function() 661 {662 // start timer663 this.timer = this.time.now;664 this.frame = 3;665 if( this.facing == Phaser.LEFT )666 {667 this.scale.x = -1;668 }669 else670 {671 this.scale.x = 1;672 }...
player.js
Source:player.js
...206 }207 208 if( s instanceof MyGame.Shaman )209 {210 s.fsm.consumeEvent(s.state);211 this.renderText(s.talk);212 this.fsm.consumeEvent('startstop');213 s.destroy();214 }215 216 217 218 if( s instanceof MyGame.Pickup ){219 this.backpack = s;220 221 s.destroy();222 223 this.fsm.consumeEvent('stop');224 this.fsm.consumeEvent('openBackpack');225 /*this.fsm.consumeEvent('startstop');*/226 } 227 if( s instanceof MyGame.Challenge ){228 if(this.backpack === undefined)229 {230 if(this.facing === 1)231 {232 this.body.velocity.x = 200;233 }else{234 this.body.velocity.x = -200;235 }236 this.renderText('Du besitzt kein Bild um das Tor zu öffnen <br> (weiter mit - Enter -)');237 this.fsm.consumeEvent('startchallenge');238 }else if(this.backpack.pictureType !== s.challengetype)239 {240 if(this.facing === 1)241 {242 this.body.velocity.x = 200;243 }else{244 this.body.velocity.x = -200;245 }246 this.renderText('Dein Bild besitzt nicht die Funktion :' +s.challengetype + ' <br> (weiter mit - Enter -)');247 MyGame.mistakes = MyGame.mistakes +1;248 this.fsm.consumeEvent('startchallenge');249 }250 else{251 this.renderText('Das Tor <b> ' + s.challengetype + ' </b> öffnet sich durch <br> <img src="assets/img/functions/'+this.backpack.picture+'.png" style=""> <br> (weiter mit - Enter -)');252 s.destroy();253 this.backpack = undefined; 254 this.fsm.consumeEvent('startstop');255 this.live = this.live+1;256 $('#live').html('Energie: ' + this.live);257 MyGame.taskTimes.push(MyGame.counter);258 MyGame.counter = 0;259 }260 }261 262 };263// Update264 MyGame.Player.prototype.updateObject = function()265 {266 var game_state = this.game.state.states[this.game.state.current];267 // collide player with tilemap layers that are marked 'solid'268 for( var i = 0; i < game_state.layers.length; i++ )269 {270 var lyr = game_state.layers[i];271 if( lyr.solid )272 this.game.physics.collide( this, lyr );273 }274 // collide with sprites that are 'solid'275 for( i = 0; i < game_state.groups.length; i++ )276 {277 this.game.physics.collide( this, game_state.groups[i], this.spriteCollisionCallback, null, this );278 }279 // handle input280 var left = this.game.input.keyboard.isDown( MyGame.KEY_L ); 281 var right = this.game.input.keyboard.isDown( MyGame.KEY_R ); 282 var up = this.game.input.keyboard.isDown( MyGame.KEY_UP );283 var down = this.game.input.keyboard.isDown( MyGame.KEY_DOWN );284 var run = this.game.input.keyboard.isDown( MyGame.KEY_RUN );285 var jump = this.game.input.keyboard.isDown( MyGame.KEY_JUMP ); 286 var openBackpack = this.game.input.keyboard.isDown( MyGame.KEY_BACKPACK ); 287 var openMap = this.game.input.keyboard.isDown( MyGame.KEY_MAP ); 288 var action = this.game.input.keyboard.isDown( MyGame.KEY_ACTION ); 289 290 var state = this.fsm.getState();291 if (this.live < 0 ){this.loseLevel();}292 switch( state )293 {294 case 'walking':295 296 if( jump ) 297 this.fsm.consumeEvent( 'jump' );298 else if( left && run)299 {300 if(this.body.blocked.left && !this.body.blocked.down)301 {302 this.fsm.consumeEvent( 'startwalljump' );303 }else{ 304 this.jump_increment = 450;305 this.walk_velocity = 230;306 this.animations.play('run');307 this.goLeft();308 }309 }310 else if( right && run )311 {312 if(this.body.blocked.right && !this.body.blocked.down)313 {314 this.fsm.consumeEvent( 'startwalljump' );315 }else{ 316 this.animations.play( 'run' ); 317 this.jump_increment = 450;318 this.walk_velocity = 230;319 this.goRight();320 }321 }322 else if( left )323 {324 this.animations.play( 'left' );325 if(this.body.blocked.left && !this.body.blocked.down)326 {327 this.fsm.consumeEvent( 'startwalljump' );328 }else{ 329 this.jump_increment = 350;330 this.walk_velocity = 110;331 this.goLeft();332 }333 }334 else if( right )335 {336 this.animations.play( 'right' );337 if(this.body.blocked.right && !this.body.blocked.down)338 {339 this.fsm.consumeEvent( 'startwalljump' );340 }else{ 341 this.jump_increment = 350;342 this.walk_velocity = 110;343 this.goRight();344 }345 }346 else347 {348 this.fsm.consumeEvent( 'stop' );349 }350 351 break;352 case 'jumping':353 case 'falling':354 // reset horizontal velocity355 this.body.velocity.x = 0;356 // land?357 if( this.body.touching.down || this.body.blocked.down )358 {359 this.fsm.consumeEvent( 'land' );360 }361 // can move side to side362 if( left )363 if(this.body.blocked.left)364 {365 this.fsm.consumeEvent('startwalljump');366 }else{367 this.airborneLeft();368 369 }370 else if( right )371 if(this.body.blocked.right)372 {373 this.fsm.consumeEvent('startwalljump');374 }else{375 this.airborneRight();376 377 }378 break;379 case 'walljump':380 // reset horizontal velocity381 this.jump_increment = 300382 this.body.velocity.x = 0;383 this.body.velocity.y = 30;384 this.body.gravity.y = 1000; 385 this.frame = 33; 386 // land?387 if( jump && right ) 388 {389 if(this.facing === 1)390 {391 this.jump_increment = 450;392 this.walk_velocity = 230;393 this.jump();394 this.fsm.consumeEvent('goRight');395 }396 }else if( jump && left ) 397 {398 if(this.facing === 2 )399 {400 this.jump_increment = 450;401 this.walk_velocity = 230;402 this.jump();403 this.fsm.consumeEvent('goRight');404 }405 }406 else if( left )407 { 408 if(this.facing === 2 ){409 this.walk_velocity = 0;410 this.body.velocity.y = 20; 411 } 412 } 413 else if( right )414 { 415 if(this.facing === 1 ){416 this.walk_velocity = 0;417 this.body.velocity.y = 20; 418 } 419 }420 else{421 422 this.fsm.consumeEvent('fall');423 }424 break;425 case 'idle':426 // reset horizontal velocity427 this.body.velocity.x = 0;428 this.walk_velocity = 110;429 this.jump_increment = 350;430 this.body.gravity.y = 1000;431 // can walk or jump432 if( jump )433 this.fsm.consumeEvent( 'jump' );434 435 else if( left )436 {437 this.facing = Phaser.LEFT;438 this.fsm.consumeEvent( 'left' );439 }440 else if( right )441 {442 this.facing = Phaser.RIGHT;443 this.fsm.consumeEvent( 'right' );444 }445 else if ( openBackpack )446 {447 this.fsm.consumeEvent( 'openBackpack' );448 }449 else if ( openMap )450 {451 this.fsm.consumeEvent( 'openMap' );452 }453 break;454 case 'openBackpack':455 456 this.fsm.consumeEvent( 'closeBackpack' );457 break;458 case 'openMap':459 this.fsm.consumeEvent( 'closeMap' );460 break;461 case 'talking':462 this.fsm.consumeEvent( 'stop' );463 break;464 case 'climbing':465 this.body.gravity.y = 1000;466 467 if( left && up ){468 this.facing = Phaser.LEFT;469 this.body.velocity.x = -300;470 this.fsm.consumeEvent( 'stop' );471 472 break;473 }else if( right && up )474 {475 this.facing = Phaser.RIGHT;476 this.body.velocity.x = 300;477 this.fsm.consumeEvent( 'stop' );478 479 break;480 }else if( up ){481 this.body.velocity.x = 0;482 this.body.gravity.y = 0;483 this.body.velocity.y = -100;484 this.fsm.consumeEvent('climbup');485 break;486 }else if(left){487 this.body.gravity.y = 1000;488 this.fsm.consumeEvent( 'left' );489 }else if(right){490 this.body.gravity.y = 1000;491 this.fsm.consumeEvent( 'right' );492 }493 break;494 case 'challenge':495 if(this.waitTime(this.timer, 400))496 {497 this.fsm.consumeEvent('startstop');498 499 }500 break;501 case 'stunned':502 if(this.waitTime(this.timer, 200))503 {504 this.fsm.consumeEvent('recover');505 }506 break;507 case 'stop':508 if( action )509 {510 $('#text').slideUp(500); 511 this.fsm.consumeEvent('end');512 }513 break;514 default:515 break;516 }517 };518 MyGame.Player.prototype.openBackpack = function()519 {520 var content = "Der Rucksack ist Leer"521 if (this.backpack !== undefined)522 {523 content = '<img src="assets/img/functions/'+this.backpack.picture+'.png" style=""> <br> (weiter mit - Enter -)' 524 }525 $('#text').html(content);526 $('#text').slideDown(500);527 };528 MyGame.Player.prototype.openMap = function()529 {530 var content = '<img src="assets/img/map.png" style="width:100%"> <br> (weiter mit - Enter -)'; 531 $('#text').html(content);532 $('#text').slideDown(500);533 };534 MyGame.Player.prototype.challenge = function()535 {536 this.timer = this.time.now;537 };538 MyGame.Player.prototype.washit = function()539 {540 this.timer = this.time.now;541 }; 542 MyGame.Player.prototype.stop = function()543 {544 this.body.velocity.x = 0;545 };546 MyGame.Player.prototype.hit = function()547 {548 // can't be hit while already stunned549 if( this.fsm.getState() != 'stunned' )550 {551 this.fsm.consumeEvent( 'hit' );552 this.live= this.live -1;553 $('#live').html('Energie: ' + this.live);554 }555 if( this.body.touching.right )556 {557 this.body.velocity.x = -150;558 this.body.touching.right = false;559 }560 else if( this.body.touching.left )561 {562 this.body.velocity.x = 150;563 this.body.touching.left = false;564 }565 if( this.body.touching.down )566 {567 this.body.velocity.y = -350;568 this.body.touching.down = false;569 }570 else if( this.body.touching.up )571 {572 if(this.facing === 1){573 this.body.velocity.x = 300;574 }else{575 this.body.velocity.x = -300;576 }577 this.body.touching.up = false;578 }579 };580 MyGame.Player.prototype.idle = function()581 {582 this.animations.stop();583 this.frame = 36;584 if( this.facing == Phaser.LEFT )585 {586 this.scale.x = -1;587 }588 else589 {590 this.scale.x = 1;591 }592 };593 MyGame.Player.prototype.walking = function()594 {595 if( this.facing == Phaser.LEFT )596 {597 this.walkLeft();598 }599 else600 {601 this.walkRight();602 }603 };604 MyGame.Player.prototype.jumping = function()605 {606 this.jump();607 };608 MyGame.Player.prototype.walljump = function()609 {610 this.animations.stop();611 this.frame = 33;612 }613 MyGame.Player.prototype.falling = function()614 {615 this.frame = 33;616 };617 MyGame.Player.prototype.recovering = function() 618 {619 this.timer = this.time.now;620 this.fsm.consumeEvent( 'recover' );621 };622 MyGame.Player.prototype.stunned = function() 623 {624 // start timer625 this.timer = this.time.now;626 this.frame = 3;627 if( this.facing == Phaser.LEFT )628 {629 this.scale.x = -1;630 }631 else632 {633 this.scale.x = 1;634 }...
queue-tests.js
Source:queue-tests.js
...102 });103 })104 describe('#consumeEvent', function() {105 it('channel consume should be when consumeEvent is called at the first place', function () {106 this.queue.consumeEvent('test-event', () => {});107 this.queue.channel.consume.should.called;108 });109 it('channel consume should be called only once and at the first consumeEvent', function () {110 this.queue.consumeEvent('test-event', () => {});111 this.queue.consumeEvent('test-event2', () => {});112 this.queue.channel.consume.should.calledOnce;113 });114 it('router.register should be called', function () {115 // router is undefined before the first consumeEvent116 // therefore, register method can not be spied.117 this.queue.consumeEvent('test-event', () => {});118 sinon.spy(this.queue.router, 'register');119 this.queue.consumeEvent('test-event2', () => {});120 this.queue.router.register.should.calledOnce;121 });122 })123 describe('#bind', function() {124 it('bindQueue should be called', function () {125 this.queue.bind('exchange', 'pattern');126 this.queue.channel.bindQueue.should.calledWith(this.queue.getUniqueName(), 'exchange', 'pattern');127 this.queue.channel.bindQueue.should.calledOnce;128 });129 })130 describe('#unbind', function() {131 it('unbindQueue should be called', function () {132 this.queue.unbind('exchange', 'pattern');133 this.queue.channel.unbindQueue.should.calledWith(this.queue.getUniqueName(), 'exchange', 'pattern');...
consume-potion.ent.js
Source:consume-potion.ent.js
1/**2 * @fileoverview Stamina Potion Consumption.3 */4const { getProvider, getContractConsumable } = require('../ether');5const { get: getConfig } = require('../configure');6const { delay } = require('../utils/helpers');7const { CONSUMABLE_REV } = require('../constants/addresses.const');8const {9 normalizeChainHero,10} = require('../heroes-fetch/normalise-blockchain.ent');11const log = require('../utils/log.service').get();12/**13 * Stamina Potion Consumption.14 *15 * @param {string} consumableAddress Address of consumable (potion).16 * @param {number|string|bigint} heroId Hero id that will consume.17 * @param {string} privKey Account's private key.18 * @param {string=} optGasPrice Gas price in wei.19 * @param {number=} optRetries Retry count.20 * @return {Promise<Object|void>} A Promise with normalized response of the21 * "ItemConsumed" event.22 */23exports.consumePotion = async (24 consumableAddress,25 heroId,26 privKey,27 optGasPrice,28 optRetries = 0,29) => {30 const signerRpc = await getProvider(privKey);31 try {32 const consumableContract = getContractConsumable(signerRpc);33 const txOpts = {};34 if (optGasPrice) {35 txOpts.gasPrice = optGasPrice;36 }37 const tx = await consumableContract.consumeItem(consumableAddress, heroId);38 const receipt = await exports._getReceipt(tx);39 if (!receipt) {40 return;41 }42 const [consumeEvent] = receipt.events.filter(43 (e) => e.event === 'ItemConsumed',44 );45 const response = exports._normalizeEvent(consumeEvent);46 return response;47 } catch (ex) {48 optRetries += 1;49 const logMessage =50 `Failed consume potion ${consumableAddress}. ` +51 `- retry: ${optRetries} - RPC: ${signerRpc.name} - ` +52 `Hero: ${heroId}`;53 if (optRetries > getConfig('maxRetries')) {54 await log.error(`consumePotion() :: Giving up! ${logMessage}`, {55 error: ex,56 });57 throw ex;58 }59 await log.error(`consumePotion() :: Error. Retry ${optRetries}`, {60 error: ex,61 });62 await delay(optRetries);63 return exports.consumePotion(64 consumableAddress,65 heroId,66 optGasPrice,67 privKey,68 optRetries,69 );70 }71};72/**73 * Will fetch the receipt of the executed transaction, retrying up to a number74 * of times. If all retry attempts fail, function will return empty without75 * throwing.76 *77 * @param {Object} tx Ethers transaction instance,78 * @param {number=} optRetries Retry count.79 * @return {Promise<Object|void>} Receipt or empty if fails.80 * @private81 */82exports._getReceipt = async (tx, optRetries = 0) => {83 try {84 const receipt = await tx.wait();85 return receipt;86 } catch (ex) {87 optRetries += 1;88 if (optRetries > getConfig('maxRetries')) {89 await log.error(`_getReceipt() :: Giving up!`, {90 error: ex,91 custom: {92 tx,93 },94 });95 return;96 }97 await delay(optRetries);98 return exports._getReceipt(tx, optRetries);99 }100};101/**102 * Will normalize the ItemConsumed event.103 *104 * @param {Object} consumeEvent The ItemConsumed event.105 * @return {Object} Normalized event.106 * @private107 */108exports._normalizeEvent = (consumeEvent) => {109 const { player, item, heroId, oldHero, newHero } = consumeEvent.args;110 const oldHeroNormalized = normalizeChainHero(111 oldHero,112 null,113 player,114 'ItemConsumed',115 );116 const newHeroNormalized = normalizeChainHero(117 newHero,118 null,119 player,120 'ItemConsumed',121 );122 const itemLowercase = item.toLowerCase();123 const normalizedResult = {124 playerAddress: player.toLowerCase(),125 itemAddress: itemLowercase,126 itemName: CONSUMABLE_REV[itemLowercase],127 heroId: Number(heroId),128 oldHero: oldHeroNormalized,129 newHero: newHeroNormalized,130 };131 return normalizedResult;...
socket.js
Source:socket.js
...62 }63 /**64 * Consume socket jobs!65 */66 broadcastQueue.consumeEvent('signa.socket.broadcast.update-channel', (data) => {67 console.log("Received channel update: " + JSON.stringify(data));68 }, {noAck: true});69 broadcastQueue.consumeEvent('signa.socket.broadcast.new-app-version', (data) => {70 console.log("Received new app version: " + JSON.stringify(data));71 }, {noAck: true});72 directQueue.consumeEvent('signa.socket.direct.update-device', (data, callback, progress, routingKey) => {73 console.log("Received update device: " + JSON.stringify(data));74 console.log("The routing key of the job was", routingKey);75 callback(null, {some: 'device updated kanka, no worries.'});76 });77 directQueue.consumeEvent('signa.socket.direct.screenshot', (data, callback, progress, routingKey) => {78 console.log("Received update device: " + JSON.stringify(data));79 console.log("The routing key of the job was", routingKey);80 setTimeout(() => {81 let rand = Math.random();82 callback(null, {some: 'screenshot ' + rand});83 console.log("Done screenshot.request " + rand);84 }, 5000);85 });86 })87 .catch((err) => {88 console.log('Cannot boot');89 console.log(err);...
io-controller.js
Source:io-controller.js
1angular.module("kitware.SimPut.core")2 .controller('SimPut.IOController', ['$scope', '$window', '$timeout', function ($scope, $window, $timeout) {3 var dropTarget = document.getElementById('drop-data-model');4 function consumeEvent(event) {5 event.stopPropagation();6 event.preventDefault(); 7 if(event.type == "dragover") {8 dropTarget.classList.add('drag-over');9 } else {10 dropTarget.classList.remove('drag-over');11 }12 13 return false;14 }15 function processFile(event) {16 var files = event.target.files || event.dataTransfer.files,17 reader = new FileReader(),18 updateModel = $scope.updateDataModel;19 // Consume event20 consumeEvent(event);21 // process File22 if(files[0]) {23 reader.onloadend = function (event) {24 updateModel(JSON.parse(reader.result));25 }26 reader.readAsText(files[0]);27 }28 // Remove drop listener29 dropTarget.removeEventListener('dragover', consumeEvent, false);30 dropTarget.removeEventListener('dragenter', consumeEvent, false);31 dropTarget.removeEventListener('drop', processFile, false);32 }33 // File reader - drop file34 dropTarget.addEventListener('dragover', consumeEvent, false);...
state-machine-test.js
Source:state-machine-test.js
...44}45var sm = new StateMachine(states);46sm.getStatus(); // will return 'working'47 48sm.consumeEvent('bored');49sm.getStatus(); // I went for coffee50 51sm.consumeEvent('call_for_meeting');52sm.getStatus(); //will return 'meeting'53 54sm.consumeEvent('bored'); //doesn't matter how boring a meeting can be...55sm.getStatus(); //will still return 'meeting'56 57sm.consumeEvent('meetings_over')...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const [request] = await Promise.all([7 page.waitForEvent('request'),8 page.click('text=Get started'),9 ]);10 console.log(request.url());11 await browser.close();12})();13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 const [request] = await Promise.all([19 page.waitForEvent('request'),20 page.click('text=Get started'),21 ]);22 console.log(request.url());23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 const [request] = await Promise.all([31 page.waitForEvent('request'),32 page.click('text=Get started'),33 ]);34 console.log(request.url());35 await browser.close();36})();37const { chromium } = require('playwright');38(async () => {39 const browser = await chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 const [request] = await Promise.all([43 page.waitForEvent('request'),44 page.click('text=Get started'),45 ]);46 console.log(request.url());47 await browser.close();48})();49const { chromium } = require('playwright');50(async () => {51 const browser = await chromium.launch();52 const context = await browser.newContext();53 const page = await context.newPage();
Using AI Code Generation
1const { consumeEvent } = require("playwright/lib/utils/events");2const { chromium } = require("playwright");3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.waitForLoadState("domcontentloaded");8 await page.click("text=Get started");9 await page.waitForLoadState("domcontentloaded");10 consumeEvent(page, "request", request => console.log(request.url()));11 await page.click("text=Docs");12 await page.waitForLoadState("domcontentloaded");13 await browser.close();14})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.click('text="Sign in"');6 await page.waitForSelector('input[name="identifier"]');7 await page.fill('input[name="identifier"]', 'testuser');8 await page.click('text="Next"');9 await page.waitForSelector('input[name="password"]');10 await page.fill('input[name="password"]', 'testpassword');11 await page.click('text="Next"');12 await page.waitForSelector('text="Search"');13 await browser.close();14})();15const { chromium } = require('playwright');16const { test } = require('@playwright/test');17test('test', async ({ page }) => {18 await page.click('text="Sign in"');19 await page.waitForSelector('input[name="identifier"]');20 await page.fill('input[name="identifier"]', 'testuser');21 await page.click('text="Next"');22 await page.waitForSelector('input[name="password"]');23 await page.fill('input[name="password"]', 'testpassword');24 await page.click('text="Next"');25 await page.waitForSelector('text="Search"');26});
Using AI Code Generation
1const { consumeEvent } = require('playwright/lib/server/events');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const event = await consumeEvent(page, 'framenavigated', () => {8 });9 console.log(event);10 await browser.close();11})();
Using AI Code Generation
1const { consumeEvent } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('input[name="q"]');8 await consumeEvent(page, 'keydown', () => page.keyboard.press('Backspace'));9 await page.screenshot({ path: 'google.png' });10 await browser.close();11})();12const { consumeEvent } = require('playwright/lib/server/supplements/recorder/recorderSupplement');13const { chromium } = require('playwright');14describe('Playwright Test', () => {15 it('Test', async () => {16 const browser = await chromium.launch();17 const context = await browser.newContext();18 const page = await context.newPage();19 await page.click('input[name="q"]');20 await consumeEvent(page, 'keydown', () => page.keyboard.press('Backspace'));21 await page.screenshot({ path: 'google.png' });22 await browser.close();23 });24});
Using AI Code Generation
1const { consumeEvent } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3const fs = require('fs');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 const elementHandle = await page.$('input');9 await elementHandle.focus();10 await elementHandle.type('Hello');11 await elementHandle.press('Enter');12 const event = await consumeEvent(page, 'keydown');13 console.log(event);14 fs.writeFileSync('event.json', JSON.stringify(event));15 await browser.close();16})();17{18}
Using AI Code Generation
1const { consumeEvent } = require('@playwright/test/lib/server/trace/viewer/traceModel');2const { chromium } = require('playwright');3const fs = require('fs');4const path = require('path');5const traceFile = path.join(__dirname, 'trace.json');6const trace = JSON.parse(fs.readFileSync(traceFile, 'utf8'));7const model = consumeEvent(trace);8(async () => {9 const browser = await chromium.launch({ headless: false });10 const context = await browser.newContext();11 const page = await context.newPage();12 for (const event of model.networkRequests()) {13 console.log(event.url);14 }15 await browser.close();16})();
Using AI Code Generation
1const { consumeEvent } = require('playwright/lib/internal/inspectorInstrumentation');2const { Page } = require('playwright/lib/server/page');3const { Frame } = require('playwright/lib/server/frame');4const { ElementHandle } = require('playwright/lib/server/dom');5const { JSHandle } = require('playwright/lib/server/jsHandle');6const { consumeEvent } = require('playwright/lib/internal/inspectorInstrumentation');7const { Page } = require('playwright/lib/server/page');8const { Frame } = require('playwright/lib/server/frame');9const { ElementHandle } = require('playwright/lib/server/dom');10const { JSHandle } = require('playwright/lib/server/jsHandle');11const { consumeEvent } = require('playwright/lib/internal/inspectorInstrumentation');12const { Page } = require('playwright/lib/server/page');13const { Frame } = require('playwright/lib/server/frame');14const { ElementHandle } = require('playwright/lib/server/dom');15const { JSHandle } = require('playwright/lib/server/jsHandle');16const { consumeEvent } = require('playwright/lib/internal/inspectorInstrumentation');17const { Page } = require('playwright/lib/server/page');18const { Frame } = require('playwright/lib/server/frame');19const { ElementHandle } = require('playwright/lib/server/dom');20const { JSHandle } = require('playwright/lib/server/jsHandle');21const { consumeEvent } = require('playwright/lib/internal/inspectorInstrumentation');22const { Page } = require('playwright/lib/server/page');23const { Frame } = require('playwright/lib/server/frame');24const { ElementHandle } = require('playwright/lib/server/dom');25const { JSHandle } = require('playwright/lib/server/jsHandle');26const { consumeEvent } = require('playwright/lib/internal/inspectorInstrumentation');27const { Page } = require('playwright/lib/server/page');28const { Frame } = require('playwright/lib/server/frame');29const { ElementHandle } = require('playwright/lib/server/dom');30const { JSHandle } = require('playwright/lib/server/jsHandle');
Using AI Code Generation
1const { consumeEvent } = require('playwright-core/lib/server/ffConnection.js');2const {connect} = require('playwright-core/lib/server/webkit.js');3const {Page} = require('playwright-core/lib/server/webkit.js');4(async () => {5 const browserServer = await webkit.launchServer({ headless: false });6 const wsEndpoint = browserServer.wsEndpoint();7 const browser = await webkit.connect({ wsEndpoint });8 const context = await browser.newContext();9 const page = await context.newPage();10 await page.click('text="I agree"');11 await page.click('text="Sign in"');12 await page.fill('input[name="identifier"]', '
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!