Best JavaScript code snippet using cypress
Viewing.Extension.CameraTween.js
Source:Viewing.Extension.CameraTween.js
...251 const pos = new THREE.Vector3().copy(252 nav.getPosition())253 const up = new THREE.Vector3().copy(254 nav.getCameraUpVector())255 const targetTween = this.createTween({256 easing: targetTweenEasing.id,257 onUpdate: (v) => {258 nav.setTarget(v)259 },260 duration: immediate ? 0 : targetTweenDuration,261 object: target,262 to: targetEnd263 })264 const posTween = this.createTween({265 easing: posTweenEasing.id,266 onUpdate: (v) => {267 nav.setPosition(v)268 },269 duration: immediate ? 0 : posTweenDuration,270 object: pos,271 to: posEnd272 })273 const upTween = this.createTween({274 easing: upTweenEasing.id,275 onUpdate: (v) => {276 nav.setCameraUpVector(v)277 },278 duration: immediate ? 0 : upTweenDuration,279 object: up,280 to: upEnd281 })282 Promise.all([283 targetTween,284 posTween,285 upTween]).then(() => {286 this.animate = false287 })...
cutscene_manager.js
Source:cutscene_manager.js
...188 //repeat process. -1 is taken as infinite time of repeart (it's a loop then)189 if( actionData.repeat && actionData.repeat < 0)190 actionData.repeat = Number.MAX_VALUE;191 //We can finally create the tween192 this.createTween(newProperties,parsedProp.targetObject,193 actionData.delay,actionData.duration,194 actionData.repeat, actionData.yoyo);195 }196}197/**198* Creates a tween for the targeted object and start it199*/200Phaser.Plugin.CutsceneManager.prototype.createTween = function(_properties,_target,_delay,_duration,_repeat,_yoyo){201 //Create a new tween202 var tween = this.game.add.tween(_target);203 //set propeties to tweeen204 tween.to(_properties,Phaser.Timer.SECOND * _duration);205 //set optional values206 if( _delay != null ) tween.delay( Phaser.Timer.SECOND * _delay ); 207 if( _repeat != null ) tween.repeat(_repeat);208 if( _yoyo != null ) tween.yoyo(_yoyo);209 //tells the tween to call onActionFinished when it's over. If looping, call it now210 if( _repeat != Number.MAX_VALUE)211 tween.onComplete.add( this.onActionFinished, this );212 else213 this.onActionFinished();214 //start the tween215 tween.start();216 return tween;217}218/**219* Calls a function on the _target GameObject220*/221Phaser.Plugin.CutsceneManager.prototype.callFunction = function(_currentAction,_target){222 //console.log("callFunction");223 //if there is a delay before calling the function 224 if( _currentAction.data.delay != null && _currentAction.data.delay > 0){225 //set a timer226 this.game.time.events.add(227 Phaser.Timer.SECOND * _currentAction.data.delay, 228 function(){229 _target.sendMessage(_currentAction.data.functionName, _currentAction.data.args);230 this.onActionFinished();231 },232 this);233 //else just call the function right now234 }else{ 235 _target.sendMessage(_currentAction.data.functionName, _currentAction.data.args);236 this.onActionFinished();237 }238}239/**240* This function returns the target object of the tween property defined by the string241* ie : if string = "body.x"242* the return value will be the body property of the object243* If a property is not found, the object is returned as itself244* example of returned object :245* { targetObject : P2.Body... , property : "x"}246*/247function getPropertyTargetByString( _object, _string){248 var returnObject = { targetObject : _object, property : _string};249 var arrayProp = _string.split('.');250 if(arrayProp.length < 2)251 return returnObject;252 var currentProp = _object;253 for(var i=0; i < arrayProp.length -1; i++){254 if( _object.hasOwnProperty(arrayProp[i])){255 currentProp = currentProp[arrayProp[i]];256 }else{257 return returnObject;258 }259 }260 returnObject.targetObject = currentProp; // the target is the property we found261 returnObject.property = arrayProp[arrayProp.length-1]; // the tweened property is the last in the array262 263 return returnObject;264}265//================================================================266// OTHER FUNCTIONS267//================================================================268/**269* This is an array that can be used to know which functions can be called as "other"270* This will mostly be used by the editor271*/272Phaser.Plugin.CutsceneManager.otherFunctions = [273 "moveCamera", "resetCamera", "cameraFollow",274 "freezeInputAll", "unfreezeInputAll", "freezeInput", "unfreezeInput",275 "changeLevel"276];277Phaser.Plugin.CutsceneManager.prototype.moveCamera = function(_args){278 //process relativeness (?). If a tween is marked as relative, the movement on x & y will be computed from the gameobject's current position279 if( _args.relative != null && _args.relative == true ){280 if( _args.properties.x != null) _args.properties.x += this.game.camera.x;281 if( _args.properties.y != null) _args.properties.y += this.game.camera.y;282 }283 //if a gameobject is targeted284 if( _args.target != null){285 var go = this.game.state.getCurrentState().findGameObjectByName(_args.target);286 if( go ){287 //compute direction from the center of the camera to the entity288 var point = new Phaser.Point();289 _args.properties.x = go.entity.x - this.game.camera.width * 0.5;290 _args.properties.y = go.entity.y - this.game.camera.height * 0.5;291 }else{292 return true;293 }294 }295 //we need to disable following for the tween to work296 this.game.camera.target = null;297 var tweenCam = this.createTween(_args.properties,this.game.camera,_args.delay,_args.duration,_args.repeat,_args.yoyo);298 return false;299}300Phaser.Plugin.CutsceneManager.prototype.cameraFollow = function(_args){301 var go = this.game.state.getCurrentState().findGameObjectByName(_args.target);302 if( go )303 this.game.camera.follow(go.entity);304 return true;305}306Phaser.Plugin.CutsceneManager.prototype.resetCamera = function(_args){307 if( this.cameraData.lastTarget){308 this.game.camera.target = this.cameraData.lastTarget;309 }else{310 this.game.camera.x = this.cameraData.lastX;311 this.game.camera.y = this.cameraData.lastY;...
Animate.js
Source:Animate.js
...150 */151 createTweens : function(elem, props) {152 var tweens = [];153 fastDev.each(props, function(key, value) {154 tweens.push(this.createTween(elem, key, value));155 }, this);156 return tweens;157 },158 /**159 * å建å¨ç»çåºæ¬å±æ§160 * @param {Element} elem å¨ç»å½±åå
ç´ 161 * @param {String} key å±æ§é®162 * @param {String} value å±æ§å¼163 * @private164 */165 createTween : function(elem, key, value) {166 // è·åå½åæ ·å¼å¼167 var currValue = fastDev.Dom.css(elem, key),168 // è·åæ°åå¼ä»¥ååä½...
Grid.js
Source:Grid.js
...166 if (oldCoordinates.x == obj.i && oldCoordinates.y == obj.j && outOfBounds == false && obstruction ==false) {167 this.callbackWrapper()168 } else {169 //start tween170 let tween = this.createTween(fade, obj, newCoordinates, Math.max(Math.abs(x), Math.abs(y)) * 600)171 172 tween.onComplete.add(this.callbackWrapper, this)173 tween.start()174 }175 }176 checkOutOfBounds(endCoordinates) {177 if (endCoordinates.x >= this.tileArray.length)178 return ({ 'x': this.tileArray.length - 1, 'y': endCoordinates.y })179 if (endCoordinates.x < 0)180 return ({ 'x': 0, 'y': endCoordinates.y })181 if (endCoordinates.y >= this.tileArray[endCoordinates.x].length)182 return ({ 'x': endCoordinates.x, 'y': this.tileArray[endCoordinates.x].length - 1 })183 if (endCoordinates.y < 0)184 return ({ 'x': endCoordinates.x, 'y': 0 })...
Tween.js
Source:Tween.js
...40 * @type Object41 */42 this._target = target;43 }44 this.createTween(target, duration, easing);45}46Tween.prototype = Object.create({});47Tween.prototype.constructor = Tween;48module.exports = Tween;49/**50 * The PIXI tween type51 *52 * @static53 * @final54 * @type String55 */56Tween.PIXI_TWEEN = 'PIXI_TWEEN';57/**58 * The CreateJS tween type...
barrage.js
Source:barrage.js
...70 dom,71 item,72 // tween: tw,73 }74 /*let tw = */this.createTween(dom, idx, _dom)75 this.createEvent(dom, item)76 }77 getElement(id) {78 return this._queueIndex[id]79 }80 // å建dom81 createDom(item, idx) {82 let { $parent, template, max } = this._opts,83 domStr = substitute(template, item),84 virtual = document.createElement('div')85 if (!$parent) this.destroy() // parentä¸åå¨åéæ¯ç»ä»¶86 virtual.innerHTML = domStr87 let dom = virtual.firstElementChild,88 top = random() * max >> 0...
animator.js
Source:animator.js
1// animator.js: Demo animator controller2// Scott Schiller | schillmania.com | May 20093// -------------------------------------------4// Provided free, "as-is", for any use. No warranty or support.5// http://www.schillmania.com/projects/javascript-animation-3/67writeDebug = (typeof console != 'undefined' && console.log && window.location.href.match(/debug=1/i))?function(sDebug) {8 // use #debug=1 etc. in URL to enable debug output for console.log()-supported shiz9 console.log(sDebug);10}:function() {11 // oh well12}1314function Animator() {15 var self = this;16 var intervalRate = 20;17 this.tweenTypes = {18 'default': [1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1],19 'blast': [12,12,11,10,10,9,8,7,6,5,4,3,2,1],20 'linear': [10,10,10,10,10,10,10,10,10,10]21 }22 this.queue = [];23 this.queueHash = [];24 this.active = false;25 this.timer = null;26 this.createTween = function(start,end,type) {27 // return array of tween coordinate data (start->end)28 type = type||'default';29 var tween = [start];30 var tmp = start;31 var diff = end-start;32 var x = self.tweenTypes[type].length;33 for (var i=0; i<x; i++) {34 tmp += diff*self.tweenTypes[type][i]*0.01;35 tween[i] = {};36 tween[i].data = tmp;37 tween[i].event = null;38 }39 return tween;40 }4142 this.enqueue = function(o,fMethod,fOnComplete) {43 // add object and associated methods to animation queue44 writeDebug('animator.enqueue()');45 if (!fMethod) {46 writeDebug('animator.enqueue(): missing fMethod');47 }4849 self.queue.push(o);50 o.active = true;51 }5253 this.animate = function() {54 var active = 0;55 for (var i=0,j=self.queue.length; i<j; i++) {56 if (self.queue[i].active) {57 self.queue[i].animate();58 active++;59 }60 }61 if (active == 0 && self.timer) {62 // all animations finished63 writeDebug('Animations complete');64 self.stop();65 } else {66 // writeDebug(active+' active');67 }68 }6970 this.start = function() {71 if (self.timer || self.active) {72 writeDebug('animator.start(): already active');73 return false;74 }75 writeDebug('animator.start()'); // report only if started76 self.active = true;77 self.timer = setInterval(self.animate,intervalRate);78 }7980 this.stop = function() {81 writeDebug('animator.stop()',true);82 // reset some things, clear for next batch of animations83 clearInterval(self.timer);84 self.timer = null;85 self.active = false;86 self.queue = [];87 }8889}9091var animator = new Animator();9293function Animation(oParams) {94 // unique animation object95 /*96 oParams = {97 from: 200,98 to: 300,99 tweenType: 'default',100 ontween: function(value) { ... }, // method called each time101 oncomplete: function() { ... } // when finished102 }103 */104 var self = this;105 if (typeof oParams.tweenType == 'undefined') {106 oParams.tweenType = 'default';107 }108 this.ontween = (oParams.ontween||null);109 this.oncomplete = (oParams.oncomplete||null);110 this.tween = animator.createTween(oParams.from,oParams.to,oParams.tweenType);111 this.frameCount = animator.tweenTypes[oParams.tweenType].length;112 this.frame = 0;113 this.active = false;114115 this.animate = function() {116 // generic animation method117 if (self.active) {118 if (self.ontween && self.tween[self.frame]) {119 self.ontween(self.tween[self.frame].data);120 }121 if (self.frame++ >= self.frameCount-1) {122 writeDebug('animation(): end');123 self.active = false;124 self.frame = 0;125 if (self.oncomplete) {126 self.oncomplete();127 // self.oncomplete = null;128 }129 return false;130 }131 return true;132 }133 return false;134 }135136 this.start = function() {137 // add this to the main animation queue138 animator.enqueue(self,self.animate,self.oncomplete);139 if (!animator.active) {140 animator.start();141 }142 }143144 this.stop = function() {145 self.active = false;146 }147
...
index.js
Source:index.js
...53 var delay = this._delay || 0;54 setTimeout(function() {55 if (this._css) this._css();56 this.map.forEach(function(obj) {57 var tween = this.createTween(obj.el, obj.props, callback);58 tweens.push(tween);59 }.bind(this));60 animate = function () {61 raf(animate);62 tweens.forEach(function(tween) {63 tween.update();64 })65 }66 animate();67 }.bind(this), delay);68 var called = false;69 var self = this;70 function callback() {71 if (called) return;...
Using AI Code Generation
1describe('Cypress', () => {2 it('Cypress', () => {3 cy.get('input[type="text"]').type('Hello world')4 cy.get('input[type="text"]').should('have.value', 'Hello world')5 })6})7describe('Cypress', () => {8 it('Cypress', () => {9 cy.get('input[type="text"]').type('Hello world')10 cy.get('input[type="text"]').should('have.value', 'Hello world')11 })12})13describe('Cypress', () => {14 it('Cypress', () => {15 cy.get('input[type="text"]').type('Hello world')16 cy.get('input[type="text"]').should('have.value', 'Hello world')17 })18})19describe('Cypress', () => {20 it('Cypress', () => {21 cy.get('input[type="text"]').type('Hello world')22 cy.get('input[type="text"]').should('have.value', 'Hello world')23 })24})25describe('Cypress', () => {26 it('Cypress', () => {27 cy.get('input[type="text"]').type('Hello world')28 cy.get('input[type="text"]').should('have.value', 'Hello world')29 })30})31describe('Cypress', () => {32 it('Cypress', () => {33 cy.get('input[type="text"]').type('Hello world')34 cy.get('input[type="text"]').should('have.value', 'Hello world')35 })36})37describe('Cypress', () => {38 it('Cypress', () => {39 cy.get('input[type="text"]').type('Hello world')40 cy.get('input[type="text"]').should('have.value', 'Hello world')41 })
Using AI Code Generation
1describe('Cypress', () => {2 it('createTween', () => {3 cy.get('.action-btn').click()4 cy.get('.action-input-hidden').should('not.be.visible')5 cy.get('.action-input-hidden').invoke('show').should('be.visible')6 cy.get('.action-input-hidden').invoke('val', 'test')7 cy.get('.action-btn').click()8 cy.get('.action-input-hidden').invoke('val').should('equal', 'test')9 cy.get('.action-input-hidden').invoke('hide').should('not.be.visible')10 cy.get('.action-input-hidden').should('not.be.visible')11 cy.get('.action-input-hidden').invoke('show').should('be.visible')12 cy.get('.action-input-hidden').invoke('val', 'test')13 cy.get('.action-btn').click()14 cy.get('.action-input-hidden').invoke('val').should('equal', 'test')15 })16})17describe('Actions', () => {18 beforeEach(() => {19 })20 it('.type() - type into a DOM element', () => {21 cy.get('.action-email')22 .type('
Using AI Code Generation
1cy.get("#myElement").then(($el) => {2 const tween = Cypress.Tween.get($el, { duration: 1000 });3 tween.to({ width: "200px" }).to({ height: "200px" });4 tween.wait(2000);5 tween.to({ width: "100px" }).to({ height: "100px" });6});7cy.get("#myElement").then(($el) => {8 const tween = Cypress.Tween.get($el, { duration: 1000 });9 tween.to({ width: "200px" });10 tween.to({ height: "200px" });11 tween.wait(2000);12 tween.to({ width: "100px" });13 tween.to({ height: "100px" });14});15cy.get("#myElement").then(($el) => {16 const tween = Cypress.Tween.get($el, { duration: 1000 });17 tween.to({ width: "200px" }).to({ height: "200px" });18 tween.wait(2000);19 tween.to({ width: "100px" }).to({ height: "100px" });20});21cy.get("#myElement").then(($el) => {22 const tween = Cypress.Tween.get($el, { duration: 1000 });23 tween.to({ width: "200px" });24 tween.to({ height: "200px" });25 tween.wait(2000);26 tween.to({ width: "100px" });27 tween.to({ height: "100px" });28});29cy.get("#myElement").then(($el) => {30 const tween = Cypress.Tween.get($el, { duration: 1000 });31 tween.to({ width: "200px" });32 tween.to({ height: "200px" });33 tween.wait(2000);34 tween.to({ width: "100px" });35 tween.to({ height: "100px" });36});37cy.get("#myElement").then(($el) => {
Using AI Code Generation
1it('test', () => {2 cy.get('body').then($body => {3 cy.wrap($body).trigger('mousemove', { pageX: 10, pageY: 10 })4 cy.wrap($body).trigger('mousemove', { pageX: 20, pageY: 20 })5 cy.wrap($body).trigger('mousemove', { pageX: 30, pageY: 30 })6 cy.wrap($body).trigger('mousemove', { pageX: 40, pageY: 40 })7 cy.wrap($body).trigger('mousemove', { pageX: 50, pageY: 50 })8 cy.wrap($body).trigger('mousemove', { pageX: 60, pageY: 60 })9 cy.wrap($body).trigger('mousemove', { pageX: 70, pageY: 70 })10 cy.wrap($body).trigger('mousemove', { pageX: 80, pageY: 80 })11 cy.wrap($body).trigger('mousemove', { pageX: 90, pageY: 90 })12 cy.wrap($body).trigger('mousemove', { pageX: 100, pageY: 100 })13 cy.wrap($body).trigger('mousemove', { pageX: 110, pageY: 110 })14 cy.wrap($body).trigger('mousemove', { pageX: 120, pageY: 120 })15 cy.wrap($body).trigger('mousemove', { pageX: 130, pageY: 130 })16 cy.wrap($body).trigger('mousemove', { pageX: 140, pageY: 140 })17 cy.wrap($body).trigger('mousemove', { pageX: 150, pageY: 150 })18 cy.wrap($body).trigger('mousemove', { pageX: 160, pageY: 160 })19 cy.wrap($body).trigger('mousemove', { pageX: 170, pageY: 170 })20 cy.wrap($body).trigger('mousemove', { pageX: 180, pageY: 180 })21 cy.wrap($body).trigger('mousemove', { pageX: 190, pageY: 190 })22 cy.wrap($body).trigger('mousemove', { pageX: 200, pageY: 200 })23 cy.wrap($body).trigger('mousemove', { page
Using AI Code Generation
1it('test', () => {2 cy.get('#selector').then(($el) => {3 const tween = Cypress.Tween.get($el, { duration: 2000 })4 .to('width', '100px')5 .to('height', '100px')6 .to('background-color', 'green')7 .to('color', 'white')8 .to('font-size', '20px')9 .to('border', '2px solid black')10 .to('opacity', 0.5)11 .to('border-radius', '5px');12 tween.pause();13 tween.resume();14 tween.stop();15 });16});17describe('test', () => {18 it('test', () => {19 cy.get('#selector').then(($el) => {20 const tween = Cypress.Tween.get($el, { duration: 2000 })21 .to('width', '100px')22 .to('height', '100px')23 .to('background-color', 'green')24 .to('color', 'white')25 .to('font-size', '20px')26 .to('border', '2px solid black')27 .to('opacity', 0.5)28 .to('border-radius', '5px');29 tween.pause();30 tween.resume();31 tween.stop();32 });33 });34});35it('test', () => {36 cy.get('.selector').then(($el) => {37 const tween = Cypress.Tween.get($el, { duration: 2000 })38 .to('width', '100px')39 .to('height', '100px')40 .to('background-color', 'green')41 .to('color', 'white')42 .to('font-size', '20px')43 .to('border', '2px solid black')44 .to('opacity', 0.5)45 .to('border-radius', '5px');46 tween.pause();47 tween.resume();48 tween.stop();49 });50});
Using AI Code Generation
1Cypress.Commands.add('createTween', (tweenName, tweenType, tweenValue) => {2 cy.get('#create-tween').click()3 cy.get('#tween-name').type(tweenName)4 cy.get('#tween-type').select(tweenType)5 cy.get('#tween-value').type(tweenValue)6 cy.get('#create-tween-btn').click()7})8Cypress.Commands.add('createTween', (tweenName, tweenType, tweenValue) => {9 cy.get('#create-tween').click()10 cy.get('#tween-name').type(tweenName)11 cy.get('#tween-type').select(tweenType)12 cy.get('#tween-value').type(tweenValue)13 cy.get('#create-tween-btn').click()14})15Cypress.Commands.add('createTween', (tweenName, tweenType, tweenValue) => {16 cy.get('#create-tween').click()17 cy.get('#tween-name').type(tweenName)18 cy.get('#tween-type').select(tweenType)19 cy.get('#tween-value').type(tweenValue)20 cy.get('#create-tween-btn').click()21})22Cypress.Commands.add('createTween', (tweenName, tweenType, tweenValue) => {23 cy.get('#create-tween').click()24 cy.get('#tween-name').type(tweenName)25 cy.get('#tween-type').select(tweenType)26 cy.get('#tween-value').type(tweenValue)27 cy.get('#create-tween-btn').click()28})29Cypress.Commands.add('createTween', (tweenName, tweenType, tweenValue) => {30 cy.get('#create-tween').click()31 cy.get('#tween-name').type(tweenName)32 cy.get('#
Using AI Code Generation
1const createTween = (subject, options) => {2 return new Cypress.Promise((resolve, reject) => {3 const tween = new TWEEN.Tween(subject, options)4 tween.onComplete(() => resolve(subject))5 tween.onError(reject)6 tween.start()7 })8}9Cypress.Commands.add('createTween', createTween)10describe('test', () => {11 it('test', () => {12 cy.createTween({ x: 0 }, { to: { x: 100 }, duration: 1000 })13 .should('have.property', 'x', 100)14 })15})16describe('test', () => {17 it('test', () => {18 cy.createTween({ x: 0 }, { to: { x: 100 }, duration: 1000 })19 .should('have.property', 'x', 100)20 })21})22describe('test', () => {23 it('test', () => {24 cy.createTween({ x: 0 }, { to: { x: 100 }, duration: 1000 })25 .should('have.property', 'x', 100)26 })27})28describe('test', () => {29 it('test', () => {30 cy.createTween({ x: 0 }, { to: { x: 100 }, duration: 1000 })31 .should('have.property', 'x', 100)32 })33})34describe('test', () => {35 it('test', () => {36 cy.createTween({ x: 0 }, { to: { x: 100 }, duration: 1000 })37 .should('have.property', 'x', 100)38 })39})40describe('test', () => {41 it('test', () => {42 cy.createTween({ x: 0 }, { to: { x:
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!