Skip to main content

Running with a try-with-resources statement

We recommend that you use a testing framework when running an Eyes test. Although it is possible to run a test using Java's main(), this method does not automatically close all resources; a resource is an object that must be closed after the program is finished with it. When resources are still being used, and are not closed, it will cause the main method to get stuck in an endless loop waiting for the resources to be closed.

To prevent this problem, we recommend that you use the try-with-resources statement. This statement is a try statement that declares one or more resources, but ensures that each resource is closed at the end of the statement. This prevents Eyes from getting stuck in an endless loop.

Example‚Äč

try(ClassicRunner runner = new ClassicRunner()) {
Eyes eyes = new Eyes(runner);
eyes.open(driver, "try-with-resources", "try-with-resources");
eyes.check(Target.window().fully(true));
eyes.close(false);
TestResultsSummary results = runner.getAllTestResults(false);
System.out.println(results);
}