Last active
April 22, 2022 22:48
-
-
Save maxbisesi/4aacb417668b36d98d72cd9b4817467d to your computer and use it in GitHub Desktop.
SF Auto PDF parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then(`the downloaded PDF Document contains the following values:`, async (dataTable) => { | |
dataTable = await Utils.processDataTable(dataTable); | |
for(let i = 0; i < 5; i++) { | |
if(testData.pdfText !== undefined){ | |
break; | |
} | |
await Browser.sleep(500); | |
} | |
for(const line of dataTable) { | |
if(testData.pdfText.includes(line)) { | |
console.log(` found ${line}`); | |
continue; | |
} | |
else await Utils.throwReferenceError(`PDF does not contain ${line}`); | |
} | |
}); | |
class PDFManager { | |
async parsePDFPage(fileName,pagenumber,variable) { | |
const parser = new pdf2json(); | |
parser.addListener(`pdfParser_dataReady`, (pdfData) => { | |
testData[variable] = pdfData.Pages[pagenumber][`Texts`].map((tex) => { | |
const line = decodeURIComponent(`${tex[`R`][0][`T`]}`); | |
console.log(` ${line}`); | |
return line; | |
}); | |
}); | |
parser.addListener(`pdfParser_dataError`, errData => Utils.throwReferenceError(`pdf error: ${errData.parserError}`) ); | |
await parser.loadPDF(fileName); | |
} | |
getESQuoteFileName() { | |
//ES000455_ 04-21-2022 | |
const today = Utils.dateManipulator(`today`); | |
} | |
async readDirectory(path) { | |
try { | |
const files = await readdir(path); | |
for (const file of files) { | |
// ES000365_04-08-2022.pdf | |
} | |
} catch (e) { console.log(e); } | |
} | |
} | |
When(`I parse page {string} of the downloaded PDF Document: {string}`, {timeout: 80000}, async (page,filename) => { | |
let pagenum = parseInt(page,10); | |
if(pagenum > 0) pagenum--; | |
PDFManager.parsePDFPage(filename,pagenum,`pdfText`); | |
}); | |
@PDF_LoadDocument | |
Scenario: I use PDF Manager to Load the test document | |
Given I log in to Salesforce as userType: "CeCrr" | |
When I parse page "1" of the downloaded PDF Document: "./pdfdownloads/testDocument.pdf" | |
Then the downloaded PDF Document contains the following values: | |
| 1425 Swisco Rd. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment