Added text check
This commit is contained in:
@@ -13,98 +13,115 @@ const ExACT_landingPage = (req, res) => {
|
|||||||
let worksheet;
|
let worksheet;
|
||||||
const startTime = new Date().toISOString();
|
const startTime = new Date().toISOString();
|
||||||
|
|
||||||
const steps = [
|
//Text to be verified
|
||||||
{ 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
|
const expectedText = 'Empowering publishers with the ability to correlate their unique content to standards.';
|
||||||
{ description: 'Expand browser', action: async () => await driver.manage().window().maximize() },
|
|
||||||
|
|
||||||
//Descriptive text 1
|
const steps = [
|
||||||
{ description: 'Wait for descriptive text 1 to be present', action: async () => await driver.wait(until.elementLocated(By.css('h2:nth-child(1)')), 5000) },
|
{ 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: 'Validate descriptive text 1', action: async () => await until.elementTextIs(By.css('h2:nth-child(1)', "WTF Let's start with the basics.")) },
|
{ description: 'Expand browser', action: async () => await driver.manage().window().maximize() },
|
||||||
//{ 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") },
|
|
||||||
|
|
||||||
/*
|
//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 () =>
|
||||||
|
{ const elementTitle = await driver.findElement(By.css('h2:nth-child(1)')).getText();
|
||||||
|
if (elementTitle === expectedText)
|
||||||
|
{console.log('Title matched as expected, Passed');}
|
||||||
|
else
|
||||||
|
{console.log(`Title text match FAILED, Expected: "${expectedText}", but found "${elementTitle}"`);}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
{ description: 'Enter username', action: async () => await driver.findElement(By.id('txtU')).sendKeys('gnight147', Key.RETURN) },
|
{ 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: '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: '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) },*/
|
{ description: 'Wait for login process to complete', action: async () => await driver.sleep(10000) },*/
|
||||||
];
|
];
|
||||||
|
|
||||||
const logStep = (worksheet, stepDescription, status, stepIndex, timestamp, screenshotPath) => {
|
const logStep = (worksheet, stepDescription, status, stepIndex, timestamp, screenshotPath) => {
|
||||||
const json_data = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
const json_data = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
||||||
json_data.push([stepIndex, stepDescription, status, timestamp, screenshotPath]);
|
json_data.push([stepIndex, stepDescription, status, timestamp, screenshotPath]);
|
||||||
return XLSX.utils.aoa_to_sheet(json_data);
|
return XLSX.utils.aoa_to_sheet(json_data);
|
||||||
};
|
};
|
||||||
|
|
||||||
const takeScreenshot = async (driver, stepIndex, stepDescription) => {
|
const takeScreenshot = async (driver, stepIndex, stepDescription) => {
|
||||||
const screenshot = await driver.takeScreenshot();
|
const screenshot = await driver.takeScreenshot();
|
||||||
|
|
||||||
const dir = path.join('screenshots', 'landingPageScript');
|
const dir = path.join('screenshots', 'landingPageScript');
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const screenshotFileName = `step_${stepIndex}_${stepDescription.replace(/\s+/g, '_')}.png`;
|
const screenshotFileName = `step_${stepIndex}_${stepDescription.replace(/\s+/g, '_')}.png`;
|
||||||
const screenshotPath = path.join(dir, screenshotFileName);
|
const screenshotPath = path.join(dir, screenshotFileName);
|
||||||
fs.writeFileSync(screenshotPath, screenshot, 'base64');
|
fs.writeFileSync(screenshotPath, screenshot, 'base64');
|
||||||
return screenshotPath;
|
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 {
|
try {
|
||||||
// Initialize workbook and worksheet
|
await step.action();
|
||||||
if (!fs.existsSync('landingPageResults.xlsx')) {
|
const screenshotPath = await takeScreenshot(driver, stepIndex, step.description);
|
||||||
workbook = XLSX.utils.book_new();
|
worksheet = logStep(worksheet, step.description, 'Passed', stepIndex, timestamp, screenshotPath);
|
||||||
worksheet = XLSX.utils.aoa_to_sheet([
|
} catch (error) {
|
||||||
['Step Number', 'Step Description', 'Status', 'Timestamp', 'Screenshot']
|
const screenshotPath = await takeScreenshot(driver, stepIndex, `${step.description}_Failed`);
|
||||||
]);
|
worksheet = logStep(worksheet, step.description, 'Failed', stepIndex, timestamp, screenshotPath);
|
||||||
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
|
throw error; // Re-throw the error to stop further execution if necessary
|
||||||
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 loginButton = await driver.wait(until.elementLocated(By.css('.login')), 5000).catch(() => false);
|
|
||||||
|
|
||||||
if (loginButton) {
|
|
||||||
console.log('Login button present');
|
|
||||||
testStatus = 'Passed';
|
|
||||||
} else {
|
|
||||||
console.log('Login button not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
|
|
||||||
|
// Check if landing page test was successful
|
||||||
|
const loginButton = await driver.wait(until.elementLocated(By.css('.login')), 5000).catch(() => false);
|
||||||
|
|
||||||
|
if (loginButton) {
|
||||||
|
console.log('Login button present');
|
||||||
|
testStatus = 'Passed';
|
||||||
|
} else {
|
||||||
|
console.log('Login button not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
const freeTialButton = await driver.wait(until.elementLocated(By.css('.btn > span')), 5000).catch(() => false);
|
||||||
|
|
||||||
|
if (freeTialButton) {
|
||||||
|
console.log('Free Trial button present');
|
||||||
|
testStatus = 'Passed';
|
||||||
|
} else {
|
||||||
|
console.log('Free Trial button not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
export default ExACT_landingPage;
|
||||||
|
|||||||
Reference in New Issue
Block a user