Best JavaScript code snippet using cypress
casper-socket.js
Source:casper-socket.js
...314 return promise;315 }316 async _setSessionAsync (accessToken) {317 if (this._socket === undefined) {318 await this._connectAsync(this._url + ((this._port != undefined && this._port !== '') ? ':' + this._port : '') + '/' + this._path);319 }320 return this._sendAsync(false, 'SET', { target: 'session' }, { access_token: accessToken });321 }322 async _extendSessionAsync (timeout) {323 return this._sendAsync(false, 'EXTEND', { target: 'session' }, {}, timeout);324 }325 /**326 * Validate the current access token, retrieve access token (session) from cookie and set on websocket327 */328 async validateSession () {329 const accessToken = this.sessionCookie;330 if (accessToken) {331 try {332 this._showOverlay({ message: 'Validação de sessão em curso', icon: 'connecting', spinner: true, loading_icon: 'loading-icon-03', noCancelOnOutsideClick: true });333 const response = await this._setSessionAsync(accessToken);334 if (response.success === false) {335 this._accessToken = undefined;336 this.deleteSessionCookie();337 this.dispatchEvent(new CustomEvent('casper-signed-out', { bubbles: true, composed: true }));338 } else {339 this._accessToken = accessToken;340 if (response.entity_id) {341 window.localStorage.setItem('casper-last-entity-id', response.entity_id);342 // add internal subscription343 this.subscribeNotifications('entity-push-events', response.entity_id, (notification) => {344 this.dispatchEvent(new CustomEvent(notification.event, {345 detail: notification.detail,346 bubbles: true,347 composed: true348 }))349 });350 this._reSubscribeNotifications(response.entity_id);351 }352 if (response.user_email) {353 this.savedEmail = response.user_email;354 }355 this._accessValidity = this.sessionValidity; // read back from cookie356 this._startIdleTimer();357 this.dispatchEvent(new CustomEvent('casper-signed-in', { bubbles: true, composed: true, detail: response }));358 }359 } catch (exception) {360 console.log(exception);361 }362 return;363 }364 this.deleteSessionCookie();365 this.dispatchEvent(new CustomEvent('casper-signed-out', { bubbles: true, composed: true }));366 }367 _reSubscribeNotifications (entity_id) {368 if (this._subscriptions) {369 this._subscriptions.forEach(function (subscription, key, map) {370 if (subscription.notification && subscription.confirmed) {371 let a = key.split(':');372 if (a[0] === 'company') {373 if (a[1] == entity_id && subscription.handler) {374 this._subscribeNotifications(a[0], a[1], subscription.handler);375 } else {376 this._unsubscribeNotifications(a[0], a[1]);377 }378 } else {379 this._subscribeNotifications(a[0], a[1], subscription.handler);380 }381 }382 }.bind(this));383 }384 }385 //***************************************************************************************//386 // //387 // ~~~ Entity Logout ~~~ //388 // //389 //***************************************************************************************//390 async signOutViaApi () {391 try {392 if (this.sessionCookie) {393 const request = await fetch('/login/sign-out', {394 headers: {395 'x-casper-access-token': this.sessionCookie,396 'Content-Type': 'application/json'397 }398 });399 }400 } catch (exception) {401 // ... ignore and proceed with the the logout402 } finally {403 this.disconnect();404 this.wipeCredentials();405 window.location = '/login';406 }407 }408 disconnectAndWipeCredentials () {409 this._socket.onclose = undefined;410 this.wipeCredentials();411 this.disconnect();412 }413 //***************************************************************************************//414 // //415 // ~~~ Entity switching ~~~ //416 // //417 //***************************************************************************************//418 async connectAndSetSession (url, accessToken) {419 this._initData();420 await this._connectAsync(url);421 return await this._setSessionAsync(accessToken);422 }423 /**424 * Switch the current entity or sub-entity using the HTTP bridge to access an interal microservice425 *426 * @param {Object} body the payload to send on the put request, must have a known 'action'427 */428 async switchViaBridge (body) {429 // ... clear the internal access token while we switch, note this is needed to430 // avoid a spurious session change detection by #checkIfSessionChanged() ...431 const oldAccessToken = this._accessToken;432 this._accessToken = undefined;433 try {434 let response;...
kucoin-client.js
Source:kucoin-client.js
...73 _connect() {74 if (!this._wss) {75 this._wss = { status: "connecting" };76 if (this.wssPath) super._connect();77 else this._connectAsync();78 }79 }80 async _connectAsync() {81 let wssPath;82 // Retry http request until successful83 while (!wssPath) {84 try {85 let raw = await https.post("https://openapi-v2.kucoin.com/api/v1/bullet-public");86 if (!raw.data || !raw.data.token) throw new Error("Unexpected token response");87 const { token, instanceServers } = raw.data;88 const { endpoint, pingInterval } = instanceServers[0];89 this._connectId = crypto.randomBytes(24).toString("hex");90 this._pingIntervalTime = pingInterval;91 wssPath = `${endpoint}?token=${token}&connectId=${this._connectId}`;92 } catch (ex) {93 this._onError(ex);94 await wait(this.connectInitTimeoutMs);...
ZeemoteGUI.js
Source:ZeemoteGUI.js
1/*2 * ZeemoteGUI.js3 * Copyright (C) 2011-2012 Zeemote. All rights reserved.4 * This is a sample script.5 */6/*7 * Property8 */9/* Menu Item Size */10/* ã¡ãã¥ã¼ã¢ã¤ãã ã®ãµã¤ãº */11var MenuItemWidth: int = 350;12var MenuItemHeight : int = 30;13/* String Data */14/* æååãã¼ã¿ */15var ButtonLabel_Cancel : String = "Cancel"; // Cancel Button16var ButtonLabel_Disconnect : String = "Disconnect"; // Disconenct Button17var DialogMessage_Connecting_prefix : String = "Connecting to "; // Connecting Message Prefix18var DialogMessage_Connected_prefix : String = "Connected to "; // Connected Message Prefix19var DialogMessage_ConnectError : String = "Unable to connect. Make sure your controller is on."; // Connect Error Message20var DialogMessage_Disconnecting : String = "Disconnecting."; // Disconnecting Mesage21var DialogMessage_Disconnected : String = "Disconnected."; // Disconnected Message22var DialogMessage_DisconnectError : String = "Unable to disconnect. Please try again in a few moments."; // Disconnect Error Message23/* Daialog Timeout */24/* ãã¤ã¢ãã°è¡¨ç¤ºãã¿ã¤ã ã¢ã¦ãããã¾ã§ã®æé */25var DialogTimeOut : float = 2.0f; // 2 seconds26/*27 * Private members28 */29 30/* ControllerID */31/* ã³ã³ããã¼ã©ã¼ID */32private var _controllerID : int = 0;33/* Menu Title */34/* ã¡ãã¥ã¼ã¿ã¤ãã« */35private var _menuTitle : String = null;36/* Menu Type */37/* 表示ããã¡ãã¥ã¼ã®ç¨®é¡ */38private static var TYPE_SELECT_MENU : int = 0; // Select Menu39private static var TYPE_DIALOG : int = 1; // Dialog40private var _menuType : int = 0;41/* Menu Item List */42/* ã¡ãã¥ã¼é
ç®ã®ãªã¹ã */43private var _menuItemList : String[] = null;44/* Selected Menu Item Index */45/* é¸æãããã¡ãã¥ã¼é
ç®ã®ã¤ã³ããã¯ã¹å¤ */46private var _selectedIdx : int = -1;47/* Available Controller Name List */48/* æ¥ç¶å¯è½ãªã³ã³ããã¼ã©ã¼ã®ååã®ãªã¹ã */49private var _nameList : String[] = null;50/* Show Menu Flag */51/* ã¡ãã¥ã¼è¡¨ç¤ºãã©ã° */52private var _showMenu : boolean = false;53/* Dialog Message */54/* ãã¤ã¢ãã°ã«è¡¨ç¤ºããã¡ãã»ã¼ã¸ */55private var _message : String = null;56/* Disconnect Menu Item List */57/* åæã¡ãã¥ã¼ã«è¡¨ç¤ºããã¡ãã¥ã¼é
ç®ã®ãªã¹ã */58private var DisconnectMenuItemList : String[] = null;59/*60 * Show Controller Menu61 * ã³ã³ããã¼ã©ã¼ã¡ãã¥ã¼ã表示ãã62 */63function ShowControllerMenu(controllerID : int, menuTitle : String) : boolean64{65 if(_showMenu == false) {66 /* Show controller menu. */67 /* ã³ã³ããã¼ã©ã¼ã¡ãã¥ã¼ã表示ãã */68 _controllerID = controllerID;69 _menuTitle = menuTitle;70 71 if(!(ZeemoteInput.IsConnected(_controllerID))) {72 /*73 * The controller is disconnected.74 * Show the connect menu.75 */76 /* 77 * æå®ã³ã³ããã¼ã©ã¼IDãæªæ¥ç¶ç¶æ
ã®å ´å78 * æ¥ç¶ã¡ãã¥ã¼ã表示ãã79 */80 StartCoroutine(ConnectionMenuProcess());81 } 82 else {83 /* 84 * The controller is connected.85 * Show the disconnect menu.86 */87 /*88 * æå®ã³ã³ããã¼ã©ã¼IDãæ¥ç¶ç¶æ
ã®å ´å89 * åæã¡ãã¥ã¼ã表示ãã90 */91 StartCoroutine(DisconnectionMenuProcess());92 }93 return true;94 }95 else {96 /* Now the menu is being displayed. */97 /* ç¾å¨ä»ã®ã¡ãã¥ã¼è¡¨ç¤ºä¸ */98 return false;99 }100}101/*102 * Start callback103 */104function Start() {105 ZeemoteInput.SetupPlugin();106} 107/*108 * On GUI callback109 */110function OnGUI () {111 if(!_showMenu)112 /* ã¡ãã¥ã¼è¡¨ç¤ºãã©ã°ãfalseãªãä½ã表示ããã«ãªã¿ã¼ã³ãã */113 return;114 switch(_menuType) {115 116 case TYPE_SELECT_MENU:117 /* Draw the select menu. */118 /* é¸æã¡ãã¥ã¼ãæç»ãã */119 _selectedIdx = DrawSelectMenu(_menuTitle, _menuItemList);120 break;121 122 case TYPE_DIALOG:123 /* Draw the dialog. */124 /* ãã¤ã¢ãã°ãæç»ãã */125 DrawDialog(_message);126 127 break;128 129 }130}131/*132 * Connection Menu Process Coroutine133 * æ¥ç¶ã¡ãã¥ã¼å¦çãè¡ãã³ã«ã¼ãã£ã³134 */135private function ConnectionMenuProcess () {136 /* Get available controllers List. */137 /* æ¥ç¶å¯è½ãªã³ã³ããã¼ã©ã¼ã®ååãªã¹ããåå¾ãã */138 ZeemoteInput.FindAvailableControllers();139 _nameList = ZeemoteInput.GetControllerNameList();140 if(_nameList == null) {141 _nameList = new String[0];142 }143 144 /* Show connect menu. */145 /* æ¥ç¶ã¡ãã¥ã¼ã表示ãã¦ã¼ã¶ã¼ã«ããé¸æãå¾
㤠*/146 ShowConnectMenu();147 while(_selectedIdx == -1)148 yield;149 150 /* Menu item was selected. Hide menu. */151 /* ã¡ãã¥ã¼é
ç®ãé¸æãããã®ã§é¸æã¡ãã¥ã¼ãæ¶ã */152 HideMenuAndDialog();153 yield WaitForSeconds(0.1);154 /* Check selected menu item. */155 /* é¸æãããã¡ãã¥ã¼é
ç®ãå¤å®ãã */156 if(_selectedIdx >= 0 && _selectedIdx < _nameList.Length) {157 /*158 * Selected menu item was a controller.159 * Show the connecting dialog160 */161 /*162 * ã³ã³ããã¼ã©ã¼ãé¸æãããå ´å163 * æ¥ç¶ä¸ãã¤ã¢ãã°ã表示ãã164 */165 ShowDialog(DialogMessage_Connecting_prefix + _nameList[_selectedIdx]);166 yield WaitForSeconds(0.1);167 168 /* Connect to the controller. */169 /* é¸æãããã³ã³ããã¼ã©ã¼ã¸éåæã§æ¥ç¶ãã */170 var _ConnectAsync : YieldInstruction = ZeemoteInput.ConnectControllerAsync(_controllerID, _selectedIdx);171 if(_ConnectAsync != null) {172 /*173 * Connecting.174 * Wait for the connection process is complete.175 */176 /*177 * æ¥ç¶å¦çéå§æå178 * æ¥ç¶å¦çã®å®äºãå¾
ã¤179 */180 yield _ConnectAsync;181 /* Check error. */182 /* ã¨ã©ã¼ãçºçãã¦ããªãã確èªãã */ 183 if(ZeemoteInput.GetError(_controllerID) == ZeemoteInput.ERR_NONE) {184 /* 185 * Connection success.186 * Hide the connecting dialog.187 */188 /*189 * æ¥ç¶æå190 * æ¥ç¶ä¸ãã¤ã¢ãã°ãæ¶ã191 */192 HideMenuAndDialog();193 yield WaitForSeconds(0.1);194 195 /* Show the connected dialog. */196 /* æ¥ç¶å®äºãã¤ã¢ãã°ã表示ãã¿ã¤ã ã¢ã¦ããå¾
㤠*/197 ShowDialog(DialogMessage_Connected_prefix + _nameList[_selectedIdx]);198 yield WaitForSeconds(DialogTimeOut);199 200 /* Hide the dialog. */201 /* ãã¤ã¢ãã°ãæ¶ã */202 HideMenuAndDialog();203 yield WaitForSeconds(0.1);204 205 /* Connection process ended. */206 /* æ¥ç¶å¦çæ£å¸¸çµäº */207 return;208 }209 }210 /*211 * Connect error212 * Hide the connecting dialog.213 */214 /*215 * æ¥ç¶ã¨ã©ã¼çºç216 * æ¥ç¶ä¸ãã¤ã¢ãã°ãæ¶ã217 */218 HideMenuAndDialog();219 yield WaitForSeconds(0.1);220 221 /* Show the error dialog. */222 /* ã¨ã©ã¼ãã¤ã¢ãã°ã表示ãã¿ã¤ã ã¢ã¦ããå¾
㤠*/223 ShowDialog(DialogMessage_ConnectError);224 yield WaitForSeconds(DialogTimeOut);225 226 /* Hide the dialog. */227 /* ãã¤ã¢ãã°ãæ¶ã */228 HideMenuAndDialog();229 yield WaitForSeconds(0.1);230 /* Connection process ended with error. */231 /* æ¥ç¶å¦çç°å¸¸çµäº */232 return;233 }234 else if(_selectedIdx == _nameList.Length) {235 /*236 * Selected menu item was the cancel.237 * Hide the menu.238 */239 /*240 * é¸æã¡ãã¥ã¼ã§ãã£ã³ã»ã«ãé¸æãããå ´å241 * é¸æã¡ãã¥ã¼ãæ¶ã242 */243 HideMenuAndDialog();244 yield WaitForSeconds(0.1);245 246 /* Connection process canceled. */247 /* æ¥ç¶å¦çãã£ã³ã»ã« */248 return;249 }250}251/*252 * Disconnection Menu Process Coroutine253 * åæã¡ãã¥ã¼å¦çãè¡ãã³ã«ã¼ãã£ã³254 */255private function DisconnectionMenuProcess () {256 /* Show disconnect menu. */257 /* åæã¡ãã¥ã¼è¡¨ç¤ºãã¦ã¼ã¶ã¼ã«ããé¸æãå¾
㤠*/258 ShowDisconnectMenu();259 while(_selectedIdx == -1)260 yield;261 /* Hide the menu. */262 /* ã¡ãã¥ã¼ãæ¶ã */263 HideMenuAndDialog();264 yield WaitForSeconds(0.1);265 /* Check selected menu item. */266 /* é¸æãããã¡ãã¥ã¼é
ç®ã確èªãã */267 if(_selectedIdx == 0) {268 /*269 * Selected menu item was the disconnect.270 * Show the disconnecting dialog271 */272 /*273 * åæãé¸æãããå ´å274 * åæä¸ãã¤ã¢ãã°ã表示ãã275 */276 ShowDialog(DialogMessage_Disconnecting);277 yield WaitForSeconds(0.1);278 279 /* Disconenct. */280 /* éåæã§åæå¦çãå®è¡ãã */281 var _DisconnectAsync : YieldInstruction = ZeemoteInput.DisconnectControllerAsync(_controllerID);282 if(_DisconnectAsync != null) {283 /*284 * Disconnecting...285 * Wait for the disconnection process is complete.286 */287 /*288 * åæå¦çéå§æå289 * åæå¦çã®å®äºãå¾
ã¤290 */291 yield _DisconnectAsync;292 /* Check error. */293 /* ã¨ã©ã¼ãçºçãã¦ããªãã確èªãã */ 294 if(ZeemoteInput.GetError(_controllerID) == ZeemoteInput.ERR_NONE) {295 /*296 * Disconnection success.297 * Hide the disconnecting dialog.298 */299 /*300 * åææå301 * åæä¸ãã¤ã¢ãã°ãæ¶ã302 */303 HideMenuAndDialog();304 yield WaitForSeconds(0.1);305 306 /* Show the disconnected dialog. */307 /* åæå®äºãã¤ã¢ãã°ã表示ãã¿ã¤ã ã¢ã¦ããå¾
㤠*/308 ShowDialog(DialogMessage_Disconnected);309 yield WaitForSeconds(DialogTimeOut);310 311 /* Hide the dialog. */312 /* ãã¤ã¢ãã°ãæ¶ã */313 HideMenuAndDialog();314 yield WaitForSeconds(0.1);315 316 /* Disconnection process ended. */317 /* åæå¦çæ£å¸¸çµäº */318 return;319 }320 }321 322 /*323 * Diconnect Error324 * Hide the disconnecting dialog325 */326 /*327 * åæå¦çã§ã¨ã©ã¼çºç328 * åæä¸ãã¤ã¢ãã°ãæ¶ã329 */330 HideMenuAndDialog();331 yield WaitForSeconds(0.1);332 333 /* Show the error dialog */334 /* åæã¨ã©ã¼ãã¤ã¢ãã°ã表示ãã¿ã¤ã ã¢ã¦ããå¾
㤠*/335 ShowDialog(DialogMessage_DisconnectError);336 yield WaitForSeconds(DialogTimeOut);337 338 /* Hide the dialog. */339 /* ãã¤ã¢ãã°ãæ¶ã */340 HideMenuAndDialog();341 yield WaitForSeconds(0.1);342 343 /* Disconnection process ended with error. */344 /* åæå¦çã¨ã©ã¼çµäº */345 return;346 }347 else if(_selectedIdx == 1) {348 /*349 * Selected menu item was the cancel.350 * Hide the menu.351 */352 /*353 * é¸æã¡ãã¥ã¼ã§ãã£ã³ã»ã«ãé¸æãããå ´å354 * ã¡ãã¥ã¼ãæ¶ã355 */356 HideMenuAndDialog();357 yield WaitForSeconds(0.1);358 359 /* Disconnection process canceled. */360 /* åæå¦çãã£ã³ã»ã« */361 return;362 }363}364/*365 * Show Connect Menu366 * æ¥ç¶ã¡ãã¥ã¼è¡¨ç¤º367 */368private function ShowConnectMenu() {369 _selectedIdx = -1;370 _menuItemList = _nameList;371 _menuType = 0;372 _showMenu = true;373}374/*375 * Show Disconnect Menu376 * åæã¡ãã¥ã¼è¡¨ç¤º377 */378private function ShowDisconnectMenu() {379 _selectedIdx = -1;380 /* Make disconnect menu item list. */381 if(DisconnectMenuItemList == null) {382 DisconnectMenuItemList = new String[1];383 DisconnectMenuItemList[0] = ButtonLabel_Disconnect;384 }385 _menuItemList = DisconnectMenuItemList;386 _menuType = TYPE_SELECT_MENU;387 _showMenu = true;388}389/*390 * Show Dialog391 * ãã¤ã¢ãã°è¡¨ç¤º392 */393private function ShowDialog(message : String) {394 _message = message;395 _menuType = TYPE_DIALOG;396 _showMenu = true;397}398/*399 * Hide Menu and Dialog400 * ã¡ãã¥ã¼ããã³ãã¤ã¢ãã°æ¶å»401 */402private function HideMenuAndDialog() {403 _showMenu = false;404}405/*406 * Draw Select Menu407 * é¸æã¡ãã¥ã¼æç»408 */409private function DrawSelectMenu(menuTitle : String, menuItemList : String[]) : int410{411 var _ret : int = -1;412 413 /* Calculate menu rect sizes. */414 /* ã¡ãã¥ã¼è¡¨ç¤ºé åãç®åºãã */415 var _MenuWidth : int = MenuItemWidth + 50;416 var _MenuHeight : int = ((MenuItemHeight + 5) * (menuItemList.Length + 2)) + 10;417 var _MenuLeft : int = Screen.width / 2 - (_MenuWidth / 2); // Horizontal centering418 var _MenuTop : int = Screen.height / 2 - (_MenuHeight /2); // Vertical centering419 420 /* Begin GUI group. */421 /* GUI group æç»éå§ */422 GUI.BeginGroup(Rect(_MenuLeft, _MenuTop, _MenuWidth, _MenuHeight));423 424 /* Draw menu box and menu title. */425 /* ã¡ãã¥ã¼ããã¯ã¹ã¨ã¡ãã¥ã¼ã¿ã¤ãã«ãæç»ãã */426 GUI.Box(Rect (0, 0, _MenuWidth, _MenuHeight), menuTitle);427 428 /* Draw menu item lists. */429 /* åã¡ãã¥ã¼é
ç®ãæç»ãã */430 for(var i : int = 0; i < menuItemList.Length; i++) {431 /* Draw menu item button and check whether the button is pressed. */432 /* ã¡ãã¥ã¼é
ç®ããã¿ã³ã¨ãã¦æç»ãããããæ¼ããããã©ããããã§ãã¯ãã */433 if(GUI.Button(Rect (25, ((MenuItemHeight + 5) * (i + 1)) , MenuItemWidth, MenuItemHeight), menuItemList[i])) {434 /* Menu item button was pressed.*/435 /* ãã¿ã³ãæ¼ãããã®ã§ã¡ãã¥ã¼é
ç®ã®ã¤ã³ããã¯ã¹ãä¿å */436 _ret = i;437 } 438 439 }440 /* Draw the cancel button and check whether the button is pressed. */441 /* ãã£ã³ã»ã«ãã¿ã³ãæç»ãããããæ¼ããããã©ããããã§ãã¯ãã */442 if(GUI.Button(Rect (25, ((MenuItemHeight + 5) * (i + 1)) , MenuItemWidth, MenuItemHeight), ButtonLabel_Cancel)) {443 /* Cancel button was pressed. */444 /* ãã£ã³ã»ã«ãã¿ã³ãæ¼ãããã®ã§ãã®ã¤ã³ããã¯ã¹ãä¿å */445 _ret = i;446 }447 448 /* End GUI group. */449 /* GUI group æç»çµäº */450 GUI.EndGroup();451 452 /* Return selected menu item index. */453 /* é¸æãããã¡ãã¥ã¼é
ç®ã®ã¤ã³ããã¯ã¹ãè¿ã (æªé¸æã®å ´å -1 ãè¿ã) */454 return _ret;455}456/*457 * Draw Dialog458 * ãã¤ã¢ãã°æç»459 */460private function DrawDialog(message : String)461{462 /* Calculate dialog rect sizes. */463 /* ãã¤ã¢ãã°è¡¨ç¤ºé åãç®åºãã */464 var _DialogWidth: int = MenuItemWidth + 50;465 var _DialogHeight: int = MenuItemHeight + 10;466 var _DialogLeft : int = Screen.width / 2 - (_DialogWidth / 2); // Horizontal centering467 var _DialogTop : int = Screen.height / 2 - (_DialogHeight /2); // Vertical centering468 /* Modfy box style. */469 /* Boxã®è¡¨ç¤ºã¹ã¿ã¤ã«ãä¸æçã«å¤æ´ãã (ã¢ã©ã¤ã¡ã³ããã»ã³ã¿ãªã³ã°ã«è¨å®ãã) */ 470 var _backupAlignment : TextAnchor = GUI.skin.box.alignment;471 GUI.skin.box.alignment = TextAnchor.MiddleCenter; // Set box alignment to middle center. 472 473 /* Begin GUI group. */474 /* GUI group æç»éå§ */475 GUI.BeginGroup(Rect(_DialogLeft, _DialogTop, _DialogWidth, _DialogHeight));476 477 /* Draw dialog box and message. */478 /* ãã¤ã¢ãã°ããã¯ã¹ã¨ã¡ãã»ã¼ã¸ãæç»ãã */479 GUI.Box(Rect (0, 0, _DialogWidth, _DialogHeight), message);480 481 /* End GUI group. */482 /* GUI group æç»çµäº */483 GUI.EndGroup();484 485 /* Restore box style.*/486 /* Boxã®è¡¨ç¤ºã¹ã¿ã¤ã«ãå
ã«æ»ã */487 GUI.skin.box.alignment = _backupAlignment;...
bittrex-client.js
Source:bittrex-client.js
...146 */147 _connect() {148 if (!this._wss) {149 this._wss = { status: "connecting" };150 this._connectAsync();151 }152 }153 /**154 * Asynchronously connect to a socket. This method will retrieve a token155 * from an HTTP request and then construct a websocket. If the HTTP156 * request fails, it will retry until successful.157 */158 async _connectAsync() {159 let wssPath = this.wssPath;160 // Retry HTTP requests until we are successful161 while (!wssPath) {162 try {163 let data = JSON.stringify([{ name: "c3" }]);164 let negotiations = await https.get(165 `https://socket-v3.bittrex.com/signalr/negotiate?connectionData=${data}&clientProtocol=1.5`166 );167 let token = encodeURIComponent(negotiations.ConnectionToken);168 wssPath = `wss://socket-v3.bittrex.com/signalr/connect?clientProtocol=1.5&transport=webSockets&connectionToken=${token}&connectionData=${data}&tid=10`;169 } catch (ex) {170 await wait(this.connectInitTimeoutMs);171 this._onError(ex);172 }...
firefox-util.js
Source:firefox-util.js
...149 ]);150 },151 setupFoxdriver(port) {152 return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {153 yield protocol._connectAsync({154 host: '127.0.0.1',155 port,156 getDelayMsForRetry,157 });158 const foxdriver = yield foxdriver_1.default.attach('127.0.0.1', port);159 const { browser } = foxdriver;160 browser.on('error', (err) => {161 debug('received error from foxdriver connection, ignoring %o', err);162 });163 forceGcCc = () => {164 let gcDuration;165 let ccDuration;166 const gc = (tab) => {167 return () => {168 // TODO: figure out why tab.memory is sometimes undefined169 if (!tab.memory)170 return;171 const start = Date.now();172 return tab.memory.forceGarbageCollection()173 .then(() => {174 gcDuration = Date.now() - start;175 timings.gc.push(gcDuration);176 });177 };178 };179 const cc = (tab) => {180 return () => {181 // TODO: figure out why tab.memory is sometimes undefined182 if (!tab.memory)183 return;184 const start = Date.now();185 return tab.memory.forceCycleCollection()186 .then(() => {187 ccDuration = Date.now() - start;188 timings.cc.push(ccDuration);189 });190 };191 };192 debug('forcing GC and CC...');193 return getPrimaryTab(browser)194 .then((tab) => {195 return attachToTabMemory(tab)196 .then(gc(tab))197 .then(cc(tab));198 })199 .then(() => {200 debug('forced GC and CC completed %o', { ccDuration, gcDuration });201 })202 .tapCatch((err) => {203 debug('firefox RDP error while forcing GC and CC %o', err);204 });205 };206 });207 },208 setupMarionette(extensions, url, port) {209 return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {210 yield protocol._connectAsync({211 host: '127.0.0.1',212 port,213 getDelayMsForRetry,214 });215 driver = new marionette_client_1.default.Drivers.Promises({216 port,217 tries: 1, // marionette-client has its own retry logic which we want to avoid218 });219 debug('firefox: navigating page with webdriver');220 const onError = (from, reject) => {221 if (!reject) {222 reject = (err) => {223 throw err;224 };...
conversation-db.js
Source:conversation-db.js
...13 })14 .catch(err => reject(err));15 });16 }17 async _connectAsync() {18 try {19 while (this.connectionLock) {}20 if (this.isConnected) return;21 this.connectionLock = true;22 this.db = await this._connect();23 this.isConnected = true;24 this.connectionLock = false;25 } catch (err) {26 console.log(err);27 }28 }29 async getDealerIdByEmail(email) {30 if (!this.isConnected) await this._connectAsync();31 return await this.db.request()32 .input('email_address', email)33 .query('select TOP 1 * from dealers where EmailAddress = @email_address');34 }35 async saveNewDealer(email, dealerName, contactName) {36 if (!this.isConnected) await this._connectAsync();37 var result = await this.db.request()38 .input('email_address', email)39 .input('dealer_name', dealerName)40 .input('contact_name', contactName)41 .output('dealer_id', sql.Int)42 .query('insert into dealers(DealerName, ContactName, EmailAddress) VALUES(@dealer_name, @contact_name, @email_address); SELECT @@IDENTITY as dealer_id');43 return result.recordset[0].dealer_id;44 }45 async saveNewConversation(hash, customerId, dealerId) {46 if (!this.isConnected) await this._connectAsync();47 return await this.db.request()48 .input('hash', hash)49 .input('customer_id', customerId)50 .input('dealer_id', dealerId)51 .query('insert into conversations(Hash, CustomerId, DealerId) VALUES(@hash,@customer_id,@dealer_id)');52 }53 async getCustomerByEmail(email) {54 if (!this.isConnected) await this._connectAsync();55 return await this.db.request()56 .input('email_address', email)57 .query('select TOP 1 * from customers where EmailAddress = @email_address');58 }59 async saveNewCustomer(email, name) {60 if (!this.isConnected) await this._connectAsync();61 var result = await this.db.request()62 .input('email_address', email)63 .input('name', name)64 .output('customer_id', sql.Int)65 .query('insert into customers(Name, EmailAddress) VALUES(@name,@email_address); SELECT @@IDENTITY as customer_id');66 return result.recordset[0].customer_id;67 }68 async saveNewMessage(conversationHash, customerId, dealerId, message) {69 if (!this.isConnected) await this._connectAsync();70 return await this.db.request()71 .input('conversation_hash', conversationHash)72 .input('customer_id', customerId)73 .input('dealer_id', dealerId)74 .input('message', message)75 .input('timestamp', new Date())76 .query('insert into messages(ConversationHash, CustomerId, DealerId, Message, Timestamp) VALUES(@conversation_hash,@customer_id,@dealer_id,@message, @timestamp)');77 }78 close() {79 this.db.close();80 this.isConnected = false;81 }...
protocol.js
Source:protocol.js
...35 */36const getWsTargetFor = (port) => {37 debug('Getting WS connection to CRI on port %d', port)38 la(is.port(port), 'expected port number', port)39 return _connectAsync({ port })40 .tapCatch((err) => {41 debug('failed to connect to CDP %o', { port, err })42 })43 .then(() => {44 debug('CRI.List on port %d', port)45 // what happens if the next call throws an error?46 // it seems to leave the browser instance open47 return CRI.List({ port })48 })49 .then((targets) => {50 debug('CRI List %o', { numTargets: targets.length, targets })51 // activate the first available id52 // find the first target page that's a real tab53 // and not the dev tools or background page....
Using AI Code Generation
1const { _connectAsync } = require('cypress-mongodb')2const { _disconnect } = require('cypress-mongodb')3const { _dropDatabase } = require('cypress-mongodb')4const { _find } = require('cypress-mongodb')5const { _insertOne } = require('cypress-mongodb')6const { _insertMany } = require('cypress-mongodb')7const { _updateOne } = require('cypress-mongodb')8const { _updateMany } = require('cypress-mongodb')9const { _deleteOne } = require('cypress-mongodb')10const { _deleteMany } = require('cypress-mongodb')11const { _aggregate } = require('cypress-mongodb')12const { _countDocuments } = require('cypress-mongodb')13const { _dropCollection } = require('cypress-mongodb')14const { _dropDatabase } = require('cypress-mongodb')15const { _createCollection } = require('cypress-mongodb')
Using AI Code Generation
1Cypress._connectAsync().then((socket) => {2 socket.on('message', (data) => {3 console.log(data)4 })5})6Cypress._connectAsync = () => {7 const socket = new WebSocket(url)8 return new Promise((resolve) => {9 socket.onopen = () => {10 console.log('Connected to websocket')11 resolve(socket)12 }13 })14}
Using AI Code Generation
1import { _connectAsync } from '@packages/driver/src/cypress/cy';2describe('My Test', () => {3 beforeEach(() => {4 });5 it('My Test Case', () => {6 _connectAsync('click', { selector: 'button' }).then((res) => {7 console.log(res);8 });9 });10});
Using AI Code Generation
1Cypress.Commands.add('_connectAsync', (url) => {2 return new Cypress.Promise((resolve, reject) => {3 const ws = new WebSocket(url);4 ws.onopen = () => {5 resolve(ws);6 };7 ws.onerror = (err) => {8 reject(err);9 };10 });11});12Cypress.Commands.add('_connectAsync', (url) => {13 return new Cypress.Promise((resolve, reject) => {14 const ws = new WebSocket(url);15 ws.onopen = () => {16 resolve(ws);17 };18 ws.onerror = (err) => {19 reject(err);20 };21 });22});23Cypress.Commands.add('_connectAsync', (url) => {24 return new Cypress.Promise((resolve, reject) => {25 const ws = new WebSocket(url);26 ws.onopen = () => {27 resolve(ws);28 };29 ws.onerror = (err) => {30 reject(err);31 };32 });33});34Cypress.Commands.add('_connectAsync', (url) => {35 return new Cypress.Promise((resolve, reject) => {36 const ws = new WebSocket(url);37 ws.onopen = () => {38 resolve(ws);39 };40 ws.onerror = (err) => {41 reject(err);42 };43 });44});45Cypress.Commands.add('_connectAsync', (url) => {46 return new Cypress.Promise((resolve, reject) => {47 const ws = new WebSocket(url);48 ws.onopen = () => {49 resolve(ws);50 };51 ws.onerror = (err) => {52 reject(err);53 };54 });55});
Using AI Code Generation
1Cypress._connectAsync = function (options) {2 var url = options.url;3 var ws = new WebSocket(url);4 ws.binaryType = 'arraybuffer';5 var connection = new Connection(ws, options);6 return connection;7};8Cypress._connectAsync = function (options) {9 var url = options.url;10 var ws = new WebSocket(url);11 ws.binaryType = 'arraybuffer';12 var connection = new Connection(ws, options);13 return connection;14};15Cypress._connectAsync = function (options) {16 var url = options.url;17 var ws = new WebSocket(url);18 ws.binaryType = 'arraybuffer';19 var connection = new Connection(ws, options);20 return connection;21};22Cypress._connectAsync = function (options) {23 var url = options.url;24 var ws = new WebSocket(url);25 ws.binaryType = 'arraybuffer';26 var connection = new Connection(ws, options);27 return connection;28};29Cypress._connectAsync = function (options) {30 var url = options.url;31 var ws = new WebSocket(url);32 ws.binaryType = 'arraybuffer';33 var connection = new Connection(ws, options);34 return connection;35};36Cypress._connectAsync = function (options) {37 var url = options.url;38 var ws = new WebSocket(url);39 ws.binaryType = 'arraybuffer';40 var connection = new Connection(ws, options);41 return connection;42};43Cypress._connectAsync = function (options) {44 var url = options.url;45 var ws = new WebSocket(url);46 ws.binaryType = 'arraybuffer';47 var connection = new Connection(ws, options);48 return connection;49};50Cypress._connectAsync = function (options) {51 var url = options.url;52 var ws = new WebSocket(url);
Using AI Code Generation
1const db = Cypress.env('db');2const dbConfig = Cypress.env('dbConfig');3const connect = async () => {4 const client = new MongoClient(dbConfig.url, {5 });6 await client.connect();7 return client.db(db);8};9Cypress.Commands.add('connectAsync', connect);10describe('Test', () => {11 it('should be able to connect to database', () => {12 cy.connectAsync().then(db => {13 });14 });15});16Cypress.Commands.add('connectAsync', async () => {17 const client = new MongoClient(dbConfig.url, {18 });19 await client.connect();20 return client.db(db);21});22Cypress.Commands.add('connectAsync', async () => {23 const client = new MongoClient(dbConfig.url, {24 });25 await client.connect();26 return client.db(db);27});28Cypress.Commands.add('connectAsync', async () => {29 const client = new MongoClient(dbConfig.url, {30 });31 await client.connect();32 return client.db(db);33});34Cypress.Commands.add('connectAsync', async () => {35 const client = new MongoClient(dbConfig.url, {36 });37 await client.connect();38 return client.db(db);39});40Cypress.Commands.add('connectAsync', async () => {41 const client = new MongoClient(dbConfig.url, {42 });43 await client.connect();44 return client.db(db);45});46Cypress.Commands.add('connectAsync', async () => {47 const client = new MongoClient(dbConfig.url, {48 });49 await client.connect();50 return client.db(db);51});52Cypress.Commands.add('connectAsync', async () => {53 const client = new MongoClient(dbConfig.url, {54 });55 await client.connect();56 return client.db(db);57});58Cypress.Commands.add('connectAsync', async () => {59 const client = new MongoClient(dbConfig.url, {
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!!