Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Environment Health Check - Test Plutora SSO Login
/**************************************************************
**********ENVIRONMENT HEALTH CHECK SAMPLE SCRIPT *************
**************************************************************
The following scripts accepts a URL and SSO Credentials as parameters passed in from the UI and logs into the Plutora Application using SSO
The script executes a headless selenium script to perform the test.
The script accepts a URL, email, password and failure email address as parameters passed in from the UI and logs into Plutora using SSO
The paramaters entered into the UI need to be named as follows and are case sensitive:
- url = <The url for your instance of Plutora>
- email = <The email address for your user>
- password = <The password address for your user>
- failureEmail = <email addresses of selected email recipients if the test fails>
The outcome of your test should return the result via a Promise.Resolve();
- resolve('Online'); Sets the environment health status to 'Online'
- resolve('Offline'); Sets the environment health status to 'Offline'
- resolve('Issue'); Sets the environment health status to 'Issue'
- resolve('Unknown'); Sets the environment health status to 'Unknown'
Any thrown errors during script execution or a call to Reject will be treated as a result of Unknown
- reject(true); Sets the environment health status to 'Unknown'
The script will trigger an email notification if the test fails
*/
let run = function (args) {
//Destructure paramater values that were set from the UI
let {url, email, password, failureEmails} = args.arguments;
return new Promise(async function (resolve, reject) {
console.log('Beginning EnvironmentCheck test');
//Execute the test
let driver = chromeDriver.driver;
try {
var testResult = null;
var expectedResult = "Plutora";
await driver.manage().window().maximize();
await driver.get(url);
await driver
.wait(chromeDriver.until.elementLocated({name: 'username'}), 200000)
.catch(function (err) {
console.log(err)
});
await driver.sleep(2000);
await driver.findElement({css: '[class="pull-left col-md-3 ng-scope"] .btn-primary'}).click();
await driver.sleep(2000);
await driver.findElement({id: 'Email'}).sendKeys(email);
await driver.sleep(500);
await driver.findElement({id: "next"}).click();
await driver.sleep(1000);
await driver.findElement({id: 'Passwd'}).sendKeys(password);
await driver.sleep(500);
await driver.findElement({id: "signIn"}).click();
await driver.sleep(5000);
await driver
.wait(chromeDriver.until.elementLocated({xpath: "//*[@title='NPM Admin']"}), 20000)
.catch(function (err) {
console.log(err)
});
await driver.getTitle().then(function (title) {
console.log(title);
if (title == expectedResult) {
console.log("Test Passed");
testResult = 'Online';
} else {
console.log("Test Failed");
testResult = 'Offline';
}
});
//Optional clause to send emails if a test fails to pass.
if (testResult = 'Offline') {
await sendFailureEmail(failureEmails, "Test completed but the result was a fail.")
}
if (testResult != null) {
resolve(testResult)
}
}
catch (error) {
console.log(error);
//Optional clause to send emails if a test fails to complete.
await sendFailureEmail(failureEmails, `Test did not complete due to error: ${error}`);
reject(error);
}
console.log('Completed EnvironmentCheck test');
resolve(testResult);
});
};
const sendFailureEmail = async function (emails, message = null) {
mailData = {
to: emails, // Required - Address data can be passed as a single string with commas separating addresses or an array of single address strings. ie: ['a@a.com', 'b@b.com']
subject: 'Environment Health Check Failure - SSO_Login', //Required
body: `A failure occured during the execution of this script. <b> Bold Text </b> <i>Italicized text</i> \n\n + ${message}` //Required - This accepts HTML or standard text input.
//signature: '\n\n\nCustom email signature.' //Optional. If excluded a default Plutora signature will be appended.
};
await mailer.send(mailData);
};
module.exports = {
run: run
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.