Best JavaScript code snippet using cypress
window.js
Source:window.js
...566 *567 * @this {HfosWindow}568 */569 _minimizeInternal: function(){570 var dimensions = this._windowManager.getDimensionsFor('minimized', this);571 this._element.hide();572 this._element.setOpacity(1.0);573 this._resizeTo(dimensions.width, dimensions.height);574 this._windowManager.setFirstNormalToActive();575 this.fire('onInactive');576 },577 /**578 * Restaura una ventana cuando está minimizada579 *580 * @this {HfosWindow}581 */582 restoreWindow: function(){583 var dimensions = this._windowManager.getDimensionsFor('normal', this);584 this._element.setStyle({585 top: dimensions.top,586 left: dimensions.left,587 width: dimensions.width,588 height: dimensions.height589 });590 this.show();591 this._relocateElements();592 //Colocar ventana como activa en el stack593 this._windowManager.setActiveWindow(this);594 },595 /**596 * Maximiza la ventana597 *598 * @this {HfosWindow}599 */600 maximize: function(){601 this._maximizeWindow();602 },603 /**604 * Maximiza la ventana (internal)605 *606 * @this {HfosWindow}607 */608 _maximizeWindow: function(){609 var dimensions;610 if(this._status=='normal'){611 dimensions = this._windowManager.getDimensionsFor('maximized', this);612 } else {613 dimensions = this._windowManager.getDimensionsFor('normal', this);614 };615 new Hfos.getAnimation().morph(this._element, {616 duration: 0.2,617 style: {618 top: dimensions.top,619 left: dimensions.left,620 width: dimensions.width,621 height: dimensions.height622 },623 afterFinish: function(){624 this._relocateElements();625 this._onResize();626 this._storePosition();627 }.bind(this)...
dom.js
Source:dom.js
...77 }78 break79 default:80 obj = {81 width: getDimensionsFor(dimensions, attr, 'width'),82 height: getDimensionsFor(dimensions, attr, 'height'),83 top: dimensions.offset.top,84 left: dimensions.offset.left,85 }86 }87 // if attr is margin then we need to additional88 // subtract what the actual marginTop + marginLeft89 // values are, since offset disregards margin completely90 if (attr === 'Margin') {91 obj.top -= dimensions.marginTop92 obj.left -= dimensions.marginLeft93 }94 // bail if the dimensions of this layer match the previous one95 // so we dont create unnecessary layers96 if (dimensionsMatchPreviousLayer(obj, container)) return...
manager.js
Source:manager.js
1/**2 * Hotel Front-Office Solution3 *4 * LICENSE5 *6 * This source file is subject to license that is bundled7 * with this package in the file docs/LICENSE.txt.8 *9 * @package Back-Office10 * @copyright BH-TECK Inc. 2009-201011 * @version $Id$12 */13/**14 * HfosWindowManager15 *16 * Administrador de Ventanas17 */18var HfosWindowManager = Class.create({19 //Referencia al Workspace20 _workspace: null,21 //Coordenadas originales de las ventanas22 _originalState: {},23 //Elemento DOM del space24 _spaceElement: null,25 //Todas las ventanas registradas26 _windows: {},27 //Referencia a la ventana modal dentro del workspace28 _modalWindow: null,29 //Número de ventanas registradas30 _numberWindows: 0,31 //Eventos para las ventanas con enlazamiento tardÃo32 _lateBindings: {},33 //Establece la posición de las ventanas en la cascada34 _windowOrder: [],35 _offsetTop: 0,36 _offsetLeft: 0,37 /**38 * @constructor39 */40 initialize: function(workspace){41 this._offsetTop = 0;42 this._offsetLeft = 0;43 this._workspace = workspace;44 },45 /**46 * Función interna para activar una ventana47 *48 * @this {HfosWindowManager}49 */50 _setActiveInternal: function(selectedWindow){51 if(selectedWindow.isActive()==false){52 var position = 0;53 this._windowOrder = [];54 $H(this._windows).each(function(_window){55 if(_window[1]!=selectedWindow){56 _window[1].setInactive(position);57 this._windowOrder.push(_window[1].getId());58 };59 position++;60 }.bind(this));61 this._windowOrder.push(selectedWindow.getId());62 selectedWindow.setActive(position);63 };64 switch(selectedWindow.getStatus()){65 case 'minimized':66 selectedWindow.restoreWindow();67 break;68 };69 },70 /**71 * Establece una ventana como activa72 *73 * @this {HfosWindowManager}74 */75 setActiveWindow: function(selectedWindow, withEffect){76 if(typeof withEffect == "undefined"){77 withEffect = false;78 };79 if(withEffect==false){80 this._setActiveInternal(selectedWindow);81 } else {82 var leftSignal = 1;83 var activeWindow = this.getActiveWindow();84 if(activeWindow!==null){85 if(activeWindow.getWindowElement().offsetLeft>selectedWindow.getWindowElement().offsetLeft){86 leftSignal = -1;87 };88 new Effect.Move(selectedWindow.getWindowElement(), {89 x: leftSignal*20,90 duration: 0.2,91 afterFinish: function(selectedWindow, leftSignal){92 this._setActiveInternal(selectedWindow);93 new Effect.Move(selectedWindow.getWindowElement(), {94 x: 20*-leftSignal,95 duration: 0.296 });97 }.bind(this, selectedWindow, leftSignal)98 });99 };100 };101 this._workspace.getTaskbar().setActive(selectedWindow);102 },103 /**104 * Registra una ventana en modo modal105 *106 * @this {HfosWindowManager}107 */108 setModalWindow: function(modalWindow, onSuccess){109 if(this._modalWindow===null){110 this._modalWindow = modalWindow;111 onSuccess();112 } else {113 new HfosModal.alert({114 title: Hfos.getApplication().getName(),115 message: 'Ya hay otra ventana modal abierta'116 });117 }118 },119 /**120 * Indica si hay una ventana en modo modal121 *122 * @this {HfosWindowManager}123 */124 hasModalWindow: function(){125 return this._modalWindow!==null;126 },127 /**128 * Quita la ventana modal activa129 *130 * @this {HfosWindowManager}131 */132 removeModalWindow: function(){133 delete this._modalWindow;134 this._modalWindow = null;135 },136 /**137 * Devuelve la ventana activa en el window manager138 *139 * @this {HfosWindowManager}140 */141 getActiveWindow: function(){142 if(this._modalWindow===null){143 var selectedWindow = null;144 $H(this._windows).each(function(_window){145 if(_window[1].isActive()){146 selectedWindow = _window[1];147 }148 });149 return selectedWindow;150 } else {151 return this._modalWindow;152 }153 },154 /**155 * Crea una nueva ventana156 *157 * @this {HfosWindowManager}158 */159 create: function(options){160 if(this.exists(options)==false){161 this._numberWindows++;162 return this._addWindow(options);163 } else {164 this.setActiveWindow(this.getWindow(options.id), true);165 return false;166 }167 },168 /**169 * Crea una nueva ventana170 *171 * @this {HfosWindowManager}172 */173 createAndRun: function(options){174 if(this.exists(options)==false){175 if(typeof options.onStartup != "undefined"){176 if(typeof options.bindings == "undefined"){177 options.bindings = { };178 };179 options.bindings.onReady = options.onStartup;180 };181 this._numberWindows++;182 return this._addWindow(options);183 } else {184 var _window = this.getWindow(options.id);185 this.setActiveWindow(_window, false);186 if(typeof options.onStartup != "undefined"){187 options.onStartup(_window);188 };189 return false;190 }191 },192 /**193 * Agrega una ventana al windowManager194 *195 * @this {HfosWindowManager}196 */197 _addWindow: function(options){198 //Registra la ventana en el WindowManager199 this._windows[options.id] = new HfosWindow(this, options);200 //Agregar botón en barra de tareas201 this._workspace.getTaskbar().add(options);202 //Colocar la ventana como activa203 this.setActiveWindow(this._windows[options.id]);204 this._offsetTop+=10;205 this._offsetLeft+=10;206 return this._windows[options.id];207 },208 /**209 * Desregistra una ventana al cerrarse210 *211 * @this {HfosWindowManager}212 */213 _closedWindow: function(hfosWindow){214 this._workspace.getTaskbar().remove(hfosWindow);215 delete this._windows[hfosWindow.getId()];216 if(typeof this._originalState[hfosWindow.getId()] != "undefined"){217 delete this._originalState[hfosWindow.getId()];218 }219 this._numberWindows--;220 this._offsetTop = (this._numberWindows*10);221 this._offsetLeft = (this._numberWindows*10);222 if(this._numberWindows>0){223 this.setFirstNormalToActive();224 }225 },226 /**227 * Consulta si una ventana existe228 *229 * @this {HfosWindowManager}230 */231 exists: function(options){232 if(typeof this._windows[options.id] == "undefined"){233 return false;234 } else {235 return true;236 }237 },238 /**239 * Obtiene un objeto de ventana apartir de su ID240 *241 * @this {HfosWindowManager}242 */243 getWindow: function(windowId){244 if(typeof this._windows[windowId] != "undefined"){245 return this._windows[windowId];246 } else {247 return null;248 }249 },250 /**251 * Obtiene todas las ventanas disponibles en el window manager252 *253 * @this {HfosWindowManager}254 */255 getWindows: function(){256 return this._windows;257 },258 /**259 * Almacena las dimensiones originales de la ventana cuando su estado es = normal260 *261 * @this {HfosWindowManager}262 */263 getDimensionsFor: function(status, hfosWindow){264 var dimensions = {};265 switch(status){266 case 'normal':267 if(typeof this._originalState[hfosWindow.getId()] != "undefined"){268 var originalState = this._originalState[hfosWindow.getId()];269 delete this._originalState[hfosWindow.getId()];270 dimensions.left = originalState.left;271 dimensions.top = originalState.top;272 dimensions.width = originalState.width;273 dimensions.height = originalState.height;274 };275 break;276 case 'maximized':277 var windowScroll = WindowUtilities.getWindowScroll(this._spaceElement);278 var pageSize = WindowUtilities.getPageSize(this._spaceElement);279 this._originalState[hfosWindow.getId()] = hfosWindow.getDimensions();280 dimensions.width = (pageSize.windowWidth-windowScroll.left-20)+"px";281 dimensions.height = (pageSize.windowHeight-windowScroll.top-50)+"px";282 dimensions.left = '10px';283 dimensions.top = '10px';284 break;285 case 'minimized':286 this._originalState[hfosWindow.getId()] = hfosWindow.getDimensions();287 dimensions.width = "680px";288 dimensions.height = "400px";289 break;290 };291 hfosWindow.setStatus(status);292 return dimensions;293 },294 /**295 * Coloca la primera ventana no-minimizada como activa296 *297 * @this {HfosWindowManager}298 */299 setFirstNormalToActive: function(){300 this._workspace.getTaskbar().setNoneActive();301 for(var i=this._windowOrder.length-1;i>=0;i--){302 var _window = this.getWindow(this._windowOrder[i]);303 if(_window!==null){304 if(_window.getStatus()!='minimized'){305 this.setActiveWindow(_window);306 break;307 }308 };309 };310 },311 /**312 * Cierra la ventana activa actualmente313 *314 * @this {HfosWindowManager}315 */316 closeActiveWindow: function(){317 if(this._modalWindow===null){318 $H(this._windows).each(function(_window){319 if(_window[1].isActive()){320 _window[1].close();321 }322 });323 } else {324 this._modalWindow.close();325 }326 },327 /**328 * Establece el elemento $('space') donde se agregan las ventanas329 *330 * @this {HfosWindowManager}331 */332 setSpaceElement: function(spaceElement){333 this._spaceElement = spaceElement;334 },335 /**336 * Establece el elemento $('space') donde se agregan las ventanas337 *338 * @this {HfosWindowManager}339 */340 getSpaceElement: function(){341 return this._spaceElement;342 },343 /**344 * Devuelve el número de ventanas activas en el WindowManager345 *346 * @this {HfosWindowManager}347 */348 getNumberWindows: function(){349 if(this._modalWindow===null){350 return this._numberWindows;351 } else {352 return this._numberWindows+1;353 }354 },355 /**356 * Obtiene el espacio adicional en "y" que se debe agregar al crear una ventana357 *358 * @this {HfosWindowManager}359 */360 getOffsetTop: function(){361 return this._offsetTop;362 },363 /**364 * Obtiene el espacio adicional en "x" que se debe agregar al crear una ventana365 *366 * @this {HfosWindowManager}367 */368 getOffsetLeft: function(){369 return this._offsetLeft;370 },371 /**372 * Devuelve la referencia a HfosWorkspace373 *374 * @this {HfosWindowManager}375 */376 getWorkspace: function(){377 return this._workspace;378 },379 /**380 * Consulta los elementos DOM que estén bajo el workspace381 *382 * @this {HfosWindowManager}383 */384 select: function(selector){385 return this._spaceElement.select(selector);386 },387 /**388 * Duerme el administrador de ventanas389 *390 * @this {HfosWindowManager}391 */392 sleep: function(){393 this._spaceElement.hide();394 },395 /**396 * Despierta el administrador de ventanas397 *398 * @this {HfosWindowManager}399 */400 wakeup: function(){401 this._spaceElement.show();402 this.setFirstNormalToActive();403 },404 /**405 * Suspende el administrador de ventanas406 *407 * @this {HfosWindowManager}408 */409 hibernate: function(){410 var windows = $H(this._windows);411 windows.each(function(_window){412 _window[1].hibernate();413 });414 this._interval = window.setInterval(function(windows){415 var hibernatedComplete = true;416 windows.each(function(_window){417 if(_window[1].getStatus()!='hibernate'){418 hibernatedComplete = false;419 }420 });421 if(hibernatedComplete){422 window.clearInterval(this._interval);423 this._workspace.notify('hibernateCompleted');424 }425 }.bind(this, windows), 200);426 },427 /**428 * Notifica al administrador de ventanas sobre un evento ocurrido en alguna ventana429 *430 * @this {HfosWindowManager}431 */432 notify: function(eventName, eventWindow){433 switch(eventName){434 case 'closed':435 this._closedWindow(eventWindow);436 break;437 }438 },439 /**440 * Agrega un evento a una ventana con enlazamiento tardÃo441 *442 * @this {HfosWindowManager}443 */444 lateBinding: function(windowId, eventName, procedure){445 HfosBindings.late(windowId, eventName, procedure);446 },447 /**448 * Devuelve los eventos de enlazamiento tardÃo de las ventanas449 *450 * @this {HfosWindowManager}451 */452 getLateBindings: function(windowId){453 return HfosBindings.get(windowId);454 }...
custom.js
Source:custom.js
...19 Blockly.cake.definitions_['include_kukadu_string'] = "#include <kukadu/robot.hpp>\n#include <kukadu/control.hpp>\n#include <kukadu/manipulation/skillfactory.hpp>\n#include <kukadu/manipulation/playing/controllers.hpp>";20 Blockly.cake.definitions_['include_PoseEstimatorFactory_string'] = "#include <kukadu/vision/poseestimatorfactory.hpp>\n";21 var variableName = block.getFieldValue("VariableName");22 var objectName = block.getFieldValue("ObjectType");23 return "auto " + variableName + " = kukadu::PoseEstimatorFactory::get().getDimensionsFor(\"" + objectName + "\");\n";24};25Blockly.cake['skillloader'] = function (block) {26 Blockly.cake.definitions_['include_kukadu_string'] = "#include <kukadu/robot.hpp>\n#include <kukadu/control.hpp>\n#include <kukadu/manipulation/skillfactory.hpp>\n#include <kukadu/manipulation/playing/controllers.hpp>";27 var hardwareSelection = Blockly.cake.valueToCode(block, 'HARDWARE', Blockly.cake.ORDER_ATOMIC);28 var splitHardware = hardwareSelection.split(", ");29 for (var i = 0; i < splitHardware.length; i++) {30 Blockly.cake.neededHardware_[splitHardware[i]] = "auto " + splitHardware[i] + " = hardwareFactory.loadHardware(\"" + splitHardware[i] + "\");\n";31 }32 var hardwareCode = "";33 var hardwareVariableNames = [];34 for (var i = 0; i < splitHardware.length; i++) {35 var hardwareVariableName = "sLeftQueue" + skillCounter + i;36 //hardwareCode += "auto " + hardwareVariableName + " = hardwareFactory.loadHardware(\"" + splitHardware[i] + "\");\n" +37 hardwareCode += "auto " + hardwareVariableName + " = getUsedHardware().at(" + getKeyIdForValueFromMap(Blockly.cake.neededHardware_, splitHardware[i]) + ");\n" +...
Using AI Code Generation
1Cypress.$(window).getDimensionsFor('width');2jQuery(window).getDimensionsFor('width');3$.getDimensionsFor('width');4$(window).getDimensionsFor('width');5jQuery.getDimensionsFor('width');6$(document).getDimensionsFor('width');7jQuery(document).getDimensionsFor('width');8$(document.body).getDimensionsFor('width');9jQuery(document.body).getDimensionsFor('width');10$(window).getDimensionsFor('height');11jQuery(window).getDimensionsFor('height');12$.getDimensionsFor('height');13$(window).getDimensionsFor('height');14jQuery.getDimensionsFor('height');15$(document).getDimensionsFor('height');16jQuery(document).getDimensionsFor('height');17$(document.body).getDimensionsFor('height');18jQuery(document.body).getDimensionsFor('height');19$(window).getDimensionsFor('width');20jQuery(window).getDimensions
Using AI Code Generation
1const dimensions = Cypress.dom.getDimensionsFor(element)2const dimensions = Cypress.dom.getDimensions(element)3const outerHeight = Cypress.dom.getOuterHeight(element)4const outerWidth = Cypress.dom.getOuterWidth(element)5const scrollHeight = Cypress.dom.getScrollHeight(element)6const scrollLeft = Cypress.dom.getScrollLeft(element)7const scrollTop = Cypress.dom.getScrollTop(element)8const scrollWidth = Cypress.dom.getScrollWidth(element)9const style = Cypress.dom.getStyle(element, prop)10const styles = Cypress.dom.getStyles(element, props)11const viewportHeight = Cypress.dom.getViewportHeight()12const viewportWidth = Cypress.dom.getViewportWidth()13const isAttached = Cypress.dom.isAttached(element)
Using AI Code Generation
1Cypress.Blob.getDimensionsFor(file).then((dimensions) => {2 console.log(dimensions.width, dimensions.height)3})4import getDimensionsFor from 'get-image-dimensions'5Cypress.Blob.getDimensionsFor = (file) => {6 return new Promise((resolve, reject) => {7 getDimensionsFor(file, (err, dimensions) => {8 if (err) {9 return reject(err)10 }11 return resolve(dimensions)12 })13 })14}15Cypress.Commands.add('getDimensionsFor', { prevSubject: true }, (subject) => {16 return Cypress.Blob.getDimensionsFor(subject)17})18describe('test', () => {19 it('test', () => {20 cy.get('img').getDimensionsFor().should('have.property', 'width', 100)21 })22})23Cypress.Blob.getDimensionsFor(file).then((dimensions) => {24 console.log(dimensions.width, dimensions.height)25})26Cypress.Blob.getDimensionsFor(file).then((dimensions) => {27 console.log(dimensions.width, dimensions.height)28})
Using AI Code Generation
1const dimensions = Cypress.dom.getDimensionsFor('.some-class');2console.log(dimensions);3Cypress.Commands.add('getDimensionsFor', (selector, options) => {4 return Cypress.dom.getDimensionsFor(selector, options);5});6describe('Test', () => {7 it('Test', () => {8 cy.getDimensionsFor('.some-class').should((dimensions) => {9 expect(dimensions).to.have.property('height', 20);10 });11 });12});
Using AI Code Generation
1describe('test', function() {2 it('test', function() {3 cy.get('iframe').then($iframe => {4 const iframe = $iframe.contents()5 const iframeBody = iframe.find('body')6 cy.log(height)7 cy.log(width)8 })9 })10})11Cypress.Commands.add('getDimensionsFor', (selector, callback) => {12 return cy.get(selector).then($iframe => {13 const iframe = $iframe.contents()14 const iframeBody = iframe.find('body')15 callback(height, width)16 })17})18describe('test', function() {19 it('test', function() {20 cy.getDimensionsFor('iframe', (height, width) => {21 cy.log(height)22 cy.log(width)23 })24 })25})
Using AI Code Generation
1describe('Cypress getDimensionsFor', () => {2 it('should get the dimensions of the element', () => {3 cy.get('#email1').then(($el) => {4 cy.getDimensionsFor($el).then((dimensions) => {5 console.log(dimensions)6 })7 })8 })9})10Cypress.Commands.add('getDimensionsFor', (element) => {11 return cy.window().then((win) => {12 const { top, left, width, height } = win.document13 .querySelector(element.selector)14 .getBoundingClientRect()15 const { x, y } = win.document.querySelector(element.selector).getBoundingClientRect()16 return {17 }18 })19})20{top: 0, left: 0, width: 200, height: 20, x: 0, y: 0}21describe('Cypress getDimensionsFor', () => {22 it('should get the dimensions of the element', () => {23 cy.get('#email1').then(($el) => {24 cy.getDimensionsFor($el).then((dimensions) => {25 console.log(dimensions)26 })27 })28 })29})30{top: 0, left: 0, width: 200, height: 20, x: 0, y: 0}
Using AI Code Generation
1const getDimensions = (selector, prop) => Cypress.$(selector).getDimensionsFor(prop);2describe('Test', () => {3 it('should get dimensions for the element', () => {4 cy.get('#test').then(($el) => {5 const { width, height } = getDimensions($el, 'width', 'height');6 expect(width).to.equal(100);7 expect(height).to.equal(100);8 });9 });10});11const getDimensions = (selector, prop) => jQuery(selector).getDimensionsFor(prop);12describe('Test', () => {13 it('should get dimensions for the element', () => {14 cy.get('#test').then(($el) => {15 const { width, height } = getDimensions($el, 'width', 'height');16 expect(width).to.equal(100);17 expect(height).to.equal(100);18 });19 });20});21window.jQuery = require('jquery');22window.$ = window.jQuery;23import $ from 'jquery';24import { getSomeData } from './someModule';25const someData = getSomeData();26import { getSomeData } from './someModule';27import { getData } from './someModule';28describe('getData', () => {29 it('should get some data', () => {30 const data = getData();31 expect(data).to.equal(someData);32 });33});34import { getSomeData } from './someModule
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!!