diff --git a/cypress/support/constants/constants.js b/cypress/support/constants/constants.js index 3950a184..fdea670f 100644 --- a/cypress/support/constants/constants.js +++ b/cypress/support/constants/constants.js @@ -501,6 +501,7 @@ module.exports = { SET_EVENT_SUCCESS: 'Event value set successfully in platform', SCENARIO_NAME: 'scenarioName', FIREBOLT_INTERACTION: 'FireboltInteraction', + PERFORMANCE_VALIDATION: 'performanceValidation', }; function getSanityReportPath() { // Check if Cypress is defined, for cypress test context diff --git a/cypress/support/cypress-commands/commands.js b/cypress/support/cypress-commands/commands.js index 93b960ca..578f9c7a 100644 --- a/cypress/support/cypress-commands/commands.js +++ b/cypress/support/cypress-commands/commands.js @@ -1265,6 +1265,9 @@ Cypress.Commands.add('methodOrEventResponseValidation', (validationType, request case CONSTANTS.SCREENSHOT_VALIDATION: cy.screenshotValidation(object); break; + case CONSTANTS.PERFORMANCE_VALIDATION: + cy.performanceValidation(object); + break; default: assert(false, 'Unsupported validation type'); break; diff --git a/cypress/support/cypress-support/src/main.js b/cypress/support/cypress-support/src/main.js index cc22e41e..006ee084 100644 --- a/cypress/support/cypress-support/src/main.js +++ b/cypress/support/cypress-support/src/main.js @@ -89,15 +89,6 @@ export default function (module) { Cypress.env(CONSTANTS.MESSAGE_QUEUE, messageQueue); UTILS.parseExceptionList(); cy.getModuleReqIdJson(); - if (UTILS.getEnvVariable(CONSTANTS.PERFORMANCE_METRICS) == true) { - cy.startOrStopPerformanceService(CONSTANTS.INITIATED).then((response) => { - if (response) { - Cypress.env(CONSTANTS.IS_PERFORMANCE_METRICS_ENABLED, true); - } - }); - } else { - cy.log(CONSTANTS.PERFORMANCE_METRICS_NOT_ACTIVE); - } // Merge fireboltCalls const v1FireboltCallsData = UTILS.getEnvVariable('fireboltCallsJson'); @@ -132,8 +123,36 @@ export default function (module) { // beforeEach beforeEach(() => { UTILS.getEnvVariable(CONSTANTS.FB_INTERACTIONLOGS).clearLogs(); - cy.getBeforeOperationObject(); - UTILS.destroyGlobalObjects([CONSTANTS.LIFECYCLE_APP_OBJECT_LIST]); + + cy.getBeforeOperationObject().then(() => { + const scenarioName = Cypress.env(CONSTANTS.SCENARIO_NAME); + + UTILS.destroyGlobalObjects([CONSTANTS.LIFECYCLE_APP_OBJECT_LIST]); + + if (UTILS.getEnvVariable(CONSTANTS.PERFORMANCE_METRICS) === true) { + if (scenarioName) { + const requestMap = { + method: CONSTANTS.REQUEST_OVERRIDE_CALLS.CREATE_MARKER, + params: scenarioName, + }; + fireLog.info(`Firebolt Call to 1st party App: ${JSON.stringify(requestMap)} `); + cy.sendMessagetoPlatforms(requestMap).then((result) => { + fireLog.isTrue( + result.success, + 'Response for marker creation: ' + JSON.stringify(result) + ); + }); + + cy.startOrStopPerformanceService(CONSTANTS.INITIATED).then((response) => { + if (response) { + Cypress.env(CONSTANTS.IS_PERFORMANCE_METRICS_ENABLED, true); + } + }); + } + } else { + cy.log(CONSTANTS.PERFORMANCE_METRICS_NOT_ACTIVE); + } + }); }); /** @@ -242,6 +261,17 @@ export default function (module) { })(); }); + // after each + afterEach(() => { + if (UTILS.getEnvVariable(CONSTANTS.IS_PERFORMANCE_METRICS_ENABLED, false) == true) { + cy.startOrStopPerformanceService(CONSTANTS.STOPPED).then((response) => { + if (response) { + Cypress.env(CONSTANTS.IS_PERFORMANCE_METRICS_ENABLED, false); + } + }); + } + }); + /** * @module main * @function sendMessagetoPlatforms diff --git a/cypress/support/validations/index.js b/cypress/support/validations/index.js index 9b59e354..36bac797 100644 --- a/cypress/support/validations/index.js +++ b/cypress/support/validations/index.js @@ -20,4 +20,5 @@ import './decodeValidation'; import './regExValidation'; import './schemaValidation'; import './undefinedValidation'; +import './performanceValidation'; import './screenshotValidation'; diff --git a/cypress/support/validations/performanceValidation.js b/cypress/support/validations/performanceValidation.js new file mode 100644 index 00000000..49ea6913 --- /dev/null +++ b/cypress/support/validations/performanceValidation.js @@ -0,0 +1,46 @@ +/** + * Copyright 2024 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +const CONSTANTS = require('../constants/constants'); +const UTILS = require('../cypress-support/src/utils'); + +Cypress.Commands.add('performanceValidation', (object) => { + if (UTILS.getEnvVariable('performanceMetrics')) { + const { type, process, percentile, threshold } = object.validations[0]; + const requestMap = { + method: CONSTANTS.REQUEST_OVERRIDE_CALLS.PERFORMANCE_THRESHOLD_VALIDATOR, + params: { type, process, percentile, threshold }, + }; + + cy.sendMessagetoPlatforms(requestMap).then((result) => { + if (result.error) { + cy.log('Failed to fetch and validate the performance metrics').then(() => { + assert(false, result.error); + }); + } else { + result.map((response) => { + cy.log(response.message).then(() => { + assert.equal(true, response?.success, response?.message); + }); + }); + } + }); + } else { + fireLog.info('performanceMetrics are disabled.'); + } +});