How to Save an ATEasy Test Log to a PDF file

Knowledge Base Article # Q200332

Read Prior Article
Summary This article will explain how Save as PDF support can be added to the ATEasy Test Executive driver.
  
Login to rate article

Introduction

When saving an ATEasy Log, the Test Executive supports the following formats: Log Files (.log), HTML Files (.htm, .html), Text Files (.txt), and HTML Web Archive Files (.mht).  From the Test Executive, the Save As selection can be accessed from the Log Menu (Figure 1).  HTML is set as the default option, but the user can scroll through the format list to view and select other available options (Figure 2).

This article will demonstrate the process for implementing ATEasy Test Executive options for saving PDF Test Log files.

Log Menu Save As
Figure 1 – Log Menu Save As


Log Menu Save As Options
Figure 2 – Log Menu Save As Options


Overview

For the Test Executive to support saving a test log as a PDF file, a Procedure needs to be created that will perform the task.  And the Test Executive needs to be customized to allow the operator a means to execute the new procedure.  Since the Test Executive driver is included as part of the ATEasy installation, any modifications made directly to the driver risk being over-written when updating your ATEasy installation or applying patches.  For this reason, the method presented in this article will avoid directly changing the Test Executive code, and instead will use the Test Executive Tools:Customize utility built into the Test Executive to add the functionality as an extension to the Test Executive.  The Test Executive extensions are saved in the ATEasy USR file and become a permanent extension to the Test Executive - without the need to modify the Test Executive directly.  Future versions of the ATEasy Test Executive released by Marvin Test Solutions can continue to take advantage of the added functionality.

The process for adding the PDF save function is:
-  Create "LogSavePdf" Procedure in the System module
-  Customize the ATEasyTest Executive to add a new Log Menu selection and a new Toolbar Button to call the PDF save procedure
-  Test the new procedure and Test Executive customizations

NOTE: The save as PDF function utilizes the Print-to-PDF functionality built into the Microsoft Edge® browser that is installed with Windows®.  While there are many other applications that provide similar functionality, they would only be available to systems where those applications have been installed.  Since Edge is installed with all later versions of Windows, the functionality described in this article is available without the need to install, or purchase, any other applications.

For details of how this process works, see:  Convert HTML to PDF by Using Microsoft Edge

Create New Save PDF Procedure

A new procedure, LogSavePdf, is inserted in the System module, Procedures submodule.  The procedure could be inserted into a driver, but this would require the driver to be installed in every ATEasy application where the functionality is desired.  Placing it in the System module and using that module as the standard System configuration going forward, allows all future ATEasy applications the ability of saving PDF test logs.

The procedure is self-contained; it does not require any parameters, and variables used within the procedure are local to the procedure to support the save PDF process.  The full variable list for the procedure is shown below.

logToSave: ALog
sPdfFile: String
sWinExecCmd: String
lFlagSignal: Long
hWinExecHandle: AHandle
sHtmlFile: String


The LogSavePdf() procedure uses existing ATEasy Test Executive controls and methods - specifically, the formTestExec.cdlg Common Dialog control and it's ShowSaveAs() method.  The Common Dialog control is used to enter/select the PDF file to use for saving the test log, and has various properties associated with it that govern the look and operation of the dialog.  The code below configures certain dialog properties before calling the ShowSaveAs() method, which then launches the file navigation dialog.

!  Set Test Executive ShowSaveAs dialog properties
TestExec.m_frmMain.cdlg.DialogTitle = "Save Log As PDF"
TestExec.m_frmMain.cdlg.Filter = "PDF Log Files (*.pdf)|*.pdf"
TestExec.m_frmMain.cdlg.InitialDir = GetDir() + "\\"

!  Call the Test Executive ShowSaveAs method/dialog
if TestExec.m_frmMain.cdlg.ShowSaveAs() = acdlgRetValCancel then return
TestExec.m_frmMain.cdlg.FilterIndex = 2 ! Reset the control filter to HTML (2)


A successful return of the ShowSaveAs() dialog will contain the PDF file name and path in the FileName property.  This is used for saving both a PDF version of the test log, as well as a temporary HTML version of the log.  The Edge Print-to-PDF function uses an HTML file as the print source, so a temporary HTML file is created using the same file name and path as the PDF file, substituting the ".HTM" extension in place of ".PDF".  Previous versions of the HTML file, if any exist, are removed before saving the new HTML formatted test log.

! create HTML path/file - temporary
sHtmlFile = Replace(TestExec.m_frmMain.cdlg.FileName, ".pdf", ".htm")
lWinExecSignal = FileRemove(sHtmlFile) ! Remove old HTML file - if exists


As ATEasy's Test Executive supports Multiple UUT testing, where each UUT is provided its own test log tab, it is necessary to select the Active Log for the PDF conversion.  This is done using the public Test Executive GetLog() procedure.  This procedure will return the ALog object of the current active test log selected using the UUT tabs located above the test log results.  The log object is saved to an ALog-type variable logToSave.  The SaveAs() method for the ALog object is called, resulting in an HTML file for the active test log being saved.  If there is an error during the save, an error message is displayed.

! get log object for active UUT
logToSave = GetLog(ateLogActive, - 1)

if logToSave.SaveAs(sHtmlFile, False) = alogSaveFailed
    MsgBox("Unable to save log file: '" + sHtmlFile + "'", aMsgOk, "Save PDF Error") ! Note the single quote usage '
    return
endif


The Edge Print-to-PDF command line script for printing an HTML file to a PDF file requires that the PDF file path and name to be surrounded by quotes.  These quotes are added as prefix and suffix escape characters ("\"").  The old PDF file is removed, and an Edge command line script is created as outlined in the article linked above.  The command line is executed using ATEasy's WinExec() command to launch Edge in silent mode (headless) and print the temporary HTML file as a PDF file.  After WinExec() completes, the temporary HTML file is removed.

! Create PDF path/file
sPdfFile = "\"" + TestExec.m_frmMain.cdlg.FileName + "\""

! Remove old PDF file - if exists
lFlagSignal = FileRemove(TestExec.m_frmMain.cdlg.FileName) ! remove old PDF

! create WinExec() command using Edge --print-to-pdf function
sWinExecCmd = "msedge.exe --headless --disable-gpu --run-all-compositor-stages-before-draw " + sHtmlFile + " --print-to-pdf=" + sPdfFile

! Execute WinExec command
hWinExecHandle = WinExec(sWinExecCmd)
lFlagSignal = WaitForSingleObject(hWinExecHandle, 10000) ! wait for WinExec signal

! Remove temporary HTML file
FileRemove(sHtmlFile)


Add Test Executive Hooks (Extension)

For the following section, refer to the Knowledge-Base article Adding Custom Commands to ATEasy Test Executive

To call the LogSavePdf() procedure we need to customize the Test Executive to add hooks to the LogSavePdf() procedure.  We do this by defining a new Test Executive command, and linking that command to new menu selections, toolbar buttons, or form selections.  From the Test Executive Tools:Customize menu, create a new User Command similar to the "SavePdf" command shown in Figure 3.  Fill in the Name, Captions and Description, and enter the System Procedure created above in "Procedure" and click the Check Box.  An error message will be displayed if the procedure cannot be found.  Finally, link an image that you would like associated with the new command.  This image can be BMP, JPG or PNG, and should be sized approximately 150 x 150 pixels.

This example used the following PNG image:  PdfIcon.png Image

To add the PDF save function to the Test Executive menu and to the Test Executive toolbar, follow the examples shown in Figure 4 and Figure 5.

Custom User Defined Command   Configure Menu Save PDF Log Selection   Configure Toolbar Save PDF Log Button
Figure 3 - Customize Command                       Figure 4 - Customize Menu Selection                      Figure 5 - Customize Toolbar


Testing The New Functions

To test the Save to PDF functions we added, we need a test program to generate a test log to save.  Since the PDF save is designed to work with multiple UUTs, it would be helpful to generate a test log the uniquely identifies the UUT number in the PDF log.  The Task/Test structure in Figure 6 below will simply display the UUT number as the Result value in the test log.

Program Task/Test Structure
Figure 6 - Program Task/Test Structure


Running the project will open the Test Executive as normal, but new menu options and toolbar buttons are available that allow saving the test log as a PDF file, see Figure 7.

Menu and Toolbar Save PDF Log Options
Figure 7 - Save PDF Menu and Toolbar Options


If the newly created System LogSavePdf() procedure is not copied to future projects, the Save PDF Log option in the Menu and Toolbar will be grayed-out - see Figure 8.  This is a reminder to copy the procedure to any new project where the ability to save a PDF test log is desired.

Menu and Toolbar Save PDF Log Options Disabled
Figure 8 - Save PDF Menu and Toolbar Options Disabled


Conclusion

This article demonstrated the process for adding a System procedure that uses the Edge Print-to-PDF capability to save an ATEasy Test Log to a PDF file.  Also demonstrated were the steps to add Save As PDF options to the ATEasy Test Executive Log Menu and Toolbar.

A copy of the ATEasy DownloadSaveAsPdf Project can be downloaded here.

See also:  Word VBA reference© and Document.ExportAsFixedFormat Method©
Article Date 12/7/2024 , 12/10/2024
Keywords Save PDF, Test Executive, Customizing ATEasy, Test Logs, WinExec(), Edge


Login to rate article

1 ratings | 5 out of 5
Read Prior Article