Use the mobile testing functionality to capture screenshots during automated test runs. You can configure specific paths and filenames for screenshots or rely on default settings.
Configure screenshot options
Mobile testing uses a specific function for configuring screenshots. Users can define custom paths and filenames using the ScreenshotOptions object or set these values to null to use default options which allows screenshots to be saved in a specific directory with a chosen file name.
Example usage
ScreenshotOptions screenshotOptions = new ScreenshotOptions("/custom/directory/path", "test-screenshot.jpg");
ScanOptions scanOptions = new ScanOptions.Builder()
.screenshotOptions(screenshotOptions)
.build();
This will saves a screenshot in /custom/directory/path with the filename test-screenshot.jpg.
Default options
If a path or filename is not specified (null), default settings are used. This simplifies the configuration while ensuring screenshots are still captured.
- Default path: resources / screenshots
- Default filename: A unique identifier <UUID>. jpg
Example usage
ScreenshotOptions screenshotOptions = new ScreenshotOptions(null, null);
ScanOptions scanOptions = new ScanOptions.Builder()
.screenshotOptions(screenshotOptions)
.build();
The screenshot will be saved in the resources/screenshots directory with a filename in the format 123e4567-e89b-12d3-a456-426614174000.jpg.
If the ScreenshotOptions object is not passed to the ScanOptions builder, no screenshot will be captured during the test run.
Error handling
The SDK provides error handling if a screenshot cannot be saved. Common causes include:
- File Permissions: Insufficient permissions to write to the specified directory.
- Cloud Storage Issues: If saving to a cloud path, network issues may prevent the file from being uploaded.
- File Path Limitations: Some operating systems have maximum path lengths, and exceeding this may result in an error.
When an error occurs, the SDK generates a default error message. This message may vary based on the operating system and provides feedback to help users troubleshoot the issue.
Error messages are operating system specific and may contain additional information depending on the cause.
Comments
0 comments
Article is closed for comments.