From 74cbe7609f3d47d7300acfb07004e65f0b894c4a Mon Sep 17 00:00:00 2001 From: anjali <47880722+anjalimukundan@users.noreply.github.com> Date: Fri, 24 Jan 2025 10:30:34 +0530 Subject: [PATCH] feat: Dismiss implementation for logged in and logged out apps (#298) Co-authored-by: Abhishek urs C J Co-authored-by: neeradanelxsi --- cypress/fixtures/docs/app_metadata.json | 29 ++- cypress/support/constants/constants.js | 5 + .../support/step_definitions/dynamicCalls.js | 4 +- .../support/step_definitions/fireboltCalls.js | 104 +++++++--- cypress/support/step_definitions/testSetup.js | 183 ++++++++++-------- 5 files changed, 206 insertions(+), 119 deletions(-) diff --git a/cypress/fixtures/docs/app_metadata.json b/cypress/fixtures/docs/app_metadata.json index 80dc9ea6..61e99ecf 100644 --- a/cypress/fixtures/docs/app_metadata.json +++ b/cypress/fixtures/docs/app_metadata.json @@ -1,16 +1,35 @@ { "defaultKeyPressSequence": { - "dismiss": ["exit", "exit", "exit"] + "dismiss": { + "loggedIn":{ + "dismiss": ["exit", "exit", "exit"] + }, + "loggedOut": { + "dismiss": ["exit", "exit", "exit"] + } + }, + "playbackDismiss": { + "loggedIn":{ + "dismiss": ["exit"] + }, + "loggedOut": { + "dismiss": ["exit"] + } + } }, "appId": { "intentName": { "entityId": "", "keyPressSequence": { - "dismiss": ["exit", "exit", "exit"] + "loggedOut": { + "dismiss": ["exit", "right", "enter"] + }, + "loggedIn": { + "dismiss": ["exit", "right", "enter"] + } + + } - }, - "defaultKeyPressSequence": { - "dismiss": ["exit", "exit", "exit"] } } diff --git a/cypress/support/constants/constants.js b/cypress/support/constants/constants.js index d61c65ca..c79a0b6d 100644 --- a/cypress/support/constants/constants.js +++ b/cypress/support/constants/constants.js @@ -529,6 +529,11 @@ module.exports = { FOREGROUND: 'FOREGROUND', PERFORMANCE_VALIDATION: 'performanceValidation', MARKER_CREATION_STATUS: 'markerCreationStatus', + PLAYBACK: 'playback', + LOGGEDIN: 'loggedIn', + LOGGEDOUT: 'loggedOut', + SCENARIO_TYPE: 'scenarioType', + DISMISS: 'dismiss', }; function getSanityReportPath() { // Check if Cypress is defined, for cypress test context diff --git a/cypress/support/step_definitions/dynamicCalls.js b/cypress/support/step_definitions/dynamicCalls.js index 6393554d..82024936 100644 --- a/cypress/support/step_definitions/dynamicCalls.js +++ b/cypress/support/step_definitions/dynamicCalls.js @@ -406,11 +406,11 @@ Given(/'(.+)' (on|with) '(.+)' page/, (validationObjectKey, type, page) => { cy.sendMessagetoPlatforms(requestMap).then((response) => { if (response.appState.toUpperCase() === CONSTANTS.FOREGROUND) { fireLog.info( - `State validation successful: Current state of ${appId} app is ${response} as expected` + `State validation successful: Current state of ${appId} app is ${JSON.stringify(response)} as expected` ); } else { fireLog.fail( - `State validation failed: Current state of ${appId} app is ${response}, expected to be ${CONSTANTS.FOREGROUND}.` + `State validation failed: Current state of ${appId} app is ${JSON.stringify(response)}, expected to be ${CONSTANTS.FOREGROUND}.` ); } }); diff --git a/cypress/support/step_definitions/fireboltCalls.js b/cypress/support/step_definitions/fireboltCalls.js index 0bee085e..7640ffb1 100644 --- a/cypress/support/step_definitions/fireboltCalls.js +++ b/cypress/support/step_definitions/fireboltCalls.js @@ -377,33 +377,85 @@ Given('device is rebooted', () => { Given(/3rd party '(.+)' app is dismissed$/, async (appType) => { const appId = Cypress.env(CONSTANTS.RUNTIME).appId; let KeyPressSequence; - if ( - // Check if keyPressSequence is defined in the runtime environment variables for the specific intent - Cypress.env(CONSTANTS.RUNTIME) && - Cypress.env(CONSTANTS.RUNTIME).intent && - Cypress.env(CONSTANTS.RUNTIME).intent.keyPressSequence - ) { - KeyPressSequence = Cypress.env(CONSTANTS.RUNTIME).intent.keyPressSequence; - } else if ( - // Check if defaultKeyPressSequence is defined for the specific appId in app_metadata - Cypress.env('app_metadata') && - Cypress.env('app_metadata')[appId] && - Cypress.env('app_metadata')[appId].defaultKeyPressSequence - ) { - KeyPressSequence = Cypress.env('app_metadata')[appId].defaultKeyPressSequence; - } else if ( - // Check if defaultKeyPressSequence is defined in the app_metadata globally - Cypress.env('app_metadata') && - Cypress.env('app_metadata').defaultKeyPressSequence - ) { - KeyPressSequence = Cypress.env('app_metadata').defaultKeyPressSequence; - } else { - // If no keyPressSequence is found, throw an error with details from the app_metadata file - const appMetadataJSON = require('../../fixtures/docs/app_metadata.json'); - throw new Error( - `Expected KeyPressSequence was not found for ${appId} in app_metadata.json. More details on app_metadata present in: ${appMetadataJSON}` - ); + let loggedType; + + const test = Cypress.env(CONSTANTS.TEST_TYPE); + const testLowerCase = test.toLowerCase(); + const scenarioType = Cypress.env(CONSTANTS.SCENARIO_TYPE); + const scenarioTypeLowerCase = scenarioType.toLowerCase(); + + if (testLowerCase.includes(CONSTANTS.DISMISS)) { + if (Cypress.env(CONSTANTS.SCENARIO_TYPE)) { + // playback dismiss + if (testLowerCase.includes(CONSTANTS.PLAYBACK)) { + if ( + Cypress.env(CONSTANTS.APP_METADATA) && + Cypress.env(CONSTANTS.APP_METADATA).defaultKeyPressSequence && + Cypress.env(CONSTANTS.APP_METADATA).defaultKeyPressSequence.playbackDismiss + ) { + playbackDismiss = Cypress.env(CONSTANTS.APP_METADATA).defaultKeyPressSequence + .playbackDismiss; + if (playbackDismiss.loggedIn) { + KeyPressSequence = playbackDismiss.loggedIn; + } else if (playbackDismiss.loggedOut) { + KeyPressSequence = playbackDismiss.loggedOut; + } + } + } else { + // other dismiss cases + + // check whether app is loggedIn or loggedOut + if (scenarioTypeLowerCase.includes(CONSTANTS.LOGGEDIN.toLowerCase())) { + loggedType = CONSTANTS.LOGGEDIN; + } else if (test.includes(CONSTANTS.LOGGEDOUT.toLowerCase())) { + loggedType = CONSTANTS.LOGGEDOUT; + } + + if ( + // Check if keyPressSequence is defined in the runtime environment variables for the specific intent + !KeyPressSequence && + Cypress.env(CONSTANTS.RUNTIME) && + Cypress.env(CONSTANTS.RUNTIME).intent && + Cypress.env(CONSTANTS.RUNTIME).intent.keyPressSequence && + Cypress.env(CONSTANTS.RUNTIME).intent.keyPressSequence[loggedType] + ) { + KeyPressSequence = Cypress.env(CONSTANTS.RUNTIME).intent.keyPressSequence[loggedType]; + } else if ( + // Check if defaultKeyPressSequence is defined for the specific appId in app_metadata + !KeyPressSequence && + Cypress.env(CONSTANTS.APP_METADATA) && + Cypress.env(CONSTANTS.APP_METADATA)[appId] && + Cypress.env(CONSTANTS.APP_METADATA)[appId].defaultKeyPressSequence && + Cypress.env(CONSTANTS.APP_METADATA)[appId].defaultKeyPressSequence[loggedType] + ) { + KeyPressSequence = Cypress.env(CONSTANTS.APP_METADATA)[appId].defaultKeyPressSequence[ + loggedType + ]; + } else if ( + // Check if defaultKeyPressSequence is defined in the app_metadata globally + !KeyPressSequence && + Cypress.env(CONSTANTS.APP_METADATA) && + Cypress.env(CONSTANTS.APP_METADATA).defaultKeyPressSequence && + Cypress.env(CONSTANTS.APP_METADATA).defaultKeyPressSequence.dismiss && + Cypress.env(CONSTANTS.APP_METADATA).defaultKeyPressSequence.dismiss[loggedType] + ) { + KeyPressSequence = Cypress.env(CONSTANTS.APP_METADATA).defaultKeyPressSequence.dismiss[ + loggedType + ]; + } else { + // If no keyPressSequence is found, throw an error with details from the app_metadata file + const appMetadataJSON = require('../../fixtures/docs/app_metadata.json'); + throw new Error( + `Expected KeyPressSequence was not found for ${appId} in app_metadata.json. More details on app_metadata present in: ${appMetadataJSON}` + ); + } + } + } else { + // when test is Dimiss and scenarioType is not present + fireLog.fail('Scenario type is not defined in the runtime environment variables'); + } } + cy.exitAppSession('dismissApp', KeyPressSequence.dismiss).then((response) => { fireLog.info(`Response from platform: ${JSON.stringify(response)}`); }); diff --git a/cypress/support/step_definitions/testSetup.js b/cypress/support/step_definitions/testSetup.js index d1462be3..ad280b4d 100644 --- a/cypress/support/step_definitions/testSetup.js +++ b/cypress/support/step_definitions/testSetup.js @@ -30,105 +30,116 @@ const { _ } = Cypress; * @example * Given the environment has been set up for 'Firebolt Sanity' tests */ -Given('the environment has been set up for {string} tests', (test) => { - const runtime = {}; +Given( + /^the environment has been set up for '([^']+)' tests(?: (for|with) '([^']+)')?$/, - // Check if the test parameter is provided - if (test) { - let fireboltCallKey; - // Check if the test parameter contains a colon to split into module and method - if (test.includes(':')) { - const [module, method] = test.split(':'); - fireboltCallKey = module.toUpperCase(); - Object.assign(runtime, { method, module }); - } else { - // Replace spaces with underscores and convert to uppercase for the fireboltCallKey - fireboltCallKey = test.replace(/\s+/g, '_').toUpperCase(); + async (test, type, scenarioType) => { + const runtime = {}; + + // Check if the test parameter is provided + if (test) { + let fireboltCallKey; + // Check if the test parameter contains a colon to split into module and method + if (test.includes(':')) { + const [module, method] = test.split(':'); + fireboltCallKey = module.toUpperCase(); + Object.assign(runtime, { method, module }); + } else { + // Replace spaces with underscores and convert to uppercase for the fireboltCallKey + fireboltCallKey = test.replace(/\s+/g, '_').toUpperCase(); + } + // Retrieve the firebolt object from environment variables using the fireboltCallKey + const fireboltObject = UTILS.getEnvVariable(CONSTANTS.COMBINEDFIREBOLTCALLS)[fireboltCallKey]; + if (fireboltObject) { + // Update the runtime environment variable with the firebolt object + runtime.fireboltCall = fireboltObject; + Cypress.env(CONSTANTS.RUNTIME, runtime); + fireLog.info(`Firebolt object successfully updated in runtime environment variable`); + } } - // Retrieve the firebolt object from environment variables using the fireboltCallKey - const fireboltObject = UTILS.getEnvVariable(CONSTANTS.COMBINEDFIREBOLTCALLS)[fireboltCallKey]; - if (fireboltObject) { - // Update the runtime environment variable with the firebolt object - runtime.fireboltCall = fireboltObject; - Cypress.env(CONSTANTS.RUNTIME, runtime); - fireLog.info(`Firebolt object successfully updated in runtime environment variable`); + Cypress.env(CONSTANTS.PREVIOUS_TEST_TYPE, Cypress.env(CONSTANTS.TEST_TYPE)); + Cypress.env(CONSTANTS.TEST_TYPE, test); + Cypress.env(CONSTANTS.SCENARIO_TYPE, scenarioType); + + if ( + UTILS.getEnvVariable(CONSTANTS.PENDING_FEATURES).includes( + JSON.stringify(window.testState.gherkinDocument.feature.name) + ) + ) { + return 'pending'; } - } - Cypress.env(CONSTANTS.PREVIOUS_TEST_TYPE, Cypress.env(CONSTANTS.TEST_TYPE)); - Cypress.env(CONSTANTS.TEST_TYPE, test); - if ( - UTILS.getEnvVariable(CONSTANTS.PENDING_FEATURES).includes( - JSON.stringify(window.testState.gherkinDocument.feature.name) - ) - ) { - return 'pending'; - } - // Calling the envConfigSetup command to setup the environment for the test from the config module. - cy.envConfigSetup(); + // Calling the envConfigSetup command to setup the environment for the test from the config module. + cy.envConfigSetup(); - if ( - !UTILS.getEnvVariable(CONSTANTS.ENV_SETUP_STATUS, false) || - UTILS.getEnvVariable(CONSTANTS.LIFECYCLE_CLOSE_TEST_TYPES).includes(test) || - UTILS.getEnvVariable(CONSTANTS.UNLOADING_APP_TEST_TYPES).includes(test) - ) { - if (test.toLowerCase() == CONSTANTS.MODULE_NAMES.LIFECYCLEAPI) { - Cypress.env(CONSTANTS.LIFECYCLE_VALIDATION, true); - } + if ( + !UTILS.getEnvVariable(CONSTANTS.ENV_SETUP_STATUS, false) || + UTILS.getEnvVariable(CONSTANTS.LIFECYCLE_CLOSE_TEST_TYPES).includes(test) || + UTILS.getEnvVariable(CONSTANTS.UNLOADING_APP_TEST_TYPES).includes(test) + ) { + if (test.toLowerCase() == CONSTANTS.MODULE_NAMES.LIFECYCLEAPI) { + Cypress.env(CONSTANTS.LIFECYCLE_VALIDATION, true); + } - if (test == CONSTANTS.SETUPCHECK) { - UTILS.getSetupDetails(); - } + if (test == CONSTANTS.SETUPCHECK) { + UTILS.getSetupDetails(); + } - destroyAppInstance(test); - Cypress.env(CONSTANTS.ENV_SETUP_STATUS, true); - if (Cypress.env(CONSTANTS.TEST_TYPE).includes('rpc-Only')) { - Cypress.env(CONSTANTS.IS_RPC_ONLY, true); - } - // fetch device details dynamically - if (Cypress.env(CONSTANTS.FETCH_DEVICE_DETAILS_DYNAMICALLY_FLAG)) { - if ( - UTILS.getEnvVariable(CONSTANTS.DYNAMIC_DEVICE_DETAILS_MODULES).includes( - Cypress.env(CONSTANTS.TEST_TYPE) - ) - ) { - cy.getDeviceData(CONSTANTS.DEVICE_ID, {}, CONSTANTS.ACTION_CORE.toLowerCase()).then( - (response) => { - if (response) { - const method = CONSTANTS.REQUEST_OVERRIDE_CALLS.FETCHDEVICEDETAILS; - const requestMap = { - method: method, - params: response, - }; - cy.sendMessagetoPlatforms(requestMap); + destroyAppInstance(test); + Cypress.env(CONSTANTS.ENV_SETUP_STATUS, true); + if (Cypress.env(CONSTANTS.TEST_TYPE).includes('rpc-Only')) { + Cypress.env(CONSTANTS.IS_RPC_ONLY, true); + } + // fetch device details dynamically + if (Cypress.env(CONSTANTS.FETCH_DEVICE_DETAILS_DYNAMICALLY_FLAG)) { + if ( + UTILS.getEnvVariable(CONSTANTS.DYNAMIC_DEVICE_DETAILS_MODULES).includes( + Cypress.env(CONSTANTS.TEST_TYPE) + ) + ) { + cy.getDeviceData(CONSTANTS.DEVICE_ID, {}, CONSTANTS.ACTION_CORE.toLowerCase()).then( + (response) => { + if (response) { + const method = CONSTANTS.REQUEST_OVERRIDE_CALLS.FETCHDEVICEDETAILS; + const requestMap = { + method: method, + params: response, + }; + cy.sendMessagetoPlatforms(requestMap); + } } - } - ); + ); + } } } - } - // Check the marker creation status - if (UTILS.getEnvVariable(CONSTANTS.PERFORMANCE_METRICS)) { - const markerCreated = Cypress.env(CONSTANTS.MARKER_CREATION_STATUS); - if (markerCreated) { - fireLog.info('Marker has been created successfully'); - } else { - fireLog.fail('Marker creation failed'); + // Check the marker creation status + if (UTILS.getEnvVariable(CONSTANTS.PERFORMANCE_METRICS)) { + const markerCreated = Cypress.env(CONSTANTS.MARKER_CREATION_STATUS); + if (markerCreated) { + fireLog.info('Marker has been created successfully'); + } else { + fireLog.fail('Marker creation failed'); + } } - } + const testLowerCase = test.toLowerCase(); + const externalModuleTestTypes = Cypress.env(CONSTANTS.EXTERNAL_MODULE_TESTTYPES); - if ( - Cypress.env(CONSTANTS.EXTERNAL_MODULE_TESTTYPES).includes(test) && - !Cypress.env(CONSTANTS.INTENT_TEMPLATES) && - !Cypress.env(CONSTANTS.APP_METADATA) - ) { - cy.fetchAppMetaData().then((appMetaData) => { - Cypress.env(CONSTANTS.APP_METADATA, appMetaData); - }); - const combinedIntentTemplates = _.merge(internalIntentTemplates, externalIntentTemplates); - Cypress.env(CONSTANTS.INTENT_TEMPLATES, combinedIntentTemplates); + if ( + externalModuleTestTypes.some( + (item) => + typeof item === 'string' && testLowerCase.toLowerCase().includes(item.toLowerCase()) + ) && + !Cypress.env(CONSTANTS.INTENT_TEMPLATES) && + !Cypress.env(CONSTANTS.APP_METADATA) + ) { + cy.fetchAppMetaData().then((appMetaData) => { + Cypress.env(CONSTANTS.APP_METADATA, appMetaData); + }); + const combinedIntentTemplates = _.merge(internalIntentTemplates, externalIntentTemplates); + Cypress.env(CONSTANTS.INTENT_TEMPLATES, combinedIntentTemplates); + } } -}); +); /** * @module TestSetupGlue