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 PaychexHandler = require('../mfa/paychex.handler');
const ItemIterator = require('../../lib/iterator/item-iterator');
const SUPPORTED_ITEM_TYPE = require('../../lib/common/constants').supportedItemTypes;
const Controller = require('../../lib/controller');
const ExtractorClassifier = require('../../lib/extractor/extractor-classifier');

/**
* PAYCHEX
*/
class Emp_1t24BlpJnA06dRQk6KLJdTEGJe1 extends EmploymentNavigator {

constructor(session_id) {
super(session_id);
this.elements = ['iframe[id="login"]', 'input[id="login-username"]', 'input[id="login-password"]', '#one-time-password, #change-delivery-method-link'];
}

async init() {
let session = global.session_mgr.get_session(this.session_id);
session.url = 'https://myapps.paychex.com/';
await super.init();
}

async execute_pre_login(page) {
logger.debug("Emp_1t24BlpJnA06dRQk6KLJdTEGJe1 -> execute_pre_login -> started");

try {
await this.ph.waitForSelector(this.elements[0], page);
} catch (e) {
logger.warn(e);
}

this.frame = await this.ph.getFrameByIdOrName('login', page);
await this.ph.waitForSelector(this.elements[2], this.frame, {
visible: true,
timeout: 20000
});
}

async is_login_page(page) {
logger.debug("Emp_1t24BlpJnA06dRQk6KLJdTEGJe1 -> is_login_page -> started");

const errRegexList = ["login information couldn't be verified", "Please reset your password", "Account Disabled", "your account has been disabled"];

if (await this.ph.isElementVisible(this.elements[3], this.frame)) {
return false;
}

let is_username = await this.ph.isElementVisible(this.elements[1], this.frame);
let is_password = await this.ph.isElementVisible(this.elements[2], this.frame);

let is_error = await this.ph.searchError(errRegexList, this.frame);
if (is_error) {
logger.debug(await this.ph.getErrorText(this.frame));
}

return (is_username || is_password || is_error);
}

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

await this.ph.fillElementValue(this.elements[1], username, this.frame);
await this.ph.fillElementValue(this.elements[2], password, this.frame);
await this.ph.pressEnter(this.elements[2], this.frame);

await this.ph.once(page, 'load');
}

async has_mfa(page) {
return await new PaychexHandler(this.session_id).has_mfa(page);
}

async navigate_to_employment_profile(page) {
logger.debug('PAYCHEX -> navigate_to_employment_profile - started');

const profile_elements = ['//a//*[text()="My Profile"]', '//*[@role="tab"]//*[text()="Employment"]', '//span[text()="Status"] | //*[text()="Status Date"] | //*[text()="Hire Date"] | //*[text()="Organization"]'];

//Click on "My Profile"
await this.ph.waitForXPath(profile_elements[0], page, {
visible: false,
timeout: 20000
});

let EH = await this.ph.getElementHandler(profile_elements[0], page);
if (typeof EH && EH.length == 0) {
throw new Error("My profilr EH is not available");
}
try {
await this.ph.performXPathHiddenClickAndNavigation(EH[0], page);
} catch (e) {
logger.warn(e);
}

//Click on "Employment Tab"
await this.ph.waitForXPath(profile_elements[1], page, {
timeout: 20000
});

EH = await this.ph.getElementHandler(profile_elements[1], page);
if (typeof EH && EH.length == 0) {
throw new Error("Employment EH is not available");
}
await this.ph.performXEClick(EH[0]);
await this.ph.waitForXPath(profile_elements[2], page);

return page;
}

async navigate_to_paystub_file(page) {
logger.debug('Emp_1t24BlpJnA06dRQk6KLJdTEGJe1 -> navigate_to_paystub_file - started');

const page_url = 'https://myapps.paychex.com/landing_remote/index.do';
const paystub_elements = ['button[text*="viewAll"]', 'input[type="checkbox"]'];

await this.ph.goto(page_url, page, ['load'], 20000);

// click on view all paystubs
await this.ph.waitForSelector(paystub_elements[0], page, {
visible: true,
timeout: 20000
});
await this.ph.performClick(paystub_elements[0], page);

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

return page;
}

async close_last_tab() {
let session = global.session_mgr.get_session(this.session_id);
const pages = await session.browser.pages();
logger.debug(pages.length);

if (pages.length > 1) {
session.page = pages[pages.length - 2];
await pages[pages.length - 1].close();
}
}

async post_navigate_to_paystub_file(page) {
logger.debug('Emp_1t24BlpJnA06dRQk6KLJdTEGJe1 -> post_navigate_to_paystub - started');
await this.close_last_tab(page);
}

async get_extractor(page, type) {
if (type === SUPPORTED_ITEM_TYPE.paystub_file) {
return new ExtractorClassifier(page).get_extractor('pdf', type);
}
return await super.get_extractor(page, type);
}

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

}

class Emp_1t24BlpJnA06dRQk6KLJdTEGJe1_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 = ['input[type="checkbox"]', 'button[ng-click*="downloadPDFs"]', 'md-tab-item[id*="tab-item"]'];
this.index = 1;
}

async init() {
this.paystub_years = await this.getPaystubYears(this.page, this.elements[2]);

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

logger.info(`Paystubs Years => ${JSON.stringify(this.paystub_years)}`);

this.num_of_items = this.paystub_years.length - 1; // indexing starts from 1 for this site
logger.info(`Total Paystub Years => ${this.num_of_items}`);

this.prev_year_idx = this.curr_year_paystub_idx = this.curr_year_total_paystub = 0;
this.curr_year_paystubs = [];
}

async close_last_tab() {
let pages = await this.session.browser.pages();
logger.debug(`Total Browser Tabs -> ${pages.length}`);

if (pages.length > 1) {
await pages[pages.length - 1].close();
}
}

async next() {
if ((this.num_of_items >= this.index)) {
await this.close_last_tab();
await this.ph.waitForSelector(this.elements[0], this.page, {
timeout: 15000,
visible: true
});
}

await this.select_year(this.page);
await this.select_paystub(this.page);

let targetPage = await this.ph.waitForNewTarget(this.session_id, this.page);
await this.chk_for_next_year();

return targetPage;
}

hasNext() {
return (this.index <= this.num_of_items);
}

async select_year(page) {
logger.debug('Emp_1t24BlpJnA06dRQk6KLJdTEGJe1_Paystub_Iterator -> select_year - started');

if (this.index != this.prev_year_idx) {

await this.ph.waitForSelector(this.paystub_years[this.index], page, {
timeout: 15000,
visible: true
});
await this.ph.performClick(this.paystub_years[this.index], page);
await this.ph.once(page, 'load', 5000);

this.prev_year_idx = this.index;

await this.re_init_paystubs(page);
}
}

async chk_for_next_year() {
logger.debug('Emp_1t24BlpJnA06dRQk6KLJdTEGJe1_Paystub_Iterator -> chk_for_next_year - started');

if (this.curr_year_paystub_idx === this.curr_year_total_paystubs) {
this.index++;
}

}

async re_init_paystubs(page) {
logger.debug('Emp_1t24BlpJnA06dRQk6KLJdTEGJe1_Paystub_Iterator -> re_init_paystubs - started');

this.curr_year_paystubs = await this.getPaystubsForCurrYear(page);
this.curr_year_total_paystubs = this.curr_year_paystubs.length - 1;
this.curr_year_paystub_idx = 1;

logger.info(`Current year Paystub Types => ${JSON.stringify(this.curr_year_paystubs)}`);
logger.info(`Total Paystubs for current year=> ${this.curr_year_total_paystubs}`);

}

async select_paystub(page) {
logger.debug('Emp_1t24BlpJnA06dRQk6KLJdTEGJe1_Paystub_Iterator -> select_paystub - started');

// click on a paystub checkbox
await this.ph.waitForSelector(this.curr_year_paystubs[this.curr_year_paystub_idx], page, {
timeout: 15000,
visible: true
});
await this.ph.performClick(this.curr_year_paystubs[this.curr_year_paystub_idx++], page);

//click on download paystub
await this.ph.waitForSelector(this.elements[1], page, {
timeout: 15000,
visible: true
});
await this.ph.performClick(this.elements[1], page);
}

async getPaystubsForCurrYear(page) {
return await page.$$eval(this.elements[0], (elements) => {
return elements.map(e => `input[id='${e.id}']`);
});
}

async getPaystubYears(page, selector) {
return await page.$$eval(selector, (elements) => {
return elements.map(el => `md-tab-item[id='${el.id}']`);
});
}
}

module.exports = Emp_1t24BlpJnA06dRQk6KLJdTEGJe1;
     
 
what is notes.io
 

Notes is a web-based application for online 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 14 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.