Added files for Juan

This commit is contained in:
2024-08-07 11:37:48 -07:00
parent 09959a23a1
commit f7878e3e60
4 changed files with 304 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
import { Builder, By, Key, until } from 'selenium-webdriver';
import fs from 'fs';
import XLSX from 'xlsx';
const registerTest = (req, res) => {
res.send('<h2>The Register Test Case</h2>');
(async function example() {
let driver = await new Builder().forBrowser('chrome').build();
let testStatus = 'Failed';
try {
await driver.navigate().to('https://app-qa.journeysmap.com/UI/User/Login');
await driver.sleep(10000);
//CLICK ON THE LINK USING TARGET: linkText=here
await driver.findElement(By.linkText('here')).click();
await driver.sleep(3000);
await driver.findElement(By.id('txtFirstName')).sendKeys('Amjad', Key.RETURN); // Replace with the correct password
await driver.sleep(3000);
await driver.findElement(By.id('txtLastName')).sendKeys('Awan', Key.RETURN); // Replace with the correct password
await driver.sleep(3000);
await driver.findElement(By.css('.btn')).click();
await driver.sleep(3000);
await driver.findElement(By.linkText('with a username')).click();
await driver.sleep(3000);
await driver.findElement(By.id('txtUsername')).sendKeys('AmjadQA16', Key.RETURN);
await driver.sleep(3000);
await driver.findElement(By.css('.btn')).click();
await driver.sleep(3000);
await driver.findElement(By.id('txtPw1')).sendKeys('edmin123', Key.RETURN);
await driver.sleep(3000);
await driver.findElement(By.id('txtPw2')).sendKeys('edmin123', Key.RETURN);
await driver.sleep(3000);
await driver.findElement(By.css('.btn')).click();
await driver.sleep(3000);
await driver.findElement(By.id('txtDobMonth')).sendKeys('01', Key.RETURN);
await driver.sleep(3000);
await driver.findElement(By.id('txtDobDate')).sendKeys('15', Key.RETURN);
await driver.sleep(3000);
await driver.findElement(By.id('txtDobYear')).sendKeys('1989', Key.RETURN);
await driver.sleep(3000);
await driver.findElement(By.css('.btn')).click();
await driver.sleep(3000);
await driver.findElement(By.css('.btn')).click();
await driver.sleep(3000);
await driver.findElement(By.css('.verticalSpacing25btm:nth-child(3) > .btn')).click();
await driver.sleep(10000);
// Check if Register is successful
const logoutButton = await driver.wait(until.elementLocated(By.id('headerContainer')), 5000).catch(() => false);
if (logoutButton) {
console.log('Register successful');
testStatus = 'Passed';
} else {
console.log('Register failed');
}
// Check if testResult.xlsx exists, and if not, create a new workbook with a sheet called "Sheet1" and add the headers ["Test Case","Status"]
if (!fs.existsSync('testResult.xlsx')) {
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.json_to_sheet([]);
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
XLSX.writeFile(workbook, 'testResult.xlsx');
}
// Read the existing workbook
const workbook = XLSX.readFile('testResult.xlsx', { cellStyles: true });
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
// Get the existing data as a JSON array, and add a new object to it with the test case and status
const json_data = XLSX.utils.sheet_to_json(worksheet);
const rowIndex = json_data.length + 1;
console.log(`Row Index is ${rowIndex}`);
json_data.push({ 'Test Case': 'SignUp into the application', Status: testStatus });
// Write the updated JSON array back to the workbook and save it
const new_worksheet = XLSX.utils.json_to_sheet(json_data);
workbook.Sheets[sheetName] = new_worksheet;
const buffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'buffer' });
fs.writeFileSync('testResult.xlsx', buffer);
} finally {
await driver.quit();
}
})();
}
export default registerTest;