Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
/* istanbul ignore next */
const EmploymentNavigator = require('../employment.navigator');
const logger = require('../../lib/common/log').logger;
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');
const DownloadUtils = require('../../lib/utils/download-utils');
const EmploymentHelper = require('../../lib/helper/employment.helper');
/**
* https://ecwr.fa.us2.oraclecloud.com/fscmUI/faces/FuseWelcome
* https://eflm.fa.us6.oraclecloud.com/hcmUI/faces/FuseWelcome
* https://jpmc.fa.oraclecloud.com/fscmUI/faces/FuseWelcome
*/
/**
* OracleCloud ESS
*/
class OracleCloud extends EmploymentNavigator {
async pre_navigate_to_item(page) {
logger.debug('OracleCloud -> pre_navigate_to_item - started');
const elements = ['a[name*="my_information"],a[title="Personal Information"]', 'a[target*="emp_card"], a[target*="payslips"], div[title*="Pay"]'];
let dashboard_url = this.dashboard_url || await page.evaluate(() => document.location.origin) + '/fscmUI/faces/FuseWelcome';
logger.info(`OracleCloud -> pre_navigate_to_item -> Page URL - ${await page.url()}`);
logger.info(`OracleCloud -> pre_navigate_to_item -> dashboard_url - ${dashboard_url}`);
await this.ph.goto(dashboard_url, page, ['load'], 15000);
try {
await this.ph.waitForSelector(elements[0], page);
await this.ph.performClick(elements[0], page);
} catch (e) {
logger.warn(e);
await this.ph.waitForSelector(elements[0], page, {
timeout: 5000,
visible: false
});
await this.ph.performHiddenClick(elements[0], page);
}
try {
await this.ph.waitForSelector(elements[1], page, {
visible: false,
timeout: 10000
});
} catch (e) {
logger.warn(e);
}
return page;
}
async expand_employment_profile(page, xpath) {
logger.debug('OracleCloud -> expand_employment_profile - started');
try {
await this.ph.waitForXPath(xpath, page);
let ehList = await this.ph.getElementHandler(xpath, page);
if (typeof ehList === 'object' && ehList.length > 0) {
for (const eh of ehList) {
await this.ph.performXEClick(eh);
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', page, 'include'), this.ph.waitFor(10000)]);
await this.ph.waitFor(2000);
}
}
} catch (e) {
logger.debug(e);
}
return page;
}
async navigate_to_employment_profile(page) {
logger.debug('OracleCloud -> navigate_to_employment_profile - started');
const profile_elements = ['a[target*="emp_card"]', '//*[contains(text(), "Legal Employer")] | //*[contains(text(), "Business Title")] | //*[contains(text(), "Department")] | //*[text()="Location"] | //*[text()="Person Number"]', '//div[@title="Expand"]'];
//Click on "Employment Info"
try {
await this.ph.waitForSelector(profile_elements[0], page);
await this.ph.performClick(profile_elements[0], page);
} catch (e) {
logger.warn(e);
//Check "Employment Profile" not available case
if (!await this.ph.isElementExist(profile_elements[0], page)) {
throw Controller.getError('general', 'notAvailable', SUPPORTED_ITEM_TYPE.employment_profile);
}
await this.ph.waitForSelector(profile_elements[0], page, {
timeout: 5000,
visible: false
});
await this.ph.performHiddenClick(profile_elements[0], page);
}
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', page, 'include'), this.ph.waitFor(10000)]);
await Promise.race([this.ph.waitForNavigation(page, {
waitUntil: ['load']
}), this.ph.waitFor(15000)]);
await this.ph.waitForXPath(profile_elements[1], page, {
timeout: 15000,
visible: true
});
page = await this.expand_employment_profile(page, profile_elements[2]);
return page;
}
async navigate_to_paystub_file(page) {
logger.debug('OracleCloud -> navigate_to_paystub_file - started');
const paystub_elements = ['a[target*="payslips"], div[title*="Pay"]', 'input[role="combobox"][title="Last 3 Months"], input[role="combobox"][aria-expanded="false"]', '//*[text()="Specific Date Range"]', '//label[text()="Start Date"]/preceding-sibling::input', '//span[contains(text(), "See My Pay Statement")]'];
//Click on "My Payslips"
try {
await this.ph.waitForSelector(paystub_elements[0], page);
await this.ph.performClick(paystub_elements[0], page);
} catch (e) {
logger.warn(e);
await this.ph.waitForSelector(paystub_elements[0], page, {
timeout: 5000,
visible: false
});
await this.ph.performHiddenClick(paystub_elements[0], page);
}
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', page, 'include'), this.ph.waitFor(10000)]);
await Promise.race([this.ph.waitForNavigation(page, {
waitUntil: ['load']
}), this.ph.waitFor(15000)]);
//Pay and Taxes Page
try {
//Wait & Click on "See My Pay Statement"
await this.ph.waitForXPath(paystub_elements[4], page, {
visible: false,
timeout: 10000
});
let eh = await this.ph.getElementHandler(paystub_elements[4], page);
if (typeof eh === 'object' && eh.length === 0) {
throw new Error('See My Pay Statement EH is not available');
}
await this.ph.performXPathHiddenClick(eh[0], page);
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', page, 'include'), this.ph.waitFor(10000)]);
await Promise.race([this.ph.waitForNavigation(page, {
waitUntil: ['load']
}), this.ph.waitFor(15000)]);
} catch (e) {
logger.warn(e);
}
//Click on "Select" combobox
await this.ph.waitForSelector(paystub_elements[1], page, {
visible: true,
timeout: 15000
});
await this.ph.performClick(paystub_elements[1], page);
//Click on "Specific Date Range" option
await this.ph.waitForXPath(paystub_elements[2], page, {
timeout: 15000,
visible: true
});
let eh = await this.ph.getElementHandler(paystub_elements[2], page);
if (typeof eh === 'object' && eh.length === 0) {
throw new Error('Specific Date Range eh not available');
}
await this.ph.performXEClick(eh[0]);
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', page, 'include'), this.ph.waitFor(10000)]);
try {
await this.ph.waitForXPath(paystub_elements[3], page);
} catch (e) {
logger.warn(e);
}
page = await this.select_paystub_date_range(page);
return page;
}
async select_paystub_date_range(page) {
logger.debug('OracleCloud -> select_paystub_date_range - started');
const elements = ['//label[text()="Start Date"]/preceding-sibling::input', '//label[text()="End Date"]/preceding-sibling::input', 'a[title="Search"] img[alt="Search"]'];
let {
start_date,
end_date
} = new EmploymentHelper().get_paystub_range(10, 'mm/dd/yyyy');
logger.info(`OracleCloud -> select_paystub_date_range -> start_date - ${start_date}, end_date - ${end_date}`);
//Fill From date input
await this.ph.waitForXPath(elements[0], page);
await this.ph.fillXapthValue(elements[0], start_date, page);
await this.ph.waitFor(1000); //Wait for the picker to process
//Fill To date input
await this.ph.waitForXPath(elements[1], page);
await this.ph.fillXapthValue(elements[1], end_date, page);
await this.ph.waitFor(1000); //Wait for the picker to process
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', page, 'include'), this.ph.waitFor(2000)]);
//Click on Filter
await this.ph.waitForSelector(elements[2], page);
await this.ph.performClick(elements[2], page);
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', page, 'include'), this.ph.waitFor(10000)]);
await this.ph.once(page, 'load'); //Wait for the page to load all the Paystubs properly
return page;
}
async get_iterator(page, type) {
if (type === SUPPORTED_ITEM_TYPE.paystub_file) {
return new OracleCloud_PaystubIterator(page, this.session_id);
}
return await super.get_iterator(page, type);
}
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);
}
}
class OracleCloud_PaystubIterator 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*="download"], a[href*="showpdfservlet"] , a[title*="PAYSLIP"]', '//*[text()="Load More Items"]', '//*[text()="Load More Items"]//following-sibling::span'];
this.is_pagination = false;
}
async init() {
try {
await this.ph.waitForXPath(this.elements[1], this.page);
} catch (e) {
logger.warn(e);
}
let eh = await this.ph.getElementHandler(this.elements[1], this.page);
if (typeof eh === 'object' && eh.length > 0) {
this.is_pagination = true;
}
logger.info(`OracleCloud_PaystubIterator -> init - is_pagination - ${this.is_pagination}`);
this.total_paystubs = await this.get_total_paystubs(this.page);
if (this.total_paystubs === 0) {
throw Controller.getError('general', 'notAvailable', SUPPORTED_ITEM_TYPE.paystub_file);
}
this.num_of_items = this.total_paystubs;
logger.info(`Total Paystubs => ${this.num_of_items}`);
if (this.is_pagination) {
this.page = await this.load_all_paystubs(this.page);
}
this.paystubs = await this.get_paystubs_elements(this.page);
logger.info(`Paystubs Elements => length - ${this.paystubs.length}, elements - ${JSON.stringify(this.paystubs)}`);
await this.ph.set_pdf_download(this.session, true);
this.du = new DownloadUtils();
this.downloadPath = this.du.getDownloadPath(this.session_id);
await this.du.createDownloadDir(this.session_id);
await this.ph.downloadFileInitializer(this.downloadPath, this.page);
}
async load_all_paystubs(page) {
let is_load_more_items = true;
while (is_load_more_items) {
let eh = await this.ph.getElementHandler(this.elements[1], page);
if (typeof eh === 'object' && eh.length === 0) {
is_load_more_items = false;
logger.info(`OracleCloud_PaystubIterator -> load_all_paystubs - All Paystubs Loaded`);
} else {
logger.info(`OracleCloud_PaystubIterator -> load_all_paystubs - ${await this.ph.getXapthInnerText(page, this.elements[2])}`);
await this.ph.performXEClick(eh[0]);
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', page, 'include'), this.ph.waitFor(20000)]);
await this.ph.waitFor(5000);
}
}
return page;
}
async removeDownloadedFiles() {
if (this.index > 0 && (this.num_of_items > this.index)) {
let files = await this.du.getDownloadFilesPath(this.session_id);
if (files.length > 0) {
await this.du.emptyDownloadDir(this.session_id);
}
}
}
async next() {
await this.removeDownloadedFiles();
//Click on "PAYSLIP" link
await this.ph.waitForSelector(this.paystubs[this.index], this.page, {
visible: false,
timeout: 10000
});
await this.ph.performHiddenClick(this.paystubs[this.index++], this.page); //This will download the paystub pdf.
await Promise.race([this.ph.waitForResponse('adf.ctrl-state', this.page, 'include'), this.ph.waitFor(5000)]);
let files = await this.du.getDownloadFilesPath(this.session_id);
if (files.length === 0) {
throw new Error('File is not available in the download path');
}
this.session.extract_file_path = files[0];
logger.debug(`session.extract_path => ${this.session.extract_file_path}`);
return this.page;
}
async get_paystubs_elements(page) {
return await page.evaluate(selector => {
let elArr = [];
elArr = Array.from(document.querySelectorAll(selector)).map((o) => {
return `a[id='${o.id}']`;
});
return elArr;
}, this.elements[0]);
}
async get_total_paystubs_elements(page) {
logger.info(`OracleCloud_PaystubIterator -> get_total_paystubs_elements - started`);
return await page.evaluate((selector) => {
let paystubsElArr = [];
paystubsElArr = Array.from(document.querySelectorAll(selector));
return paystubsElArr.length;
}, this.elements[0]);
}
async get_total_paystubs(page) {
if (!this.is_pagination) {
return await this.get_total_paystubs_elements(page);
}
let str = await this.ph.getXapthInnerText(page, this.elements[2]); //1-25 of 85 items
str = str.trim().slice(str.indexOf('of') + 3, str.indexOf('items') - 1);
return parseInt(str);
}
}
module.exports = OracleCloud;
![]() |
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