CEO_Demo_29_Aug_2024.spec.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. const {test, expect} = require('@playwright/test');
  2. const { Console } = require('console');
  3. const exp = require('constants');
  4. const { copyFileSync } = require('fs');
  5. test('Login page', async({page})=>{
  6. const menuListItemName = 'PIM';
  7. const pim_menu_AddEmp = 'Add Employee';
  8. // Increase the default timeout for this test
  9. test.setTimeout(200000);
  10. //hitting the testing URL
  11. await page.goto('https://testingone-osondemand.orangehrm.com/auth/login');
  12. //Locators
  13. const loginUserNameField = await page.locator('[name="username"]');
  14. const loginPasswordField = await page.locator('[type="password"]');
  15. const loginButton = await page.locator('[type="submit"]');
  16. // Login page -- check error message after enter invalid credentials
  17. await loginUserNameField.fill('XYZ');
  18. await loginPasswordField.fill('XYZ112')
  19. await loginButton.click();
  20. console.log('Error message is: ',await page.locator('.oxd-alert-content--error p').textContent());
  21. await expect(await page.locator('.oxd-alert-content--error p')).toContainText('Invalid credentials');
  22. //Checking and clicking on the forgot password link
  23. const forgotLocator = await page.locator('.orangehrm-login-forgot-header');
  24. const forgotTextLink = await forgotLocator.textContent();
  25. await console.log('Forgot password Link Text',forgotTextLink);
  26. console.log(await forgotLocator.isVisible()); // -- O/p -- True
  27. await expect(await forgotLocator.isVisible()).toBeTruthy(); // -- checking it is correct or not
  28. await forgotLocator.click();
  29. const forgotPage = await page.locator('.orangehrm-forgot-password-title');
  30. await forgotPage.waitFor();
  31. console.log(await forgotPage.isVisible());
  32. await expect(await forgotPage.isVisible()).toBeTruthy();
  33. const forgotMsg = await page.locator('.orangehrm-card-note-text');
  34. const forgotMsgText = await forgotMsg.textContent();
  35. console.log(forgotMsgText);
  36. console.log(await forgotMsg.isVisible());
  37. await expect(await forgotMsg.isVisible()).toBeTruthy();
  38. //going back to the login page
  39. await page.goBack();
  40. await loginUserNameField.waitFor();
  41. await loginUserNameField.fill('Admin');
  42. await loginPasswordField.fill('Ishir@123')
  43. await loginButton.click();
  44. //On Dashboard page check the loggedin user name
  45. await page.locator('.oxd-userdropdown-name').waitFor();
  46. console.log('Is User name is visibe on the page');
  47. console.log(await page.locator('.oxd-userdropdown-name').isVisible());
  48. const loggedUserName = await page.locator('.oxd-userdropdown-name').textContent();
  49. console.log('Logged in User Name is: ', loggedUserName);
  50. await expect(loggedUserName === 'Testing One').toBeTruthy();
  51. // PIM
  52. //await page.waitForTimeout(3000);
  53. const navBarList = await page.locator('.oxd-main-menu li span');
  54. const menuItemCount = await navBarList.count();
  55. console.log(menuItemCount);
  56. for(let i=0; i<menuItemCount; i++){
  57. const menuItemName = await navBarList.nth(i).textContent();
  58. if(menuItemName === menuListItemName){
  59. await navBarList.nth(i).click();
  60. break;
  61. }
  62. }
  63. //PIM menu i.e. clicking on "Add Employee" link
  64. await page.waitForTimeout(30000);
  65. const menuItemList = await page.locator('.oxd-topbar-body-nav ul li a');
  66. const menuItemListCount = await menuItemList.count();
  67. for(let i=0; i<menuItemListCount; i++){
  68. const menuText = await menuItemList.nth(i).textContent();
  69. if(menuText === pim_menu_AddEmp){
  70. await await menuItemList.nth(i).click();
  71. break;
  72. }
  73. }
  74. //uploading image
  75. await page.locator('input[type="file"]').setInputFiles('Amy_Acker.png');
  76. //PIM menu i.e. Filling the "Add Employee" form
  77. await page.locator('.orangehrm-employee-form [name="firstName"]').pressSequentially('Amy1');
  78. await page.locator('.orangehrm-employee-form [name="lastName"]').pressSequentially('Acker1');
  79. await page.locator('.--label-right').click();
  80. await page.locator('.oxd-form-row input[class="oxd-input oxd-input--active"]').nth(1).pressSequentially('Amy_Acker1');
  81. await page.locator('.oxd-form-row input[type="password"]').nth(0).pressSequentially('Ishir@123');
  82. await page.locator('.oxd-form-row input[type="password"]').nth(1).pressSequentially('Ishir@123');
  83. await page.locator('button[type="submit"]').click();
  84. await page.waitForTimeout(2000);
  85. // I am clicking on the Employee List tab and find the User
  86. const EmpListMenu = await page.locator('.oxd-topbar-body-nav-tab-item').nth(1);
  87. await EmpListMenu.click();
  88. //finding the newly created user in the list not with the help of search functionlality
  89. await page.locator('.oxd-table-card').first().waitFor();
  90. const numRows = await page.locator('.oxd-table-card');
  91. const numRowsCount = await numRows.count();
  92. console.log('Number of Users: ',numRowsCount);
  93. for(let i=0; i<numRowsCount; i++){
  94. const nthRow = await numRows.nth(i);
  95. const cell = await nthRow.locator('.oxd-padding-cell').nth(1);
  96. const cellText = await cell.locator('div').textContent();
  97. if(cellText ==='0004'){
  98. console.log('Id is okay');
  99. const cell = await nthRow.locator('.oxd-padding-cell').nth(2);
  100. const cellText = await cell.locator('div').textContent();
  101. if(cellText==='Amy1 '){
  102. console.log('First Name is okay');
  103. const cell = await nthRow.locator('.oxd-padding-cell').nth(3);
  104. const cellText = await cell.locator('div').textContent();
  105. if(cellText==='Acker1'){
  106. console.log('Laste Name is okay');
  107. await nthRow.locator('.oxd-padding-cell .bi-pencil-fill').nth(0).click();
  108. break;
  109. }
  110. }
  111. }
  112. }
  113. //Personal Details -- Driver's License Number
  114. await page.locator('input[placeholder="First Name"]').waitFor();
  115. await page.waitForTimeout(2000);
  116. await page.locator('.oxd-input').nth(6).pressSequentially('Driv123456789');
  117. // Personal Details -- License Expiry Date -- Year
  118. const calen1 = await page.locator('.bi-calendar').first().click();
  119. let LicensecalYearLocatorText = parseInt(await page.locator('.oxd-calendar-selector-year-selected p').textContent());
  120. console.log(LicensecalYearLocatorText);
  121. if (LicensecalYearLocatorText < 2027) {
  122. while (LicensecalYearLocatorText < 2027) {
  123. await page.locator('.bi-chevron-right').click();
  124. LicensecalYearLocatorText = parseInt(await page.locator('.oxd-calendar-selector-year-selected p').textContent());
  125. if (LicensecalYearLocatorText === 2027) {
  126. break;
  127. }
  128. }
  129. }
  130. // Personal Details -- License Expiry Date -- Month
  131. await page.locator('.oxd-calendar-selector-month-selected .bi-caret-down-fill').click();
  132. const monthdropdown = await page.locator('.oxd-calendar-dropdown .oxd-calendar-dropdown--option');
  133. const monthdropdownCount = await monthdropdown.count();
  134. for(let i=0; i<monthdropdownCount; i++){
  135. const monthdropdownText = await monthdropdown.nth(i).textContent();
  136. if(monthdropdownText === 'May'){
  137. await monthdropdown.nth(i).click();
  138. break
  139. }
  140. }
  141. //Date
  142. const calDateLocator = await page.locator('.oxd-calendar-date-wrapper .oxd-calendar-date');
  143. await calDateLocator.nth(19).click();
  144. //Nationalty
  145. const Nationality_drop = await page.locator('.oxd-select-text--arrow').first();
  146. const Nationality_dropClick = await Nationality_drop.click();
  147. const Nationalityoption = await page.locator('.oxd-select-option', { hasText: 'American' });
  148. await Nationalityoption.click();
  149. //Marital Status
  150. const mariatlStatus = await page.locator('.oxd-select-text--arrow').last();
  151. const mariatlStatusClick = await mariatlStatus.click();
  152. const mariatlStatusoption = await page.locator('.oxd-select-option', { hasText: 'Married' });
  153. await mariatlStatusoption.click();
  154. // Personal Details -- User Date of Birth -- Year
  155. const calen2 = await page.locator('.bi-calendar').last().click();
  156. let dobLocatorText = parseInt(await page.locator('.oxd-calendar-selector-year-selected p').textContent());
  157. console.log(dobLocatorText);
  158. if (dobLocatorText > 2022) {
  159. while (dobLocatorText > 2022) {
  160. await page.locator('.bi-chevron-left').last().click();
  161. let dobLocatorText = parseInt(await page.locator('.oxd-calendar-selector-year-selected p').textContent());
  162. if (dobLocatorText === 2022) {
  163. break;
  164. }
  165. }
  166. }
  167. // Personal Details -- DOB -- Month
  168. await page.locator('.oxd-calendar-selector-month-selected .bi-caret-down-fill').click();
  169. const monthdropdown1 = await page.locator('.oxd-calendar-dropdown .oxd-calendar-dropdown--option');
  170. const monthdropdownCount1 = await monthdropdown1.count();
  171. for(let i=0; i<monthdropdownCount1; i++){
  172. const monthdropdownText = await monthdropdown1.nth(i).textContent();
  173. if(monthdropdownText === 'May'){
  174. await monthdropdown1.nth(i).click();
  175. break
  176. }
  177. }
  178. //DOB - Date
  179. const calDateLocator1 = await page.locator('.oxd-calendar-date-wrapper .oxd-calendar-date');
  180. await calDateLocator1.nth(19).click();
  181. //Gender
  182. await page.locator('.--gender-grouped-field label').last().click();
  183. // Clicking on the save button of the Form
  184. await page.locator('.orangehrm-left-space').click();
  185. //Attaching a file & Upload file
  186. await page.locator('.oxd-button--medium').last().click();
  187. await page.locator('input[type="file"]').setInputFiles('Amy_Acker.png');
  188. //adding comment
  189. await page.locator(' textarea[placeholder="Type comment here"]').pressSequentially('Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type.');
  190. //Clicking on save button after upload a file
  191. await page.locator('button[type="submit"]').last().click();
  192. //await page.pause();
  193. //Going to the Admin page i.e. clicking on Admin menue
  194. const menus = await page.locator('.oxd-main-menu-item--name');
  195. const menusCount = await menus.count();
  196. for(let i=0; i<menusCount; i++){
  197. const menusText = await menus.nth(i).textContent();
  198. if(menusText=== 'Admin'){
  199. await menus.nth(i).click();
  200. break;
  201. }
  202. }
  203. //Search functionlaity -- by filter option
  204. //Enter User Name in the seach section
  205. //await page.locator('.oxd-form-row .oxd-input--active').waitFor();
  206. await page.locator('.oxd-form-row .oxd-input--active').pressSequentially('Amy_Acker1');
  207. //User role drop-down in the search section
  208. await page.locator('.oxd-select-text--arrow').first().click();
  209. //await page.locator('.oxd-select-dropdown .oxd-select-option').waitFor();
  210. //////await page.waitForTimeout(2000);
  211. const optionLocatorFirst = await page.locator('.oxd-select-dropdown .oxd-select-option');
  212. const optionCount = await optionLocatorFirst.count();
  213. for(let i=0; i<optionCount; i++){
  214. const optionName1 = await optionLocatorFirst.locator('span').nth(i).textContent();
  215. if(optionName1 === 'ESS'){
  216. await optionLocatorFirst.locator('span').nth(i).click();
  217. break;
  218. }
  219. }
  220. //Employee Name
  221. const empName = await page.locator('[placeholder="Type for hints..."]').first();
  222. await empName.click();
  223. await empName.pressSequentially('Amy');
  224. await page.waitForTimeout(2000);
  225. const dropMenus = await page.locator('.oxd-autocomplete-dropdown .oxd-autocomplete-option');
  226. const dropMenusCount = await dropMenus.count();
  227. for(let i=0; i<dropMenusCount; i++){
  228. const dropMenuText = await dropMenus.nth(i).textContent();
  229. if(dropMenuText=== 'Amy1 Acker1' ){
  230. await dropMenus.nth(i).click();
  231. break;
  232. }
  233. }
  234. //Check status
  235. await page.locator('.oxd-select-text--arrow').last().click();
  236. const optionLocator = await page.locator('.oxd-select-dropdown .oxd-select-option');
  237. const optionCount1 = await page.locator('.oxd-select-dropdown .oxd-select-option').count();
  238. for(let i=0; i<optionCount1; i++){
  239. const optionName1 = await optionLocator.locator('span').nth(i).textContent();
  240. if(optionName1 === 'Enabled'){
  241. await optionLocator.locator('span').nth(i).click();
  242. break;
  243. }
  244. }
  245. await page.locator('.orangehrm-left-space').click();
  246. //Again clicking on the PIM menu button
  247. const navBarList1 = await page.locator('.oxd-main-menu li span');
  248. const menuItemCount1 = await navBarList1.count();
  249. console.log(menuItemCount1);
  250. for(let i=0; i<menuItemCount1; i++){
  251. const menuItemName = await navBarList1.nth(i).textContent();
  252. if(menuItemName === menuListItemName){
  253. await navBarList1.nth(i).click();
  254. break;
  255. }
  256. }
  257. //finding the newly created user in the PIM list not with the help of search functionlality - Delete the user
  258. await page.locator('.oxd-table-card').first().waitFor();
  259. const numRows2 = await page.locator('.oxd-table-card');
  260. const numRowsCount2 = await numRows2.count();
  261. console.log('Number of Users: ',numRowsCount2);
  262. for(let i=0; i<numRowsCount2; i++){
  263. const nthRow = await numRows2.nth(i);
  264. const cell = await nthRow.locator('.oxd-padding-cell').nth(1);
  265. const cellText = await cell.locator('div').textContent();
  266. if(cellText ==='0003'){
  267. console.log('Id is okay');
  268. const cell = await nthRow.locator('.oxd-padding-cell').nth(2);
  269. const cellText = await cell.locator('div').textContent();
  270. if(cellText==='Amy1 '){
  271. console.log('First Name is okay');
  272. const cell = await nthRow.locator('.oxd-padding-cell').nth(3);
  273. const cellText = await cell.locator('div').textContent();
  274. if(cellText==='Acker1'){
  275. console.log('Laste Name is okay');
  276. await nthRow.locator('.oxd-padding-cell .bi-trash').nth(0).click();
  277. break;
  278. }
  279. }
  280. }
  281. }
  282. //Delete the newwly created user form the PIM
  283. await page.locator('.orangehrm-dialog-popup .orangehrm-button-margin').last().click();
  284. await page.pause();
  285. })