matlab.unittest.diagnostics.ScreenshotDiagnostic Class
Namespace: matlab.unittest.diagnostics
Diagnostic to capture screen as image file
Description
Use the ScreenshotDiagnostic
class to create a diagnostic that captures available screens as image files. The files persist after MATLAB® completes the test run, and so they are available for post-test inspection.
Construction
ScreenshotDiagnostic()
creates a diagnostic that captures available screens as image files. When the testing framework diagnoses the ScreenshotDiagnostic
instance, it saves the screenshots to PNG files. The files each have a unique name consisting of a prefix (Screenshot_'
, by default), an automatically generated identifier, and the file extension. An example file name is Screenshot_cf95fe7f-5a7c-4310-9c49-16c0c18a969f.png
. To view the location of the files, access the FileArtifact
object through the TestResult
instance.
ScreenshotDiagnostic('Prefix',
creates a diagnostic that saves screenshots to files with names that begin with a specified prefix.prefix
)
Input Arguments
Properties
Copy Semantics
Handle. To learn how handle classes affect copy operations, see Copying Objects.
Examples
Tips
The location of the saved screenshots is a folder with a name unique to a test run within the folder contained in the
ArtifactsRootFolder
. If you are running a test interactively, the location of the root folder is the value returned bytempdir()
.To determine the path of the saved screenshots, access the
FileArtifact
object for a particular test result. For example, assume that you have aTestResult
array,res
. Determine the location of the saved figure for the first element of the array as follows.res(1).Details.DiagnosticRecord.TestDiagnosticResults.Artifacts
ans = FileArtifact with properties: Name: "Screenshot_f51601ef-86bc-499c-bcec-203969f72a85.png" Location: "C:\work\Temp\1f4d3b64-3201-4bde-92ed-ad6859e97051" FullPath: "C:\work\Temp\1f4d3b64-3201-4bde-92ed-ad6859e97051\Screenshot_f51601ef-86bc-499c-bcec-203969f72a85.png"
If you are using a macOS system, in System Preferences, allow the Terminal app to record the contents of your screen. This permission enables
ScreenshotDiagnostic
to include open windows, such as the MATLAB desktop, when it captures the screen as an image file.
Version History
Introduced in R2017a