Skip to main content

Set SmartUI Comparison Modes at the Session Level

SmartUI now lets you declare a comparison mode once at the session level and have it apply to every screenshot in that run. Set the mode in LT:Options alongside your other capabilities, and SmartUI uses it as the default for each smartui.takeScreenshot call — no need to repeat the option on every screenshot.

This is ideal when a whole project or test suite should share the same comparison behaviour. A team can switch a project between comparison modes by changing a single capability line, while individual screenshots can still opt into a different mode when they need to.

How it works

SmartUI resolves the comparison mode for each screenshot in two layers:

LayerWhere you set itScope
Session defaultA smartUI.* capability in LT:OptionsApplies to every screenshot in the session.
Per-screenshot overrideThe options map passed to smartui.takeScreenshotApplies to that one screenshot and wins over the session default.

If a screenshot does not specify a comparison option, it inherits the session default from LT:Options. If it does specify one, the screenshot-level value takes precedence for that screenshot only. This means you can set a baseline behaviour for the run and still fine-tune individual screenshots.

Supported comparison capabilities

Set any of these in the LT:Options block for the session:

CapabilityTypeEffect
smartUI.ignoreTypearrayComparison type applied to every screenshot, for example ["layout"] for layout comparison.
smartUI.smartIgnorebooleanEnables Smart Ignore for the whole session.
smartUI.ignoreRegionsobjectSession-default ignore regions (by coordinates or selector) applied to every screenshot.
note

Set the same comparison capabilities on both the baseline and the comparison runs so the two builds are compared in the same mode.

1. Layout comparison for the whole session

Set smartUI.ignoreType to ["layout"] in LT:Options. Every screenshot in the session is then compared in layout mode, the same as passing ignoreType: ["layout"] on each individual screenshot.

import java.util.Arrays;
import java.util.HashMap;
import org.openqa.selenium.chrome.ChromeOptions;

ChromeOptions browserOptions = new ChromeOptions();
HashMap<String, Object> ltOptions = new HashMap<>();
ltOptions.put("username", System.getenv("LT_USERNAME"));
ltOptions.put("accessKey", System.getenv("LT_ACCESS_KEY"));
ltOptions.put("visual", true);
ltOptions.put("smartUI.project", "Your_Project_Name");
ltOptions.put("smartUI.ignoreType", Arrays.asList("layout")); // applies to every screenshot

browserOptions.setCapability("LT:Options", ltOptions);

With this set, your screenshot calls stay clean — no comparison option is needed on each one:

Map<String, Object> options = new HashMap<>();
options.put("screenshotName", "home-page");
((JavascriptExecutor) driver).executeScript("smartui.takeScreenshot", options);
// compared in layout mode because of the session default

2. Smart Ignore for the whole session

Set smartUI.smartIgnore to true in LT:Options to apply Smart Ignore across the session.

ltOptions.put("smartUI.project", "Your_Project_Name");
ltOptions.put("smartUI.smartIgnore", true); // applies to every screenshot

3. Ignore regions for the whole session

Set smartUI.ignoreRegions in LT:Options to apply the same ignored areas to every screenshot, so you do not have to repeat them per screenshot. Regions can be defined by coordinates or by selector.

import java.util.HashMap;

HashMap<String, Object> ignoreRegions = new HashMap<>();
ignoreRegions.put("coordinates", new String[]{"847,185,1571,734"});
ignoreRegions.put("cssSelector", new String[]{".promo-banner"});

ltOptions.put("smartUI.project", "Your_Project_Name");
ltOptions.put("smartUI.ignoreRegions", ignoreRegions); // applies to every screenshot

For the full set of coordinate and WebElement options on the Web Hooks path, see Ignore and Select Regions on Web Hooks.

4. Override the session default for one screenshot

Because the screenshot-level option always wins, you can keep a session default and still change the mode for a specific screenshot. For example, with a layout default set in LT:Options, you can compare one screenshot in the standard pixel mode by passing a different ignoreType on that call:

Map<String, Object> options = new HashMap<>();
options.put("screenshotName", "pricing-table");
options.put("ignoreType", Arrays.asList()); // override: compare this one in full detail
((JavascriptExecutor) driver).executeScript("smartui.takeScreenshot", options);

Behaviour summary

You setWhereResult
smartUI.ignoreType: ["layout"]LT:OptionsEvery screenshot uses layout comparison by default.
smartUI.smartIgnore: trueLT:OptionsSmart Ignore applied across the session.
smartUI.ignoreRegionsLT:OptionsThe same ignore regions applied to every screenshot.
A comparison option on a screenshotsmartui.takeScreenshotOverrides the session default for that screenshot only.

Baseline and comparison notes

  • Use the same smartUI.project and screenshot names across runs.
  • Apply the same comparison capabilities to both the baseline and comparison sessions.
  • Changing the comparison mode generally requires a fresh baseline.

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles