How to use _connectAsync method in Cypress

Best JavaScript code snippet using cypress

casper-socket.js

Source:casper-socket.js Github

copy

Full Screen

...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;...

Full Screen

Full Screen

kucoin-client.js

Source:kucoin-client.js Github

copy

Full Screen

...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);...

Full Screen

Full Screen

ZeemoteGUI.js

Source:ZeemoteGUI.js Github

copy

Full Screen

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;...

Full Screen

Full Screen

bittrex-client.js

Source:bittrex-client.js Github

copy

Full Screen

...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 }...

Full Screen

Full Screen

firefox-util.js

Source:firefox-util.js Github

copy

Full Screen

...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 };...

Full Screen

Full Screen

conversation-db.js

Source:conversation-db.js Github

copy

Full Screen

...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 }...

Full Screen

Full Screen

protocol.js

Source:protocol.js Github

copy

Full Screen

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

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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')

Full Screen

Using AI Code Generation

copy

Full Screen

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}

Full Screen

Using AI Code Generation

copy

Full Screen

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});

Full Screen

Using AI Code Generation

copy

Full Screen

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});

Full Screen

Using AI Code Generation

copy

Full Screen

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);

Full Screen

Using AI Code Generation

copy

Full Screen

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, {

Full Screen

Cypress Tutorial

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.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

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.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful