From e763e8ae45fc45dba5e4089fff8572b7159ac1d4 Mon Sep 17 00:00:00 2001 From: AShahzad Date: Thu, 10 Oct 2024 22:56:10 +0500 Subject: [PATCH] Updated code for login.js to fix the pass and fail status issue in excel file as well old results and screenshots will be removed now in every test execution --- landingPageResults.xlsx | Bin 3597590 -> 6952120 bytes loginResults.xlsx | Bin 26006 -> 26006 bytes tests/ExACT_login.js | 86 +++++++++++++++++++++++++++++++--------- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/landingPageResults.xlsx b/landingPageResults.xlsx index ed4d70e52c52a284e33d5bbf11f148ce8cd306f1..d0cd458ec1ac9e21eea2cd37fa7b4280d6ff9b30 100644 GIT binary patch delta 7500 zcmeHMe{56N6~^&M>2MNfDsd1Cu|pCdgy;9(z30B?kdT;BZ7SnOs#faQXkt|ZEo;}n zR93W3O*WRaTM)?~&1r>H@H#D9rWUdSW~EvQYSpe|qfw=msjA`>)^*xS6NySg)ymGj z4#{<%X{||Y|0Igz7w5k3eD}NOJLf!Q@b$NSr+)QI|FMq?7Ju~afuj#s>|8*v=L`KO zel(P>4F-qOe=epUwZZnGmOw?z%x5O1M~b?T{@QZ#fk;bv-NaONy`kGPdTpfp2hjCD-3vIjQ0fcytgQyb*b^5BCjvfg~j>YJe2Oqb6sJH zXCwKFl`af^2A32i#)|Ze@Y4mPx3BIq?vr=45A_Dtrx&CeYsG;f zJo2)*H4v*>-*{hmPg7OgwQ-=8SNL5!h68)q$^v>%*0U7_^oP;!^0J6!-eoxroW8+u zW3lax(Y@;%qxVhUe>*Lknqbu>E;DB_nTcnvuqA%_5O?3n8VX#77V;H77ZZIvq+trf zjByVp!_v#l#_(zuBVbDdwy=G(0=96hjnzru(JhiK!(=xv3(v5Hm|-*1gNy^;5DbG+ zwz}A5wg!x&4NyjeX*;`Elf>Ko6j!*V+nA;T;d0@{rSRk2#={BLNWe@7o>~WGwDEWa zFUK(1%HnyDQ4zYGL zWCtf-QOV)p)Yn-VrvJ{D5#QwVtXk3^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G_b0q85Tld@D{-+fMz~nVcN_D zh&)MFuG|5J1kOyMLOD=NIzb|P+aK|GhayB5iH*gs&^#zGdaug21d_;Y_X70~p(atv zyHU)lZNi9wH{WnHK((!;4FvJlOeomk;~Cnj_eCFvdPSSso=;$e#wCrlLz;UNjy87- zmAC%S3o6G#v!USF$)`n^vuK+u$l+qzh+=Nva}1t~c2AzNPS zaVj3o0Z~KOk+`bLi9=b6IEG{9n2vVuBH(@jMT13xrf8v=PzanHmtLWZ#4)OR;WU_1 z>J!r9)CIHWQOAhoDEpY)Kow*>4PRO13eAY>dhdGXWM4c^GKZcKEAaP!6r1RwG*$K|@#<~*zcBIr zcg3B)ow)9zSiXGjQ!PE%PJb<{**X1;d+?&D^S|})Z{dpLK*re;^azUYC)m^gHQAG`(}_5p%O5P0 z6t$Fcy}u>3xoI5CPO8h|P#iBTyg^sAcvp zpPv0U(;FzWeaGL-<08l{&gor3SwW1()9(sp$;qJ`4Ky7Jq*aZf78wd>X)&9gGn*bK zoMpxQ>Y~~7*&s&bWwYrwgtN?;&s{Z}E+~>^&Ajb~*>r!AEE{I~TV~VyM6y)aS|6DK GjROG4>kyUz diff --git a/loginResults.xlsx b/loginResults.xlsx index b697c53a4062ffe26804eca195234d7f15c1bb87..412d9e573fbeb312f1cd32759c1a207a12119b23 100644 GIT binary patch delta 612 zcmYk4yGlbr5QaG-1QbCfL4v4+81ND&J7@2S8t>w@5mdxZAHdeq2aps8Y-|NvVJZ=9 z6fEK^_yl5MDI&O9MOFn}oNTy+3060NQP_zgqAuW0xRZtQl{J!74`2>(T=bu^ZaG;m?g6 xgfPkYW;zG%OcgbDdfEn#AYG(4yE51MP;V#q(JzNzktYBE delta 612 zcmYk4yGnyW5QX_g5F&y~LJ(1r81Rxz_BMM-ykGI!2x?)c4`6F0K7ge7A&s2~w!%~* z*eF=USFpAa3ri8fpCp@2c|OjZSM|E)sX;OoA5Xpo zEo>~O{+e285M0ES>EE_SVQ6WlCu#$u4DA;NJutvHqqAZ<0HG~ap)UYrmhMWK08HX| zWkVj=B!kl@&juhgr#{&MP%tW~k>D^+(jm4T4wytb*BwA|N7tr3;sCXzXPb+98f7R) zUv8`whzyu!l&$zjB|vhd%Is)xpg}sF>i|{>x|+{<2M6XHJuVcYRAU2jkdnR^eK(0l zr{ezQpJtmVfLl%Jl>wh1Kr>BjbvOWLBps}c`$(BwkS^D)Hz*KEyDu9UfU=yrH+|ix zz#xk!wpuqv1ZFH1w#WShf)av`c8Y$70mrGjn`#(jnM)AH(d`~)njh-@ await driver.navigate().to('https://stage.edgate.com/exact/login.php') }, + { 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() }, +//RIGHT PANEL + + //ExACT logo { description: 'Verify ExACT logo is present', action: async () => { @@ -59,6 +62,7 @@ const steps = [ } }, + //Welcome back text { description: 'Validate Welcome back text', action: async () => { @@ -70,6 +74,7 @@ const steps = [ } }, + //Welcome back text color { description: 'Validate Welcome back text color', action: async () => { @@ -81,6 +86,7 @@ const steps = [ } }, + //Welcome back icon { description: 'Verify Welcome back icon is present', action: async () => { @@ -92,6 +98,7 @@ const steps = [ } }, + //Login title text { description: 'Validate Login title text', action: async () => { @@ -103,6 +110,7 @@ const steps = [ } }, + //Login title text color { description: 'Validate Login title text color', action: async () => { @@ -114,6 +122,7 @@ const steps = [ } }, + //Login title text font { description: 'Validate Login title text font size', action: async () => { @@ -125,6 +134,7 @@ const steps = [ } }, + //Username label text { description: 'Validate Username label text', action: async () => { @@ -136,6 +146,7 @@ const steps = [ } }, + //Username label text color { description: 'Validate Username label text color', action: async () => { @@ -147,6 +158,7 @@ const steps = [ } }, + //Username textbox placeholder { description: 'Validate Username placeholder text', action: async () => { @@ -158,6 +170,8 @@ const steps = [ } }, + + //Password label text { description: 'Validate Password label text', action: async () => { @@ -169,6 +183,7 @@ const steps = [ } }, + //Password label text color { description: 'Validate Password label text color', action: async () => { @@ -180,6 +195,7 @@ const steps = [ } }, + //Password textbox placeholder { description: 'Validate Password placeholder text', action: async () => { @@ -191,6 +207,7 @@ const steps = [ } }, + //Forgot password text link color { description: 'Validate Forgot Password link text color', action: async () => { @@ -202,6 +219,7 @@ const steps = [ } }, + //Login button text { description: 'Validate Login button text', action: async () => { @@ -213,6 +231,7 @@ const steps = [ } }, + //Login button background color { description: 'Validate Login button background color', action: async () => { @@ -224,6 +243,7 @@ const steps = [ } }, + //Don't have an account? text { description: 'Validate Dont have account text', action: async () => { @@ -235,6 +255,7 @@ const steps = [ } }, + //Free trial button text { description: 'Validate Free trial button text', action: async () => { @@ -246,6 +267,7 @@ const steps = [ } }, + //Free trial button background color { description: 'Validate Free trial button background color', action: async () => { @@ -257,6 +279,7 @@ const steps = [ } }, + //EdGate copyright image { description: 'Verify EdGate copyright image is present', action: async () => { @@ -268,12 +291,29 @@ const steps = [ } }, + //Validation + { description: 'Click Login button', action: async () => await driver.findElement(By.css('.login')).click() }, + + /*Username validation + + { description: 'Validate username validadtion text', action: async () => + { const elementText = await driver.findElement(By.css('?')).getText(); + if (elementText === expectedUsernameValidationText) + {console.log('Passed: Username validation text matched as expected');} + else + {console.log(`FAILED: Expected: "${expectedUsernameValidationText}"; Actual: "${elementText}"`);} + } + },*/ + + { description: 'Enter username', action: async () => await driver.findElement(By.css('.form-control:nth-child(2)')).sendKeys('exact_juan') }, { description: 'Click Login button after entering username', action: async () => await driver.findElement(By.css('.login')).click() }, { description: 'Enter incorrect password', action: async () => await driver.findElement(By.css('.passfield')).sendKeys('Edgate1') }, { description: 'Click Login button after entering wrong password', action: async () => await driver.findElement(By.css('.login')).click() }, + //Confirm validation message + { description: 'Validate authentication failed validation text', action: async () => { @@ -285,6 +325,7 @@ const steps = [ } }, + //Authentication validation text background color { description: 'Validate authentication alert background color', action: async () => { @@ -295,7 +336,7 @@ const steps = [ console.log('Passed: Authentication alert background color matched as expected'); } }, - + { description: 'Enter username', action: async () => await driver.findElement(By.css('.form-control:nth-child(2)')).sendKeys('exact_juan') }, { description: 'Enter correct password', action: async () => await driver.findElement(By.css('.passfield')).sendKeys('Edgate1!') }, { description: 'Click Login button after entering correct password', action: async () => await driver.findElement(By.css('.login')).click() }, @@ -312,30 +353,36 @@ const takeScreenshot = async (driver, stepIndex, stepDescription) => { const screenshot = await driver.takeScreenshot(); const dir = path.join('screenshots', 'loginScript'); - 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; }; + const clearOldResults = () => { + // Remove old screenshots + const screenshotDir = path.join('screenshots', 'loginScript'); + if (fs.existsSync(screenshotDir)) { + fs.rmSync(screenshotDir, { recursive: true, force: true }); + } + fs.mkdirSync(screenshotDir, { recursive: true }); + + // Remove old Excel file + if (fs.existsSync('loginResults.xlsx')) { + fs.unlinkSync('loginResults.xlsx'); + } + }; + try { // Initialize workbook and worksheet - if (!fs.existsSync('loginResults.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, 'loginResults.xlsx'); - } else { - workbook = XLSX.readFile('loginResults.xlsx', { cellStyles: true }); - const sheetName = workbook.SheetNames[0]; - worksheet = workbook.Sheets[sheetName]; - } + clearOldResults(); + + // Initialize workbook and worksheet + 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'); // Log test start time worksheet = logStep(worksheet, 'Test Start', 'Started', '', startTime, ''); @@ -355,6 +402,7 @@ try { testStatus = 'Failed'; } } + //Check if login was successful const usernameValidation = await driver.wait(until.elementLocated(By.css('#navbarDropdown > span')), 5000).catch(() => false); @@ -365,7 +413,7 @@ try { console.log('FAILED: Unable to log in'); testStatus = 'Failed'; } - + // Log test end time const endTime = new Date().toISOString(); worksheet = logStep(worksheet, 'Test End', testStatus, '', endTime, '');