Added scripts

This commit is contained in:
2024-09-26 15:20:31 -07:00
parent a54ddc07cb
commit 500662707b
8 changed files with 2478 additions and 0 deletions

2
ExACTRegressionScripts/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules
screenshots

View File

@@ -0,0 +1,30 @@
import express from 'express';
//import authentication test scripts
//import loginTest from './tests/login.js';
import ExACT_landingPage from './tests/ExACT_landingPage.js';
const app = express();
app.get('/', (req, res) => {
res.send(`
<div style="text-align:center; background:#ccc;" width="100%">
<h1 style="text-align:center; color:#055a8c; padding-top: 40px;">ExACT</h1>
<h1 style="text-align:center; color:#001; padding-top: 10px;">Click the corresponding link to exeucate the desired automated test case script:</h1>
<br><div style="padding:3px;"><strong><a href='/ExACT_landingPage' target='_blank'>Landing Page</a></strong></div>
<br>
<br>
</div>
`);
})
//Authentication Test Automations Routes
//app.get('/login', loginTest);
app.get('/ExACT_landingPage', ExACT_landingPage);
app.listen(8000, () => {
console.log('Server is running on port 8000');
});

Binary file not shown.

2314
ExACTRegressionScripts/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
{
"name": "testingflow",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"dev": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"chromedriver": "^126.0.4",
"express": "^4.19.2",
"geckodriver": "^4.4.1",
"nodemon": "^3.1.0",
"selenium-webdriver": "^4.22.0",
"xlsx": "^0.18.5"
}
}

View File

View File

@@ -0,0 +1,110 @@
import { Builder, By, Key, until } from 'selenium-webdriver';
import fs from 'fs';
import XLSX from 'xlsx';
import path from 'path';
import { assert } from 'console';
const ExACT_landingPage = (req, res) => {
res.send('<h2>ExACT Automated Test Script - Landing Page: Excecuted</h2>');
(async function example() {
let driver = await new Builder().forBrowser('chrome').build();
let testStatus = 'Failed';
let workbook;
let worksheet;
const startTime = new Date().toISOString();
const steps = [
{ description: 'Navigate to ExACT Landing Page', action: async () => await driver.navigate().to('https://stage.edgate.com/exact/login.php') }, //PROD - https://correlation.edgate.com/exact/login.php
{ description: 'Expand browser', action: async () => await driver.manage().window().maximize() },
//Descriptive text 1
{ description: 'Wait for descriptive text 1 to be present', action: async () => await driver.wait(until.elementLocated(By.css('h2:nth-child(1)')), 5000) },
//{ description: 'Validate descriptive text 1', action: async () => await until.elementTextIs(By.css('h2:nth-child(1)', "WTF Let's start with the basics.")) },
//{ description: 'Validate descriptive text 1', action: elementTextIs(By.css('h2:nth-child(1)', "Empowering publishers with the ability to correlate their unique content to standards."))},
//{ String actualText = driver.findElement(By.css('h2:nth-child(1)')).getAttribute("value")},
//{ description: 'Validate descriptive text 1', action: async () => await driver.findElement(By.css('h2:nth-child(1)'), "wtf") },
/*
{ description: 'Enter username', action: async () => await driver.findElement(By.id('txtU')).sendKeys('gnight147', Key.RETURN) },
{ description: 'Wait for password field to be present', action: async () => await driver.sleep(3000) },
{ description: 'Enter password', action: async () => await driver.findElement(By.id('txtP')).sendKeys('EDmin123', Key.RETURN) },
{ description: 'Wait for login process to complete', action: async () => await driver.sleep(10000) },*/
];
const logStep = (worksheet, stepDescription, status, stepIndex, timestamp, screenshotPath) => {
const json_data = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
json_data.push([stepIndex, stepDescription, status, timestamp, screenshotPath]);
return XLSX.utils.aoa_to_sheet(json_data);
};
const takeScreenshot = async (driver, stepIndex, stepDescription) => {
const screenshot = await driver.takeScreenshot();
const dir = path.join('screenshots', 'landingPageScript');
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
const screenshotFileName = `step_${stepIndex}_${stepDescription.replace(/\s+/g, '_')}.png`;
const screenshotPath = path.join(dir, screenshotFileName);
fs.writeFileSync(screenshotPath, screenshot, 'base64');
return screenshotPath;
};
try {
// Initialize workbook and worksheet
if (!fs.existsSync('landingPageResults.xlsx')) {
workbook = XLSX.utils.book_new();
worksheet = XLSX.utils.aoa_to_sheet([
['Step Number', 'Step Description', 'Status', 'Timestamp', 'Screenshot']
]);
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
XLSX.writeFile(workbook, 'landingPageResults.xlsx');
} else {
workbook = XLSX.readFile('landingPageResults.xlsx', { cellStyles: true });
const sheetName = workbook.SheetNames[0];
worksheet = workbook.Sheets[sheetName];
}
// Log test start time
worksheet = logStep(worksheet, 'Test Start', 'Started', '', startTime, '');
for (const step of steps) {
const stepIndex = steps.indexOf(step) + 1;
const timestamp = new Date().toISOString();
try {
await step.action();
const screenshotPath = await takeScreenshot(driver, stepIndex, step.description);
worksheet = logStep(worksheet, step.description, 'Passed', stepIndex, timestamp, screenshotPath);
} catch (error) {
const screenshotPath = await takeScreenshot(driver, stepIndex, `${step.description}_Failed`);
worksheet = logStep(worksheet, step.description, 'Failed', stepIndex, timestamp, screenshotPath);
throw error; // Re-throw the error to stop further execution if necessary
}
}
// Check if landing page test was successful
const logoutButton = await driver.wait(until.elementLocated(By.id('headerContainer')), 5000).catch(() => false);
if (logoutButton) {
console.log('Login successful');
testStatus = 'Passed';
} else {
console.log('Login failed');
}
// Log test end time
const endTime = new Date().toISOString();
worksheet = logStep(worksheet, 'Test End', 'Ended', '', endTime, '');
// Write the updated worksheet back to the workbook and save it
workbook.Sheets['Sheet1'] = worksheet;
XLSX.writeFile(workbook, 'landingPageResults.xlsx');
} finally {
await driver.quit();
}
})();
}
export default ExACT_landingPage;

View File