guys!!
I have several .csv extension files in a folder (below there will be a file as an example).
I need to query a specific file and validate it using Cypress.
After finding the file, I need to look for specific data and, after finding it, validate the entire line.
Currently I can search for the file and find it (see code below).
What I’m not able to do is validate the specific line in the file.
Could anyone help?
Follow the code below in Cypress:
urId = result[0].ur_external_reference_id
cy.task('getFiles', 'batch/cerc/22896431000382/unidades_recebiveis/processada')
.then(result => {
const files = result
let continue_loop = true
cy.wrap(continue_loop, { log: false }).as('continue')
for (let i = 0; i < files.length; i++) {
cy.get('@continue', { log: false }).then(continue_loop => {
if (continue_loop) {
cy.readFile(`batch/cerc/22896431000382/unidades_recebiveis/processada/${files[i]}`)
.then(txt => {
if (txt.includes(urId)) {
continue_loop = false
cy.wrap(continue_loop, { log: false }).as('continue')
cy.wrap(txt).as('txt')
}
})
}
})
}
cy.get('@txt').then(txt => {
// cy.log(JSON.stringify(txt))
});
});
Example file .csv:
phzSbLtMsETJhBhfuGkd;0010a753-d920-3e20-8346-b79a03ca291e;2024-04-29T20:05:31.618Z;1;"102031;ISPB INVALIDO"
sDgcMYCbcqnrbgrIUkDw;0037ec1f-4ec9-3bd0-9bb1-c999211b1d2e;2024-04-29T20:05:31.618Z;1;"102918;OPERACAO INVALIDA EM UMA UR JA INATIVA OU BAIXADA COM DATA DE LIQUIDACAO ANTERIOR A 90 DIAS"
OdPfhZosiSTqVzxbyBmo;008eafb4-5777-310a-9351-0b67545dd039;2024-04-29T20:05:31.618Z;1;"102031;ISPB INVALIDO"
bcpcEnhnzsXOTVDYuPnc;008fecc8-ab6c-3e33-97d1-e06bce2e0f2d;2024-04-29T20:05:31.618Z;1;"102031;ISPB INVALIDO"
hYPoKOptfRQPqSfgbFBi;0096cac9-9e2b-36fb-ad7f-30661f85cbdd;2024-04-29T20:05:31.618Z;1;"102031;ISPB INVALIDO"
dchoMPWdnhafDvvVuHhX;0097a56d-8cd3-3c9f-abed-56b5a74cc6d2;2024-04-29T20:05:31.618Z;1;"102031;ISPB INVALIDO"
IYPOlsRTRWyFWgBlwDhM;009b0404-2938-38c9-a5c1-3242ead00f91;2024-04-29T20:05:31.618Z;1;"102031;ISPB INVALIDO"
yKnRwTFsPlnKxPzUfIRa;00baee0a-d09c-3be2-8eb8-8c0cb2d9618d;2024-04-29T20:05:31.618Z;1;"102918;OPERACAO INVALIDA EM UMA UR JA INATIVA OU BAIXADA COM DATA DE LIQUIDACAO ANTERIOR A 90 DIAS"
OflUxSWmWdDkomckgLsz;00c12c8a-9856-3d98-a32f-d638cc3d4b3a;2024-04-29T20:05:31.618Z;1;"102031;ISPB INVALIDO"
lCHgHZduncDkrSeurGZY;00c43c4f-d146-3cf0-bab3-067de8a7bd5e;2024-04-29T20:05:31.618Z;1;"102031;ISPB INVALIDO"
I need to look for an id in the file. Example: “hYPoKOptfRQPqSfgbFBi”. After finding it, I only validate the data from the respective line. More precisely, the penultimate column must be “0”.
Remembering, the code is currently in Cypress
Thanks in advance!
EFPMS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.