matlab.unittest.diagnostics.ScreenshotDiagnostic Class
Namespace: matlab.unittest.diagnostics
Superclasses: matlab.automation.diagnostics.Diagnostic
Diagnostic to capture screens as image files
Description
Use the matlab.unittest.diagnostics.ScreenshotDiagnostic class to create a diagnostic for capturing available
screens as image (PNG) files during a test run. The screenshots persist after the test run and
are available for post-test inspection.
Note
The number of PNG files produced by a ScreenshotDiagnostic object depends
on the operating system:
On Windows® and Linux® systems, the testing framework generates a single PNG file, regardless of the number of available screens.
On macOS systems, the framework generates one PNG file for each available screen.
The matlab.unittest.diagnostics.ScreenshotDiagnostic class is a handle class.
Creation
Description
diag = matlab.unittest.diagnostics.ScreenshotDiagnostic
creates a diagnostic to capture available screens as image files. When the testing
framework diagnoses the ScreenshotDiagnostic object, the framework saves
the screenshots to one or more PNG files. A generated PNG file has a unique name
consisting of a prefix ("Screenshot_", by default), an automatically
generated identifier, and the file extension. An example filename is
Screenshot_cf95fe7f-5a7c-4310-9c49-16c0c18a969f.png. To view the
location of the screenshots, access the FileArtifact object through the
corresponding TestResult instance.
Input Arguments
Properties
Examples
Tips
The location of the saved screenshots is a folder with a name unique to a test run within the artifacts root folder (specified in the
ArtifactsRootFolderproperty of the test runner). If you run tests interactively, the location is the value returned bytempdir.To determine the path of saved screenshots, access the
FileArtifactobject for a particular test result. For example, suppose that the variableresultsrepresents yourTestResultarray. This code determines the location of the saved screenshots for the first test result.results(1).Details.DiagnosticRecord.TestDiagnosticResults.Artifacts
ans = FileArtifact with properties: Name: "Screenshot_f51601ef-86bc-499c-bcec-203969f72a85.png" Location: "C:\Users\username\AppData\Local\Temp\1f4d3b64-3201-4bde-92ed-ad6859e97051" FullPath: "C:\Users\username\AppData\Local\Temp\1f4d3b64-3201-4bde-92ed-ad6859e97051\Screenshot_f51601ef-86bc-499c-bcec-203969f72a85.png"If you are using a macOS system, in System Settings, allow the Terminal app to record the contents of your screens. This permission enables
ScreenshotDiagnosticto include open windows, such as the MATLAB® desktop, when it captures the available screens as image files.
Version History
Introduced in R2017a