Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support lifecycle validation for App Assurance #336

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cypress/support/cypress-commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import UTILS, { fireLog, getEnvVariable } from '../cypress-support/src/utils';
const logger = require('../Logger')('command.js');
import { apiObject, eventObject } from '../appObjectConfigs';
const path = require('path');
const jsonAssertion = require('soft-assert');

/**
* @module commands
Expand Down Expand Up @@ -1313,6 +1314,7 @@ Cypress.Commands.add('methodOrEventResponseValidation', (validationType, request
// Helper function to handle switch case validation
const handleValidation = (object, methodOrEventObject, methodOrEventResponse = null) => {
const scenario = object.type;
console.log('2708 commands.js object >>> ', object);
if (scenario === CONSTANTS.SCHEMA_ONLY || !object.validations) return;
switch (scenario) {
case CONSTANTS.REGEX:
Expand Down Expand Up @@ -1783,3 +1785,34 @@ Cypress.Commands.add('extractAppMetadata', (appDataDir, appMetaDataFile) => {
});
});
});

/**
* @module commands
* @function softAssert
* @description soft assertion to compare actual and expected values
* @example
* cy.softAssert(actual, expected, message)
*/
Cypress.Commands.add('softAssert', (actual, expected, message) => {
jsonAssertion.softAssert(actual, expected, message);
if (jsonAssertion.jsonDiffArray.length) {
jsonAssertion.jsonDiffArray.forEach((diff) => {
Cypress.log({
name: 'Soft assertion error',
displayName: 'softAssert',
message: diff.error.message,
});
});
} else {
cy.log(`Soft assertion passed : ${message}`);
}
});

/**
* @module commands
* @function softAssertAll
* @description soft assertion to check all the assertions
* @example
* cy.softAssertAll()
*/
Cypress.Commands.add('softAssertAll', () => jsonAssertion.softAssertAll());
5 changes: 4 additions & 1 deletion cypress/support/cypress-support/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,10 @@ export default function (module) {
module.customValidations[functionName] &&
typeof module.customValidations[functionName] === 'function'
) {
message = module.customValidations[functionName](apiOrEventObject);
message = module.customValidations[functionName](
apiOrEventObject,
fcsValidationObjectData
);
} else if (
// if customValidations doesn't have a function as the functionName passed
!module.customValidations[functionName] ||
Expand Down
85 changes: 50 additions & 35 deletions cypress/support/step_definitions/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,44 +201,59 @@ Then(/'(.+)' will (be|stay) in '(.+)' state/, (app, condition, state) => {
? UTILS.getEnvVariable(CONSTANTS.FIRST_PARTY_APPID)
: app;
const isEventsExpected = condition == CONSTANTS.STAY ? false : true;
const appObject = UTILS.getEnvVariable(appId);
const scenarioName = cy.state().test.title;
const moduleReqIdJson = Cypress.env(CONSTANTS.MODULEREQIDJSON);
const featureFileName = cy.state().test.parent.title;
const scenarioList = moduleReqIdJson?.scenarioNames[featureFileName];
const validationObject = scenarioList[scenarioName]?.validationObject;
// custom validation in case of lifecycle test cases where app is not reachable
// if validationObject is present in the modReqId for the specific TC, we have to validate based on that value
try {
if (validationObject) {
if (Cypress.env(CONSTANTS.COMBINEVALIDATIONOBJECTSJSON).hasOwnProperty(validationObject)) {
// the validation type is expected to be "custom"
if (
Cypress.env(CONSTANTS.COMBINEVALIDATIONOBJECTSJSON)[validationObject]?.data[0]?.type ==
'custom'
) {
const validationObjectData = Cypress.env(CONSTANTS.COMBINEVALIDATIONOBJECTSJSON)[
validationObject
].data[0];
// passing the validationObject to perform customValidation
cy.customValidation(validationObjectData);
} else {
assert(
false,
`Expected validationObject to be of "custom" type. Current value : ${Cypress.env(CONSTANTS.COMBINEVALIDATIONOBJECTSJSON)[validationObject].data[0].type}`
);
let appObject = null;
if (Cypress.env(CONSTANTS.TEST_TYPE) == CONSTANTS.MODULE_NAMES.LIFECYCLE) {
appObject = UTILS.getEnvVariable(appId);

const scenarioName = cy.state().test.title;
const moduleReqIdJson = Cypress.env(CONSTANTS.MODULEREQIDJSON);
const featureFileName = cy.state().test.parent.title;
const scenarioList = moduleReqIdJson?.scenarioNames[featureFileName];
const validationObject = scenarioList[scenarioName]?.validationObject;
// custom validation in case of lifecycle test cases where app is not reachable
// if validationObject is present in the modReqId for the specific TC, we have to validate based on that value
try {
if (validationObject) {
if (Cypress.env(CONSTANTS.COMBINEVALIDATIONOBJECTSJSON).hasOwnProperty(validationObject)) {
// the validation type is expected to be "custom"
if (
Cypress.env(CONSTANTS.COMBINEVALIDATIONOBJECTSJSON)[validationObject]?.data[0]?.type ==
'custom'
) {
const validationObjectData = Cypress.env(CONSTANTS.COMBINEVALIDATIONOBJECTSJSON)[
validationObject
].data[0];
// passing the validationObject to perform customValidation
cy.customValidation(validationObjectData);
} else {
assert(
false,
`Expected validationObject to be of "custom" type. Current value : ${Cypress.env(CONSTANTS.COMBINEVALIDATIONOBJECTSJSON)[validationObject].data[0].type}`
);
}
}
} else {
cy.validateLifecycleState(appObject.getAppObjectState().state, appId);
cy.validateLifecycleHistoryAndEvents(
appObject.getAppObjectState().state,
appId,
isEventsExpected
);
}
} else {
cy.validateLifecycleState(appObject.getAppObjectState().state, appId);
cy.validateLifecycleHistoryAndEvents(
appObject.getAppObjectState().state,
appId,
isEventsExpected
);
} catch (error) {
throw new Error(`Error occurred during validation: ${JSON.stringify(error)}`);
}
} catch (error) {
throw new Error(`Error occurred during validation: ${JSON.stringify(error)}`);
} else {
// 2708
let validationObjectKey = Cypress.env(CONSTANTS.TEST_TYPE);
validationObjectKey = validationObjectKey.replaceAll(' ', '_').toUpperCase();
cy.getFireboltData(validationObjectKey).then((fireboltData) => {
const type = fireboltData?.event ? CONSTANTS.EVENT : CONSTANTS.METHOD;
const validationObject = UTILS.resolveRecursiveValues(fireboltData);
cy.methodOrEventResponseValidation(type, validationObject).then((response) => {
cy.softAssertAll();
});
});
}
});

Expand Down
2 changes: 2 additions & 0 deletions cypress/support/validations/screenshotValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Cypress.Commands.add('screenshotValidation', (object) => {
const failedOne = response.validations.find((valObject) => valObject.status === 'fail');
fireLog.fail(`Screenshot Validation Failed: ${failedOne.message}`);
}
} else if (object.validations.length == 0) {
cy.log('ScreenshotValidation : No validations found for screenshot.');
}
});
} else {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"setimmediate": "^1.0.5",
"shell-exec": "1.0.2",
"uuid": "^8.3.1",
"winston": "^3.8.2"
"winston": "^3.8.2",
"soft-assert": "^0.2.7"
},
"devDependencies": {
"babel-jest": "^27.4.5",
Expand Down