Skip to content

Commit

Permalink
feat: Dismiss implementation for logged in and logged out apps (#298)
Browse files Browse the repository at this point in the history
Co-authored-by: Abhishek urs C J <[email protected]>
Co-authored-by: neeradanelxsi <[email protected]>
  • Loading branch information
3 people authored Jan 24, 2025
1 parent 7e30f61 commit 74cbe76
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 119 deletions.
29 changes: 24 additions & 5 deletions cypress/fixtures/docs/app_metadata.json
Original file line number Diff line number Diff line change
@@ -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": "<entityId>",
"keyPressSequence": {
"dismiss": ["exit", "exit", "exit"]
"loggedOut": {
"dismiss": ["exit", "right", "enter"]
},
"loggedIn": {
"dismiss": ["exit", "right", "enter"]
}


}
},
"defaultKeyPressSequence": {
"dismiss": ["exit", "exit", "exit"]
}
}

Expand Down
5 changes: 5 additions & 0 deletions cypress/support/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cypress/support/step_definitions/dynamicCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`
);
}
});
Expand Down
104 changes: 78 additions & 26 deletions cypress/support/step_definitions/fireboltCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
});
Expand Down
183 changes: 97 additions & 86 deletions cypress/support/step_definitions/testSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 74cbe76

Please sign in to comment.