NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/* jshint esversion: 8 */
/* istanbul ignore next */
const EmploymentNavigator = require('../employment.navigator');
const CustomMfaHandler = require('../mfa/emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p.custom.handler');
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');


/**
* Defense Finance and Accounting Service
*/

// MFA Session. Not tested
class Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p extends EmploymentNavigator {

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

const mfa_page_text = ['Text Message to', 'Two-Factor Authentication', 'Email to Personal'];
let is_mfa_page = await this.ph.searchError(mfa_page_text, page);
if (is_mfa_page) {
logger.info('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> is_login_page -> MFA matched!!');
return false;
}

return await super.is_login_page(page);
}

async has_mfa(page) {
logger.debug('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> has_mfa - started');
return await new CustomMfaHandler(this.session_id).has_mfa(page);
}

async terms_page(page) {
logger.debug('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> terms_page - started');
const elements = ['//*[contains(text(), "terms of the User Agreement")]'];
try {
await this.ph.waitForXPath(elements[0], page, {
visible: true,
timeout: 15000
});
logger.info('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> terms_page -> xpath is visible');
let eh = await this.ph.getElementHandler(elements[0], page);
if (typeof eh === 'object' && eh.length === 0) {
throw new Error('I Agree EH is not available');
}
await this.ph.performXPathHiddenClickAndNavigation(eh[0], page, {
timeout: 25000,
waitUntil: ['load']
});
logger.info('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> terms_page - ended');
await this.pu.debugger(page, this.session_id);
} catch (e) {
logger.warn(e);
}
return page;
}

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

const page_url = 'https://mypay.dfas.mil/#/active/home';
const profile_elements = ['*[id="sidemenu"] a[href="#/active/w2"]', "//a[@class='btn' and contains(text(),'Employee Info')]", "//*[contains(text(),'Employer Name')] | //*[contains(text(),'Identification')] | //*[contains(text(),'Social Security Number')]"];

//Go to Home page
await this.ph.goto(page_url, page, ['load'], 30000);
page = await this.terms_page(page);

await this.ph.waitForSelector(profile_elements[0], page, {
visible: true,
timeout: 20000
});
await this.ph.performClick(profile_elements[0], page);
await this.ph.waitForXPath(profile_elements[1], page, {
timeout: 20000,
visible: true
});
let eh = await this.ph.getElementHandler(profile_elements[1], page);
if (typeof eh === 'object' && eh.length === 0) {
throw new Error('Employee Info EH is not available');
}
await this.ph.performXEClick(eh[0]);
await this.ph.waitForXPath(profile_elements[2], page, {
timeout: 30000,
visible: true
});
return page;
}

async navigate_to_paystub_file(page) {
logger.debug('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> navigate_to_paystub_file - started');
const page_url = 'https://mypay.dfas.mil/#/active/home';
const paystub_elements = ['*[id="sidemenu"] a[href*="active/les"], a[href*="civilian/les"]', '//*[contains(text(), "Leave and Earnings Statement")]'];
//Go to Home page
await this.ph.goto(page_url, page, ['load'], 30000);
page = await this.terms_page(page);
await this.pu.debugger(page, this.session_id);
try {
await this.ph.waitForSelector(paystub_elements[0], page, {
visible: true,
timeout: 20000
});
await this.ph.performClick(paystub_elements[0], page);
await this.ph.once(page, 'load');
} catch (e) {
logger.warn(e);
await this.ph.waitForSelector(paystub_elements[0], page, {
visible: false,
timeout: 20000
});
await this.ph.performHiddenClick(paystub_elements[0], page);
await this.ph.once(page, 'load');
}

await this.ph.waitForXPath(paystub_elements[1], page, {
visible: true,
timeout: 15000
});
return page;
}

async get_iterator(page, type) {
if (type === SUPPORTED_ITEM_TYPE.paystub_file) {
return new Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p_Paystub_Iterator(page);
}

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 Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p_Paystub_Iterator extends ItemIterator {

constructor(page) {
super(page);
this.elements = ['select[aria-label="LES History Select"]', 'button[class*="print-btn"]', "div[role='document'] button[popover='Close'],div[role='document'] button[aria-label='Close']", 'iframe[src*="mypay.dfas"]', 'iframe[title*="Leave and Earning"]'];
}

async init() {
this.paystubs = await this.ph.getSelectOptions(this.elements[0], this.page);
this.paystubs = this.paystubs.filter(p => p.value !== '');

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

logger.info(`Paystubs Select Options => ${JSON.stringify(this.paystubs)}`);
this.num_of_items = this.paystubs.length;
logger.info(`Total Paystubs => ${this.num_of_items}`);
}

async next() {
if (this.index > 0 && (this.index < this.num_of_items)) {
//Click on the close button to close the pdf tab
try {
await this.ph.waitForSelector(this.elements[2], this.page, {
timeout: 10000,
visible: true
});
} catch (e) {
logger.warn(e);
}
await this.ph.performClick(this.elements[2], this.page);
}

//Select Month
await this.ph.waitForSelector(this.elements[0], this.page);
await this.ph.performSingleSelect(this.elements[0], this.paystubs[this.index++].value, this.page);

logger.warn(await this.ph.get_page_content(this.page)); // for debugging purpose

//Click on Printer Friendly LES button to view PDF
try {
await this.ph.waitForSelector(this.elements[1], this.page, {
timeout: 15000
});
await this.ph.performClick(this.elements[1], this.page);
} catch (e) {
await this.ph.performHiddenClick(this.elements[1], this.page);
logger.warn(e);
}

logger.warn(await this.ph.get_page_content(this.page)); // for debugging purpose

this.paystubFrame = await this.get_paystub_frame(this.page);
if (!this.paystubFrame) {
throw new Error('paystub Frame not available');
}

return this.paystubFrame;
}

async get_paystub_frame(page) {
logger.debug('Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p -> get_paystub_frame - started');

try {
await this.ph.waitForSelector(this.elements[3], page, {
timeout: 15000,
visible: true
});
logger.info(`Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p - iframe[src*="mypay.dfas"] - found `);
return await page.frames().find(frame => frame.url().includes('mypay.dfas') === true);
} catch (e) {
logger.warn(e);
}

try {
await this.ph.waitForSelector(this.elements[4], page, {
timeout: 15000,
visible: true
});
const frameHandle = await page.$(this.elements[4]);
logger.info(`Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p - iframe[title*="Leave and Earning"] - found `);
return await frameHandle.contentFrame();
} catch (e) {
logger.warn(e);
throw new Error('Leave and Earning Frame not found');
}
}

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

module.exports = Emp_1xAN3ybyQbDlCPxZxbFTW1TOW2p;
     
 
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.