0

I am encountering an internal TestCafe error with code E70 while trying to download and process a PDF file in a TestCafe test within the GT:UI of Guidewire Testing Framework. The variables are correctly set, and other functions and libraries used in the code are properly installed and configured. I am using TestCafe version 1.16.0, which cannot be updated.

I have tried using both t.wait and setTimeout to wait for the file to download, but the error persists. Below is the code snippet where the error occurs (note that some variables and paths have been obfuscated to protect privacy):

const pdfData = world.PdfDataList4RPVpwaacdc\[0\];  
pdfData.data.id = 'SubmissionWizard-XXXXXXX-XXXXXXXX-XXXXXXXXX-0-NameLink';  
try {
  const elementHTML = Selector(`#${pdfData.data.id}`);
  await t.expect(elementHTML.exists).ok();
  await t.expect(elementHTML.textContent).contains(pdfData.docType);
  console.log(`'${pdfData.docType}' found`);  
  await t.setNativeDialogHandler(() =\> true);
  await t.click(elementHTML);

  // The problematic line (line 360)
  await new Promise(resolve =\> setTimeout(resolve, 5000));

  const filePath = (await t.getNativeDialogHistory())\[0\].downloadPath;
  const pdfBuffer = await fs.promises.readFile(filePath);

  // I will use pdf-lib to analyze the PDF file
  // Here is an example of how to use pdf-lib to read text from a PDF file:
  const { PDFDocument } = require('pdf-lib');
  const pdfDoc = await PDFDocument.load(pdfBuffer);
  const pages = pdfDoc.getPages();
  let pdfText = '';
  for (let i = 0; i \< pages.length; i++) {
  const page = pages\[i\];
  const pageText = await page.getText();
  pdfText += pageText + '\\n';
}
console.log(`PDF text: ${pdfText}`);

} catch (error) {
console.error(error);
}

The error details are as follows:

'Étude' found
{
  code: 'E70',
  isTestCafeError: true,
  callsite: CallsiteRecord {
    filename: 'C:\\Guidewire\\guidewiretestingframework\\gt-ui\\policysolutions\\XXXXXXXXXXXXXXXX.js',
    lineNum: 360,
    callsiteFrameIdx: 4,
    stackFrames: [
      [Object], [Object],
      [Object], [Object],
      [Object], CallSite {},
      [Object], [Object],
      [Object]
    ],
isV8Frames: true
  }
}

I have also tried running the test with the --skip-js-errors flag, but the error still occurs.
I've tried applying this https://stackoverflow.com/questions/57575052/testcafe-testing-a-page-opening-a-pdf-in-a-new-tab without succeed...
I would appreciate any help in resolving this issue or any suggestions on how to avoid the error.

Thank you very much in advance for your time.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
ddou
  • 1
  • I examined the error and code snippet. It seems that testcafe tries to open this file and switch to it. TestCafe cannot open PDF files, which is why the error occurs. Unfortunately, I cannot determine the cause without a reproducible example and knowing which OS and browser you use. Anyway, try running your tests in the latest TestCafe version. Possibly, this behavior has already been fixed. – Alexey Popov May 25 '23 at 08:04
  • Thanks Aleksey, but can't update TestCafe. Nevertheless, I've found a way by downloading the PDF and then looking on the Download folder for the last PDF modified... And that's it! – ddou May 25 '23 at 09:43

0 Answers0