NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/* jshint esversion: 8 */
/* istanbul ignore next */
const EmploymentNavigator = require('../employment.navigator');
const logger = require('../../lib/common/log').logger;
const PuppeteerHelper = require('../../lib/helper/puppeteer.helper');
const ItemIterator = require('../../lib/iterator/item-iterator');
const SUPPORTED_ITEM_TYPE = require('../../lib/common/constants').supportedItemTypes;

/**
* Berry Global Employee Portal
*/
class Emp_1xJZkx90YWEIRyArxp44iVO6DqQ extends EmploymentNavigator {
constructor(session_id) {
super(session_id);
this.elements = ['input#userId', 'input#password'];
}



async init() {
let session = global.session_mgr.get_session(this.session_id);
session.url = 'https://hcm.berryplastics.com/SHCM/ahess/LogInScript0.jsp';
await super.init();
}

async execute_pre_login(page) {
logger.debug('Emp_1xJZkx90YWEIRyArxp44iVO6DqQ -> execute_pre_login - started');



await this.ph.waitForSelector(this.elements[1], page, {
timeout: 30000,
visible: true
});
}

async dialog_handler(page, session_id, dialog, navigation_handler) {
logger.debug('into overriden dialog handler for this Emp_1xJZkx90YWEIRyArxp44iVO6DqQ');

if (!dialog) return;

let dialog_message = await dialog.message();

if (dialog_message.includes('Invalid User or password has been entered') || dialog_message.includes('Invalid')) {
await dialog.accept();
this.is_invalid = true;
logger.debug('Invalid Credentials -> dialog found!');
return;
}
await dialog.accept();

await this.authentication_event_handler(page);
}

async is_login_page(page) {
logger.debug('Emp_1xJZkx90YWEIRyArxp44iVO6DqQ -> is_login_page - started');

let is_username = await this.ph.isElementExist(this.elements[0], page);
let is_password = await this.ph.isElementExist(this.elements[1], page);

logger.info(`Emp_1xJZkx90YWEIRyArxp44iVO6DqQ -> is_login_page -> is_username - ${is_username}, is_password - ${is_password}, this.is_invalid - ${this.is_invalid}`);

return (is_username || is_password || this.is_invalid);
}

async do_login(page, username, password) {
logger.debug('Emp_1xJZkx90YWEIRyArxp44iVO6DqQ -> do_login - started');

await this.ph.fillElementValue(this.elements[0], username, page);
await this.ph.fillElementValue(this.elements[1], password, page);
await this.ph.pressEnter(this.elements[1], page);
await this.ph.once(page, 'load');
}

async navigate_to_employment_profile(page) {
const elements = ['//*[text()="Employment Information"]']

await this.ph.goto('https://hcm.berryplastics.com/SHCM/ahess/ChangePersonalInfo.jsp', page, ['load'], 30000);

await this.ph.waitForXPath(elements[0], page)

return page
}

async post_navigate_to_employment_profile(page) {

await this.ph.goto('https://hcm.berryplastics.com/SHCM/ahess/index.jsp', page, ['load'], 30000);


return page
}

async navigate_to_paystub_file(page) {
const elements = ['//*[contains(text(),"view detailed pay information")]']

await this.ph.goto('https://hcm.berryplastics.com/SHCM/ahess/ViewCheckMain.jsp', page, ['load'], 30000);

await this.ph.waitForXPath(elements[0], page)

return page
}

async post_navigate_to_paystub_file(page) {

await this.ph.goto('https://hcm.berryplastics.com/SHCM/ahess/index.jsp', page, ['load'], 30000);


return page
}

async navigate_to_w2_file(page) {
const elements = ['//*[contains(text(),"W-2 Year column")]']

await this.ph.goto('https://hcm.berryplastics.com/SHCM/ahess/W2Select.jsp', page, ['load'], 30000);

await this.ph.waitForXPath(elements[0], page)

return page
}

async get_iterator(page, type) {
if (type === SUPPORTED_ITEM_TYPE.paystub_file) {
return new Emp_1xJZkx90YWEIRyArxp44iVO6DqQ_Paystub_Iterator(page, this.session_id);
}
if (type === SUPPORTED_ITEM_TYPE.w2_file) {
return new Emp_1xJZkx90YWEIRyArxp44iVO6DqQ_W2_Iterator(page, this.session_id);
}
return await super.get_iterator(page, type);
}

async getPageIterator(page, type) {
if (type === SUPPORTED_ITEM_TYPE.paystub_file) {
return new Emp_1xJZkx90YWEIRyArxp44iVO6DqQ_Paystub_Page_Iterator(page, this.session_id);
}
if (type === SUPPORTED_ITEM_TYPE.w2_file) {
return new Emp_1xJZkx90YWEIRyArxp44iVO6DqQ_W2_Page_Iterator(page, this.session_id);
}
return await super.getPageIterator(page, type);
}
}

class Emp_1xJZkx90YWEIRyArxp44iVO6DqQ_Paystub_Iterator extends ItemIterator {
constructor(page, session_id) {
super(page)
this.session_id = session_id;
this.session = global.session_mgr.get_session(session_id);
this.elements = ['.inforHyperlink', 'button[value*="Return"]']
}

async init() {
this.paystubs = await this.getTotalPaystubs(this.page)
this.num_of_items = this.paystubs.length
logger.info(`Total Paystubs => ${this.num_of_items}`);

if (this.num_of_items === 0) {
throw Controller.getError('general', 'notAvailable', SUPPORTED_ITEM_TYPE.paystub_file);
}

logger.info(`${JSON.stringify(this.paystubs)}`);
}

async next() {

if (await this.ph.isElementExist(this.elements[1], this.page)) {
await this.ph.performClick(this.elements[1], this.page)
await this.ph.waitFor(5000)
}

this.session.current_paystub = this.paystubs[this.index]

this.index++

return this.page;
}

async getTotalPaystubs(page) {
const elements = await page.evaluate((selector) => {
const linksArr = Array.from(document.querySelectorAll(selector)).map((o) => {
return `//a[text()="${o.innerText}"]`;
});
return linksArr;
}, this.elements[0]);
return elements
}

}

class Emp_1xJZkx90YWEIRyArxp44iVO6DqQ_Paystub_Page_Iterator extends ItemIterator {
constructor(page, session_id) {
super(page)
this.session_id = session_id;
this.session = global.session_mgr.get_session(session_id);
this.elements = ['//*[contains(text(),"Hours & Earnings")]']
}


async init() {

}

async next() {
await this.ph.waitForXPath(this.session.current_paystub, this.page);
const eh = await this.ph.getElementHandler(this.session.current_paystub, this.page);
if (typeof eh == 'object' && eh.length == 0) {
throw new Error('Paystub EH is not available');
}
await this.ph.performXEClick(eh[0]);
await this.ph.waitFor(5000)

await this.ph.waitForXPath(this.elements[0], this.page, {
timeout: 20000
});

this.index++

return this.page;
}
}

class Emp_1xJZkx90YWEIRyArxp44iVO6DqQ_W2_Iterator extends ItemIterator {
constructor(page, session_id) {
super(page)
this.session_id = session_id;
this.session = global.session_mgr.get_session(session_id);
this.elements = ['a[href*="W2View"]', 'button[value*="Continue"]']
}

async init() {
this.total_w2 = await this.getTotalW2(this.page)
this.num_of_items = this.total_w2.length
logger.info(`Total W2 => ${this.num_of_items}`);

if (this.num_of_items === 0) {
throw Controller.getError('general', 'notAvailable', SUPPORTED_ITEM_TYPE.w2_file);
}

logger.info(`${JSON.stringify(this.total_w2)}`);
}

async next() {

if (await this.ph.isElementExist(this.elements[1], this.page)) {
await this.ph.performClick(this.elements[1], this.page)
await this.ph.waitFor(5000)
}

this.session.current_w2 = this.total_w2[this.index]

this.index++

return this.page;
}

async getTotalW2(page) {
const elements = await page.evaluate((selector) => {
const linksArr = Array.from(document.querySelectorAll(selector)).map((o) => {
return `//a[text()="${o.innerText}"]`;
});
return [...new Set(linksArr)]
}, this.elements[0]);
return elements
}

}

class Emp_1xJZkx90YWEIRyArxp44iVO6DqQ_W2_Page_Iterator extends ItemIterator {
constructor(page, session_id) {
super(page)
this.session_id = session_id;
this.session = global.session_mgr.get_session(session_id);
this.elements = ['//*[contains(text(),"Miscellaneous Payments")]']
}


async init() {

}

async next() {
await this.ph.waitForXPath(this.session.current_w2, this.page);
const eh = await this.ph.getElementHandler(this.session.current_w2, this.page);
if (typeof eh == 'object' && eh.length == 0) {
throw new Error('W2 EH is not available');
}
await this.ph.performXEClick(eh[0]);
await this.ph.waitFor(5000)

await this.ph.waitForXPath(this.elements[0], this.page, {
timeout: 20000
});

this.index++

return this.page;
}
}

module.exports = Emp_1xJZkx90YWEIRyArxp44iVO6DqQ;
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.