close method

Class: EyesPlatform: Selenium Language: JavaScript

Call this method at the end of the test. This terminates the sequence of checkpoints, and then waits synchronously for the test results and returns them.


let  promise = eyes.close(throwEx);


If this parameter has a value of true, then if there are new, missing, or mismatched steps, an exception will be thrown. If the parameter is set to false, then an exception will not be thrown for the above cases. If the parameter is not passed, then it is as if a true value was passed.

Return value

Type: Promise<TestResult>

The result of the test can be obtained from the object returned. See TestResults class for a list of what information can be obtained from this object. See TestResults class for a list of what information can be obtained from this object.


The example below shows a basic skeleton of an Eyes visual test using Selenium. For a more detailed example and explanation please see Writing visual tests with the Eyes SDK.

The main points to note are:
  • The first step is to instantiate an object of the class. Using this object, you call various methods and properties to configure and run your visual tests. When the constructor is called without a parameter, then the checkpoints are taken from screenshots on a browser running on your test computer. To use the Visual Grid to render the checkpoint screenshots see Setting up and configuring the Visual Grid.
  • In order to do a visual test you have to provide your API Key. In this example we show the value being obained from an environment variable.If the environment variable APPLITOOLS_API_KEY is defined then Eyes will automatically use that value as the API key, and you don't need to use the . To obtain your key see How to obtain your API key
  • You access the web page you are testing, and provide mouse and keyboard events using the platform driver. In this example we create a chrome driver.
  • Before you start your test there are various configuration you can do that affect the default way images are captured or the way the image is processed. For example,
    					In this snippet, the 
    			is set to ensure that the entire webpage is captured even if it is larger than the viewport. As another example, the   
    					is configured here so that the image matching is done less strictly (instead of the default Strict match level). For example if the text on the page is dynamic, you can use the layout match level and  Eyes will check the general layout of the page but will not report mismatches due to text or image differences.
    If a particular checkpoint needs a different configuration then you can use the Fluent API to change some of the configuration options. 
  • Now you start a test. The first parameter you pass is the webdriver you created previously in step 3. You also pass two strings, an application name and test name that together uniquely identifier this test, and optionally, the viewport size, which defines the viewport of the widow in which the application run. These three values, along with the browser and operating system type determine the baseline that will be used for matching. The baselines provides the reference images to which , your test checkpoints images will be compared. For more information on this see Using viewports in Eyes. The method returns a web driver which is a clone of the web driver you passed as a parameter. In most cases you should use this returned web driver instance for further calls to the web driver.
  • Now you use the web driver to navigate the browser to the test URL.
  • Next comes the heart of visual testing - telling eyes to capture a screenshot image and to send it to the Eyes server for processing. The checkwindow method used here is the simplest way to execute a checkpoint, when what you want is to test the entire window. In cases where parts of the window need to be ignored, need a different match level, or need some other special processing, use the check method and the Fluent API methods. See The Eyes SDK check Fluent API for more details and examples. You may call as many check points as you want, typically you will call the web driver to surf to different pages, click buttons or menus, enter text and so on to fully exercise your UI and call checkwindow or check or check_region or one of the other check calls. in each state.
  • When you're done calling all your test points, call the close method. If you pass a false value to this method then it will return the results of the test. If you don't pass a parameter or pass a true value then if the test passes then the method will return normally, if there are any mismatches, or new or missing steps, then an exception will be thrown.
  • Since an exception may be thrown during the test, the call to close may be skipped, so always wrap your test in an exception handler and call abortifnotclosed to correctly terminate the test.
  • Finally you should quit your web driver.