The WebLibrary collection provides user code methods that simplify complex web testing tasks. These methods allow you to download files, check server status codes, and capture comprehensive screenshots without writing custom scripts.
WebLibrary methods
To use these methods, add them to your recording module. For more information, see Using the User Code Library.
DownloadFile
This method simplifies downloading a file from a web address during your web test execution.
Arguments:
- String URI: The web address of the file to download. The test fails if the address is incorrect or the file is missing.
- String localPath: The folder path where you want to save the file. Can be absolute or relative. If you leave this empty, the method saves the file in your solution's output folder.
- Boolean overwriteExisting: Set to true to replace an existing file with the same name. Set to false to abort the download and issue a warning if the file already exists.
Results in the report:
- Report showing successful download of the file.
- Report showing aborted download, as the file already existed and overwriteExisting was set to false.
- Report showing a failed module because the file could not be downloaded.
GetHttpStatusCode
This method checks a specific URL and returns the HTTP status code.
Arguments:
- String URL: The address of the website you want to check.
You can bind the resulting status code value of type String to a variable for use in subsequent validation steps.
Results in the report:
ReportFullPageScreenshot
This method captures a screenshot of an entire webpage, including content not currently visible on the screen.
Arguments:
- RepoItemInfo repoItemInfo: The repository item representing the webpage. The method logs an error if the item is not a valid webpage, though the module itself does not fail.
The method saves the screenshot in the output folder and includes it in the Ranorex Report.