How to use getUniqueRequestId method in Cypress

Best JavaScript code snippet using cypress

adf.mf.device.integration.js

Source:adf.mf.device.integration.js Github

copy

Full Screen

...414 {415 try416 {417 this.timestamp = "T" + ((new Date()).getTime() % 600000);418 this.requestId = adf.mf.internal.processingRequestQueue.getUniqueRequestId();419 this.scb = adf.mf.internal.util.is_array(success)? success : [success];420 this.fcb = adf.mf.internal.util.is_array(failed)? failed : [failed ];421 this.plugin = "ADFMobileShell";422 this.methodName = "invokeJavaMethod";423 this.request = request;424 /**425 * set the plugin name426 * @param name427 **/428 /* void */429 this.setPlugin = function(name)430 {431 this.plugin = name;432 };...

Full Screen

Full Screen

Payment.js

Source:Payment.js Github

copy

Full Screen

...50 static createTxnToken(paymentDetails) {51 return __awaiter(this, void 0, void 0, function* () {52 if (paymentDetails instanceof _PaymentDetail.PaymentDetail) {53 try {54 _Config.Config.requestId = _CommonUtil.CommonUtil.getUniqueRequestId();55 if (!_MerchantProperties.MerchantProperties.isInitialized) {56 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", "MerchantProperties are not initialized ");57 var exception = _SDKException.SDKException.getMerchantPropertyInitializationException();58 var response_body = new _InitiateTransactionResponseBody.InitiateTransactionResponseBody();59 var response = new _InitiateTransactionResponse.InitiateTransactionResponse(null, response_body);60 return _CommonUtil.CommonUtil.getSDKResponse(exception, response);61 }62 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", "In createTxnToken PaymentDetail: ", paymentDetails);63 Payment.validatePaymentDetailsObject(paymentDetails);64 var request = Payment.createInitiateTransactionRequest(paymentDetails);65 var requestHead = request.getHead();66 var requestBody = request.getBody();67 yield Payment.setSignature(requestHead, requestBody);68 var url = Payment.urlBuilder(_MerchantProperties.MerchantProperties.getInitiateTxnUrl(), requestBody.getMid(), requestBody.getOrderId());69 return yield _Request.Request.process(request, url, "InitiateTransactionResponse", paymentDetails.getReadTimeout(), _MerchantProperties.MerchantProperties.connectTimeout);70 }71 catch (e) {72 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", "Exception caught in createTxnToken: ", e);73 return _CommonUtil.CommonUtil.getSDKResponse(e, new _InitiateTransactionResponse.InitiateTransactionResponse(null, new _InitiateTransactionResponseBody.InitiateTransactionResponseBody()));74 }75 }76 else {77 var e = _SDKException.SDKException.getSDKException("In createInitiateTransactionRequest, " + _ErrorConstants.ErrorMessage.UNEXPECTED_OBJECT_PASSED_AS_PARAM, null);78 return _CommonUtil.CommonUtil.getSDKResponse(e, new _InitiateTransactionResponse.InitiateTransactionResponse(null, new _InitiateTransactionResponseBody.InitiateTransactionResponseBody()));79 }80 });81 }82 /**83 * validateCreateTxnToken checks if all mandatory parameters are present for84 * CreateTxnToken api call.85 * If not, then this will throw SDKException exception86 *87 * @param PaymentDetail88 * @throws Exception89 * @return void90 */91 static validatePaymentDetailsObject(paymentDetails) {92 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", "validatePaymentDetailsObject for object: ", paymentDetails);93 if (paymentDetails instanceof _PaymentDetail.PaymentDetail) {94 var txnAmount = paymentDetails.getTxnAmount();95 var userInfo = paymentDetails.getUserInfo();96 if ( //Is ChannelId a mandatory param ????97 _CommonUtil.CommonUtil.isEmptyOrNull(paymentDetails.getOrderId())98 || (false === (txnAmount instanceof _Money.Money))99 || _CommonUtil.CommonUtil.isEmptyOrNull(txnAmount.getValue())100 || (false === (userInfo instanceof _UserInfo.UserInfo))101 || _CommonUtil.CommonUtil.isEmptyOrNull(userInfo.getCustId())) {102 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", " validatePaymentDetailsObject returns false ");103 throw _SDKException.SDKException.getMissingMandatoryParametersException();104 }105 }106 else {107 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", "validatePaymentDetailsObject for object: " + _ErrorConstants.ErrorMessage.UNEXPECTED_OBJECT_PASSED_AS_PARAM);108 throw new _SDKException.SDKException("In validatePaymentDetailsObject, " + _ErrorConstants.ErrorMessage.UNEXPECTED_OBJECT_PASSED_AS_PARAM);109 }110 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", " validatePaymentDetailsObject returns true ");111 }112 /**113 * @param PaymentDetail114 * @return InitiateTransactionRequest115 * @throws Exception116 */117 static createInitiateTransactionRequest(paymentDetails) {118 if (paymentDetails instanceof _PaymentDetail.PaymentDetail) {119 var head = _CommonUtil.CommonUtil.getSecureRequestHeader(_MerchantProperties.MerchantProperties.getClientId(), paymentDetails.getWorkFlow(), paymentDetails.getChannelId());120 var body = paymentDetails.createInitiateTransactionRequestBody();121 var request = new _InitiateTransactionRequest.InitiateTransactionRequest(head, body);122 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", "InitiateTransactionRequest object ", request);123 return request;124 }125 else {126 throw _SDKException.SDKException.getSDKException("In createInitiateTransactionRequest, " + _ErrorConstants.ErrorMessage.UNEXPECTED_OBJECT_PASSED_AS_PARAM, null);127 }128 }129 /**130 * setSignature set the signature in head(SecureRequestHeader), signature will131 * be generated by the body(Object)132 *133 * @param SecureRequestHeader134 * @param InitiateTransactionRequestBody|NativePaymentStatusRequestBody135 * @throws Exception136 */137 static setSignature(head, body) {138 return __awaiter(this, void 0, void 0, function* () {139 if (head instanceof _SecureRequestHeader.SecureRequestHeader) {140 var formattedJsonBody = JSON.stringify(body);141 var signature = yield _EncDecUtil.EncDecUtil.generateSignature(formattedJsonBody, _MerchantProperties.MerchantProperties.getMerchantKey());142 head.setSignature(signature);143 }144 else {145 throw _SDKException.SDKException.getSDKException("In setSignature, " + _ErrorConstants.ErrorMessage.UNEXPECTED_OBJECT_PASSED_AS_PARAM, null);146 }147 });148 }149 /**150 * getPaymentStatus gets constant parameters and creates request object to call151 * ProcessRequest.process. It returns the NativeMerchantStatusResponseBody which152 * holds the getPaymentStatus result parameters which will be used by merchant153 * in future. It handles the exception if occurred, and returns the respective154 * object with error message.155 *156 * @param PaymentStatusDetail157 * @return SDKResponse158 * @throws Exception159 */160 static getPaymentStatus(paymentStatusDetail) {161 return __awaiter(this, void 0, void 0, function* () {162 if (paymentStatusDetail instanceof _PaymentStatusDetail.PaymentStatusDetail) {163 _Config.Config.requestId = _CommonUtil.CommonUtil.getUniqueRequestId();164 try {165 if (!_MerchantProperties.MerchantProperties.isInitialized) {166 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", " MerchantProperties are not initialized ");167 return _CommonUtil.CommonUtil.getSDKResponse(_SDKException.SDKException.getMerchantPropertyInitializationException(), new _NativePaymentStatusResponse.NativePaymentStatusResponse(null, new _NativePaymentStatusResponseBody.NativePaymentStatusResponseBody()));168 }169 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Payment", "In getPaymentStatus PaymentStatusDetail: ", paymentStatusDetail);170 Payment.validatePaymentStatusDetailObject(paymentStatusDetail);171 var request = Payment.createNativePaymentStatusRequest(paymentStatusDetail);172 var requestHead = request.getHead();173 var requestBody = request.getBody();174 yield Payment.setSignature(requestHead, requestBody);175 return yield _Request.Request.process(request, _MerchantProperties.MerchantProperties.getPaymentStatusUrl(), "NativePaymentStatusResponse", paymentStatusDetail.getReadTimeout(), _MerchantProperties.MerchantProperties.connectTimeout);176 }177 catch (e) {...

Full Screen

Full Screen

Refund.js

Source:Refund.js Github

copy

Full Screen

...50 static initiateRefund(refundDetail) {51 return __awaiter(this, void 0, void 0, function* () {52 if (refundDetail instanceof _RefundDetail.RefundDetail) {53 try {54 _Config.Config.requestId = _CommonUtil.CommonUtil.getUniqueRequestId();55 if (!_MerchantProperties.MerchantProperties.isInitialized) {56 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", " MerchantProperties are not initialized ");57 return _CommonUtil.CommonUtil.getSDKResponse(_SDKException.SDKException.getMerchantPropertyInitializationException(), new _AsyncRefundResponse.AsyncRefundResponse(null, new _AsyncRefundResponseBody.AsyncRefundResponseBody()));58 }59 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", "In doRefund RefundDetail " + JSON.stringify(refundDetail));60 Refund.validateRefundDetailObject(refundDetail);61 var request = Refund.createRefundInitiateRequest(refundDetail);62 var requestHead = request.getHead();63 var requestBody = request.getBody();64 yield Refund.setSignature(requestHead, requestBody);65 return yield _Request.Request.process(request, _MerchantProperties.MerchantProperties.getRefundUrl(), "AsyncRefundResponse", refundDetail.getReadTimeout(), _MerchantProperties.MerchantProperties.connectTimeout);66 }67 catch (e) {68 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", "Caught exception in doRefund, exception object: ", e);69 return _CommonUtil.CommonUtil.getSDKResponse(e, new _AsyncRefundResponse.AsyncRefundResponse(null, new _AsyncRefundResponseBody.AsyncRefundResponseBody()));70 }71 }72 else {73 var e = _SDKException.SDKException.getSDKException("In initiateRefund, " + _ErrorConstants.ErrorMessage.UNEXPECTED_OBJECT_PASSED_AS_PARAM, null);74 return _CommonUtil.CommonUtil.getSDKResponse(e, new _AsyncRefundResponse.AsyncRefundResponse(null, new _AsyncRefundResponseBody.AsyncRefundResponseBody()));75 }76 });77 }78 /**79 * setSignature set the signature in head(SecureRequestHeader), signature will80 * be generated by the body(Object)81 * @param SecureRequestHeader82 * @param RefundInitiateRequestBody83 * @throws Exception84 */85 static setSignature(head, body) {86 return __awaiter(this, void 0, void 0, function* () {87 if (head instanceof _SecureRequestHeader.SecureRequestHeader) {88 var formattedJsonBody = JSON.stringify(body);89 var signature = yield _EncDecUtil.EncDecUtil.generateSignature(formattedJsonBody, _MerchantProperties.MerchantProperties.getMerchantKey());90 head.setSignature(signature);91 }92 else {93 throw _SDKException.SDKException.getSDKException("In setSignature, " + _ErrorConstants.ErrorMessage.UNEXPECTED_OBJECT_PASSED_AS_PARAM, null);94 }95 });96 }97 /**98 * @param RefundDetail99 * @return RefundInitiateRequest100 * @throws Exception101 */102 static createRefundInitiateRequest(refundDetail) {103 if (refundDetail instanceof _RefundDetail.RefundDetail) {104 var head = _CommonUtil.CommonUtil.getSecureRequestHeader(_MerchantProperties.MerchantProperties.getClientId(), refundDetail.getWorkFlow(), null);105 var body = refundDetail.createRefundInitiateRequestBody();106 var request = new _RefundInitiateRequest.RefundInitiateRequest();107 request.setHead(head);108 request.setBody(body);109 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", "RefundInitiateRequest object " + JSON.stringify(request));110 return request;111 }112 else {113 throw _SDKException.SDKException.getSDKException('In createRefundInitiateRequestWithRefundDetail' + _ErrorConstants.ErrorMessage.UNEXPECTED_OBJECT_PASSED_AS_PARAM, null);114 }115 }116 /**117 * validateRefund checks if all mandatory parameters are present for Refund api118 * call. If not, then is will throw the SDKException exception119 *120 * @param RefundDetail121 * @return void122 * @throws Exception123 */124 static validateRefundDetailObject(refundDetail) {125 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", "validateRefundDetailObject for object: " + JSON.stringify(refundDetail));126 if (_CommonUtil.CommonUtil.isEmptyOrNull(refundDetail.getOrderId())127 || _CommonUtil.CommonUtil.isEmptyOrNull(refundDetail.getRefId())128 || _CommonUtil.CommonUtil.isEmptyOrNull(refundDetail.getTxnId())129 || _CommonUtil.CommonUtil.isEmptyOrNull(refundDetail.getTxnType())130 || _CommonUtil.CommonUtil.isEmptyOrNull(refundDetail.getRefundAmount())) {131 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", "validateRefundDetailObject returns false ");132 throw _SDKException.SDKException.getMissingMandatoryParametersException();133 }134 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", "validateRefundDetailObject returns true ");135 }136 /**137 * This method gets RefundStatusDetail object as parameter and returns the138 * SDKResponse(NativeRefundStatusResponse).139 *140 * It creates request object to call ProcessRequest.process. It returns the141 * SDKResponse(NativeRefundStatusResponse) which contains refund status object.142 * It handles the exception if occurred, and returns the respective object with143 * error message.144 *145 * @param RefundStatusDetail object containing data regarding refund status146 * @return SDKResponse containing response string from api hit and response object147 *148 * @throws Exception149 */150 static getRefundStatus(refundStatusDetail) {151 return __awaiter(this, void 0, void 0, function* () {152 if (refundStatusDetail instanceof _RefundStatusDetail.RefundStatusDetail) {153 try {154 _Config.Config.requestId = _CommonUtil.CommonUtil.getUniqueRequestId();155 if (!_MerchantProperties.MerchantProperties.isInitialized) {156 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", " MerchantProperties are not initialized ");157 return _CommonUtil.CommonUtil.getSDKResponse(_SDKException.SDKException.getMerchantPropertyInitializationException(), new _NativeRefundStatusResponse.NativeRefundStatusResponse(null, new _NativeRefundStatusResponseBody.NativeRefundStatusResponseBody()));158 }159 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.INFO, "Refund", "In getRefundStatus, RefundStatusDetail: " + JSON.stringify(refundStatusDetail));160 Refund.validateRefundStatusDetailObject(refundStatusDetail);161 var request = Refund.createRefundStatusRequest(refundStatusDetail);162 var requestHead = request.getHead();163 var requestBody = request.getBody();164 yield Refund.setSignature(requestHead, requestBody);165 return yield _Request.Request.process(request, _MerchantProperties.MerchantProperties.getRefundStatusUrl(), "NativeRefundStatusResponse", refundStatusDetail.getReadTimeout(), _MerchantProperties.MerchantProperties.connectTimeout);166 }167 catch (e) {168 _LoggingUtil.LoggingUtil.addLog(_LoggingUtil.LoggingUtil.LogLevel.ERROR, "Refund", "Caught exception in getRefundStatus: ", e);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...108 };109 return runMiddlewareStack();110}111exports._runStage = _runStage;112function getUniqueRequestId(requestId) {113 const match = /^(.*)-retry-([\d]+)$/.exec(requestId);114 if (match) {115 return `${match[1]}-retry-${Number(match[2]) + 1}`;116 }117 return `${requestId}-retry-1`;118}119class Http {120 constructor(opts) {121 this.preRequests = new prerequests_1.PreRequests();122 this.renderedHTMLOrigins = {};123 this.getRenderedHTMLOrigins = () => {124 return this.renderedHTMLOrigins;125 };126 this.buffers = new buffers_1.HttpBuffers();127 this.deferredSourceMapCache = new rewriter_1.DeferredSourceMapCache(opts.request);128 this.config = opts.config;129 this.shouldCorrelatePreRequests = opts.shouldCorrelatePreRequests || (() => false);130 this.getFileServerToken = opts.getFileServerToken;131 this.getRemoteState = opts.getRemoteState;132 this.middleware = opts.middleware;133 this.netStubbingState = opts.netStubbingState;134 this.socket = opts.socket;135 this.request = opts.request;136 if (typeof opts.middleware === 'undefined') {137 this.middleware = exports.defaultMiddleware;138 }139 }140 handle(req, res) {141 const ctx = {142 req,143 res,144 buffers: this.buffers,145 config: this.config,146 shouldCorrelatePreRequests: this.shouldCorrelatePreRequests,147 getFileServerToken: this.getFileServerToken,148 getRemoteState: this.getRemoteState,149 request: this.request,150 middleware: lodash_1.default.cloneDeep(this.middleware),151 netStubbingState: this.netStubbingState,152 socket: this.socket,153 debug: (formatter, ...args) => {154 debugRequests(`%s %s %s ${formatter}`, ctx.req.method, ctx.req.proxiedUrl, ctx.stage, ...args);155 },156 deferSourceMapRewrite: (opts) => {157 this.deferredSourceMapCache.defer(Object.assign({ resHeaders: ctx.incomingRes.headers }, opts));158 },159 getRenderedHTMLOrigins: this.getRenderedHTMLOrigins,160 getPreRequest: (cb) => {161 this.preRequests.get(ctx.req, ctx.debug, cb);162 },163 };164 const onError = () => {165 if (ctx.req.browserPreRequest) {166 // browsers will retry requests in the event of network errors, but they will not send pre-requests,167 // so try to re-use the current browserPreRequest for the next retry after incrementing the ID.168 const preRequest = Object.assign(Object.assign({}, ctx.req.browserPreRequest), { requestId: getUniqueRequestId(ctx.req.browserPreRequest.requestId) });169 ctx.debug('Re-using pre-request data %o', preRequest);170 this.addPendingBrowserPreRequest(preRequest);171 }172 };173 return _runStage(HttpStages.IncomingRequest, ctx, onError)174 .then(() => {175 if (ctx.incomingRes) {176 return _runStage(HttpStages.IncomingResponse, ctx, onError);177 }178 return ctx.debug('Warning: Request was not fulfilled with a response.');179 });180 }181 handleSourceMapRequest(req, res) {182 return __awaiter(this, void 0, void 0, function* () {...

Full Screen

Full Screen

client.js

Source:client.js Github

copy

Full Screen

1/* @flow */2import Relay from 'react-relay/classic';3import RequestObject from './requestObject';4type Headers = {[name: string]: string};5export type ClientNetworkLayerOpts = {6 graphqlUrl?: string,7 headers?: Headers,8 withCredentials?: boolean,9 env: Relay.Environment10};11const getUniqueRequestID = (request) => request.getID12 ? request.getID()13 : request.getVariables().input_0.clientMutationId;14export default class ClientNetworkLayer {15 url: string;16 headers: Headers;17 withCredentials: boolean;18 env: Relay.Environment;19 constructor({graphqlUrl = '/graphql', headers = {}, withCredentials = false, env}: ClientNetworkLayerOpts = {}) {20 this.url = graphqlUrl;21 this.env = env;22 this.withCredentials = withCredentials;23 this.headers = {24 'X-Requested-With': 'XMLHttpRequest',25 'Content-Type': 'application/json',26 'Accept': 'application/json',27 ...headers28 };29 }30 supports() {}31 sendQueries(queryRequests: any) {32 return Promise.all(queryRequests.map(this.sendQuery));33 }34 sendQuery = (queryRequest: any) => {35 return this.send(queryRequest.getID(), 'query', queryRequest);36 };37 sendMutation(mutationRequest: any) {38 const id = getUniqueRequestID(mutationRequest);39 return this.send(id, 'mutation', mutationRequest);40 }41 // We store the XHR as a RequestObject so that it can be retrieved and manipulated later42 _storeRequest = (xhr: XMLHttpRequest, id: string) => {43 const removeSelf = () => {44 this.env._requests.delete(id);45 };46 const endOfLifeEvents = ['error', 'abort', 'loadend', 'timeout'];47 endOfLifeEvents.forEach(event => {48 xhr.addEventListener(event, removeSelf);49 });50 const requestObj = new RequestObject({51 id,52 _xhr: xhr,53 removeSelf54 });55 this.env._requests.set(id, requestObj);56 };57 // These methods allow you to handle the promise rejection in your subclass58 // while also allowing access to the underlying xhr59 onError(xhr: XMLHttpRequest, resolve: () => void, reject: (err: Error) => void, response: Object) {60 const error = new Error(JSON.stringify(response.errors));61 reject(error);62 }63 getHeaders() { return this.headers; }64 getUrl(id: string, requestType: string, request: any): string { return this.url; } // eslint-disable-line no-unused-vars65 onLoad(xhr: XMLHttpRequest, resolve: () => void, reject: (any) => void) {66 if (xhr.status >= 400) {67 reject(new Error("Request failed"));68 return;69 }70 if (!xhr.response) {71 reject(new Error("Invalid JSON response returned from server"));72 return;73 }74 var response = xhr.response;75 if (typeof response === 'string') {76 try {77 response = JSON.parse(response);78 } catch (err) {79 reject(new Error("Invalid JSON response returned from server"));80 return;81 }82 }83 const {data} = response;84 if ('errors' in response || !data) {85 this.onError(xhr, resolve, reject, response);86 } else {87 resolve(data);88 }89 }90 send(id: string, requestType: string, request: any): Promise<*> {91 return new Promise((resolve, reject) => {92 const xhr = new XMLHttpRequest();93 xhr.open('POST', this.getUrl(id, requestType, request), true);94 xhr.responseType = 'json';95 if (this.withCredentials) {96 xhr.withCredentials = true;97 }98 xhr.addEventListener("load", () => {99 this.onLoad(xhr, resolve, reject);100 });101 xhr.addEventListener("error", () => {102 reject(new TypeError('Network request failed'));103 });104 xhr.addEventListener("abort", () => {105 reject({cancelled: true});106 });107 const headers = this.getHeaders();108 const files = request.getFiles && request.getFiles();109 var body;110 if (files) {111 var form = new FormData();112 form.append('id', id);113 form.append('query', request.getQueryString());114 form.append('variables', JSON.stringify(request.getVariables()));115 Object.keys(files).forEach(filename => {116 if (Array.isArray(files[filename])) {117 files[filename].forEach(file => {118 form.append(filename, file);119 });120 } else {121 form.append(filename, files[filename]);122 }123 });124 body = form;125 delete headers['Content-Type'];126 } else {127 body = JSON.stringify({128 id,129 query: request.getQueryString(),130 variables: request.getVariables()131 });132 }133 Object.keys(headers).forEach(name => {134 xhr.setRequestHeader(name, headers[name]);135 });136 const xhrId = getUniqueRequestID(request);137 this._storeRequest(xhr, xhrId);138 xhr.send(body);139 }).then(data => {140 request.resolve({response: data});141 return data;142 }).catch(err => {143 request.reject(err);144 });145 }...

Full Screen

Full Screen

CommonUtil.js

Source:CommonUtil.js Github

copy

Full Screen

...105 }106 /**107 * @return string108 */109 static getUniqueRequestId() {110 return _LibraryContants.LibraryConstants.NODE_SDK_TEXT + ":" + _LibraryContants.LibraryConstants.NODE_SDK_VERSION + ":" +111 uuid.v4();112 }113}...

Full Screen

Full Screen

MainServerRequestHandler.js

Source:MainServerRequestHandler.js Github

copy

Full Screen

...12 .toString('hex') /** convert to hexadecimal format */13 .slice(0, length); /** return required number of characters */14 }1516 async #getUniqueRequestId() {17 let id = this.#generateRequestId();18 while (await this.requestIdExist(id)) {19 id = this.#generateRequestId();20 }21 return id;22 }2324 removeExpectedRequest(id) {25 db.none(`DELETE FROM main_server_requests WHERE id = $1`, [id]);26 }2728 requestIdExist(id) {29 return new Promise(resolve => {30 db.any(`SELECT * FROM main_server_requests WHERE id = $1`, [id]).then(result => {31 resolve(result.length > 0);32 });33 });34 }3536 async addExpectedRequest() {37 const id = await this.#getUniqueRequestId();38 await db.none(`INSERT INTO main_server_requests (id) VALUES ($1)`, [id]);39 setTimeout(this.removeExpectedRequest, 5000, id);40 return id;41 }42}43 ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.getUniqueRequestId().then((requestId) => {2 cy.log(requestId)3})4cy.getUniqueRequestId().then((requestId) => {5 cy.log(requestId)6})7cy.getUniqueRequestId().then((requestId) => {8 cy.log(requestId)9})10cy.getUniqueRequestId().then((requestId) => {11 cy.log(requestId)12})13cy.getUniqueRequestId().then((requestId) => {14 cy.log(requestId)15})16cy.getUniqueRequestId().then((requestId) => {17 cy.log(requestId)18})19cy.getUniqueRequestId().then((requestId) => {20 cy.log(requestId)21})22cy.getUniqueRequestId().then((requestId) => {23 cy.log(requestId)24})25cy.getUniqueRequestId().then((requestId) => {26 cy.log(requestId)27})28cy.getUniqueRequestId().then((requestId) => {29 cy.log(requestId)30})31cy.getUniqueRequestId().then((requestId) => {32 cy.log(requestId)33})34cy.getUniqueRequestId().then((requestId) => {35 cy.log(requestId)36})37cy.getUniqueRequestId().then((requestId) => {38 cy.log(requestId)39})40cy.getUniqueRequestId().then((requestId) => {41 cy.log(requestId)42})43cy.getUniqueRequestId().then((requestId) => {44 cy.log(requestId)45})46cy.getUniqueRequestId().then((requestId) => {47 cy.log(requestId)48})49cy.getUniqueRequestId().then((requestId) => {50 cy.log(requestId)51})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 cy.get('input[name="q"]').type('Hello')4 cy.get('input[name="q"]').should('have.value', 'Hello')5 cy.get('input[name="q"]').type(' World')6 cy.get('input[name="q"]').should('have.value', 'Hello World')7 })8})

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('getUniqueRequestId', (requestUrl, method = 'GET', options = {}) => {2 const requestId = Cypress._.uniqueId('requestId_');3 cy.server();4 cy.route({5 onRequest: (xhr) => {6 xhr.requestId = requestId;7 },8 }).as(requestId);9 return requestId;10});11Cypress.Commands.add('getResponseForUniqueRequestId', (requestId) => {12 return cy.wait(`@${requestId}`).then((xhr) => {13 return xhr.response.body;14 });15});16Cypress.Commands.add('getResponse', (requestUrl, method = 'GET', options = {}) => {17 const requestId = Cypress._.uniqueId('requestId_');18 cy.server();19 cy.route({20 onRequest: (xhr) => {21 xhr.requestId = requestId;22 },23 }).as(requestId);24 return cy.wait(`@${requestId}`).then((xhr) => {25 return xhr.response.body;26 });27});28Cypress.Commands.add('getResponseForUniqueRequestId', (requestId) => {29 return cy.wait(`@${requestId}`).then((xhr) => {30 return xhr.response.body;31 });32});33Cypress.Commands.add('getResponse', (requestUrl, method = 'GET', options = {}) => {34 const requestId = Cypress._.uniqueId('requestId_');35 cy.server();36 cy.route({37 onRequest: (xhr) => {38 xhr.requestId = requestId;39 },40 }).as(requestId);41 return cy.wait(`@${requestId}`).then((xhr) => {42 return xhr.response.body;43 });44});45Cypress.Commands.add('getResponseForUniqueRequestId', (requestId) => {46 return cy.wait(`@${requestId}`).then((xhr) => {47 return xhr.response.body;48 });49});50Cypress.Commands.add('getResponse', (requestUrl, method =

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', function() {2 it('Test', function() {3 cy.log(requestId)4 })5 })6})7Cypress.Commands.add('getUniqueRequestId', (url) => {8 cy.server()9 cy.route(url).as('request')10 cy.wait('@request').then((xhr) => {11 cy.log(xhr.requestId)12 })13})

Full Screen

Using AI Code Generation

copy

Full Screen

1 cy.get('@request').should((request) => {2 expect(request.response.body).to.have.property('id', id)3 })4})5Cypress.Commands.add('getUniqueRequestId', (method, url) => {6 .server()7 .route({8 response: {},9 onRequest: (xhr) => {10 xhr.on('response', (res) => {11 cy.wrap(res.body.id).as('request')12 })13 },14 })15 .as('getUniqueRequestId')16})

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