- Utility to easily integrate Applitools VisualAI with your JAVA-TestNG automation framework
- This is a library which implements basic utilities
for Applitools
(com.applitools)
- Dashboard link: https://eyes.applitools.com/
mvn clean install -DskipTests
If facing issues with dependencies not being resolved from https://jitpack.io, then check the
settings.xml
file you're using for building your maven projects. If you've proxies configured in the same, then make surejitpack.io
is part ofnonProxyHosts
configuration. For instance
<proxy>
<id>httpmyproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>someHost</host>
<port>8080</port>
<username>UserName</username>
<password>Password</password>
<nonProxyHosts>*.google.com|*jitpack.io</nonProxyHosts>
</proxy>
<dependency>
<groupId>com.github.znsio</groupId>
<artifactId>ApplitoolsIntegration</artifactId>
<version>x.x.x</version>
</dependency>
-
To disable visual validation for the tests, set
IS_VISUAL
tofalse
in config properties of your automation framework repo -
For running visual validations:
- Set
IS_VISUAL
totrue
in config properties of your automation framework repo - Set the environment variable for
APPLITOOLS_API_KEY
like thisApplitools API Key can be picked from user Dashboardexport APPLITOOLS_API_KEY=<Your API KEY>
https://eyes.applitools.com/
- Properties file: Create a
applitools.properties
file either insrc/test/resources
directory in your automation framework. Specify the path of the file in youconfig.properties
of your automation framework like this:TheAPPLITOOLS_CONFIGURATION_FILE=./src/test/resources/applitools.properties
applitools.properties
file should have the following mandatory attributes:SERVER_URL=https://eyes.applitools.com/ CONCURRENCY=<Integer Value> MATCH_LEVEL=strict SEND_DOM=<true or false> STITCH_MODE=css TAKE_FULL_PAGE_SCREENSHOT=<true or false> VIEWPORT_SIZE=1200x700 USE_UFG=<true or false> SHOW_LOGS=<true or false> SAVE_BASELINE_FOR_NEW_TESTS=<true or false> FAIL_TEST_WHEN_DIFFERENCE_FOUND=<true or false>
- Annotate the test with the
visual
TestNG group annotation which you want to run as part of visual validation. If the test is not part ofvisual
group, visual validations will not take place for that test even ifIS_DISABLED
value is set tofalse
and test contains theeyes
validations. For instance,@Test(description = "Validating login with valid username and password", groups = {"visual"}) public void validLoginTest(String username, String password, String expectedMessage) throws InterruptedException { performLogin(username, password); verifyMessageAfterLogin(expectedMessage); }
- To perform Visual Validations on a test, add any of the following commands in the test wherever you need to run
visual validation. Use one of the following approaches:
-
The eyes check window command captures an image of all the content in the browser window. When capturing on a
local browser/App, If the content in the window is larger than the viewport, then the command captures
multiple images at different offsets in the window and stitches them together to obtain an image that
includes all the content in the window.
For Instance:
eyes.checkWindow("<A string message giving info about which screen you're validating>");
eyes.checkWindow("HomePage");
-
In the Fluent API you create and configure checkpoints using the eyes$check method. You pass this method a
parameter that is created from a chain of methods calls from the target and checksettings classes. The
particular chain of methods you call, determines the target that will be checked and how it is configured.
eyes.check("<string message>", <constraints>);
- For instance
eyes.check("Home Page", Target.window().strict() .layout(By.xpath("//div[@class='ReactVirtualized__Grid items']"), By.id("breadcrumb-container"), By.className("//div[@class=' breadcrumb-section']")) .ignore(By.xpath("//div[@class='component-layout']//div[@class" + "='img-animate'][1]"), By.xpath("//div[@class='banner-components-runtime']/div")));
- For more detailed explanation and different examples, visit URL: The Eyes SDK check Fluent API
- For instance
-
The eyes check window command captures an image of all the content in the browser window. When capturing on a
local browser/App, If the content in the window is larger than the viewport, then the command captures
multiple images at different offsets in the window and stitches them together to obtain an image that
includes all the content in the window.
-
Applitools Ultrafast Grid allows you to perform visual testing across multiple browsers and devices in seconds,
to make sure that your content is visually perfect on every device, screen size, and browser combination. To Run
Visual Validations on multiple Browser Types Using Ultra Fast Grid, Set
USE_UFG
totrue
inapplitools.properties
file of your automation framework repo. Browser Combination need to be added insetUFGBrowserConfig(Configuration eyesConfig)
underApplitoolsConfigurationManager
class as illustrated in Below example:For More Details on Configuring Ultra Fast Grid, Visit: Ultrafast Grid configurationeyesConfig.addBrowser(1512, 866, BrowserType.CHROME); eyesConfig.addBrowser(1600, 1200, BrowserType.FIREFOX); eyesConfig.addBrowser(1024, 768, BrowserType.SAFARI); eyesConfig.addDeviceEmulation(DeviceName.Galaxy_Note_10); eyesConfig.addDeviceEmulation(DeviceName.iPhone_11_Pro_Max);
-
- Incorrect Viewport size will cause the tests to be skipped with exception
as
EyesException: Unable to set Viewport Size
. - In that case, follow the below process to set Viewport Size Correctly:
- Navigate to Site:
https://whatismyviewport.com/
to get the viewport size. - Set the Viewport size in
VIEWPORT_SIZE
in format:Widthxheight
inapplitools.properties
file of your automation framework repo
- Navigate to Site:
- Incorrect Viewport size will cause the tests to be skipped with exception
as
- Set
-
Dynamic properties: For setting any additional property to either batch/test properties which is not already configured in
ApplitoolsConfigurationManager
class, set that attribute key and value at either System Property level or at Environment variable. Any key with prefixAP_BATCH_
(for Batch Property) orAP_TEST_
(for Test property) set at System property or Environment variable level will be set as Applitools's Batch/Test property respectively. The method which takes care of this configuration issetPropertiesFromSystemVariables
defined insideApplitoolsConfigurationManager
class. For instance, if you're setting environment variable likeexport AP_BATCH_Version=0.0.1
andexport AP_TEST_Version=0.0.1
, then on Applitools dashboard, you'll see the corresponding properties asVersion:0.0.1
for Batch/Test property respectively -
Pipeline configuration:
- Set an environment variable
IS_VISUAL
totrue
for configuring visual validations for pipeline executions. This property takes precedence over theIS_VISUAL
property value ofconfig.properties
in your automation framework repo. - The
ApplitoolsConfigurationManager
class takes care of setting the following batch/test properties in case the test execution is happening on CI (Pipeline)All these properties will be set as either batch/test properties if the execution is happening on CI, and if they are either set at System property or System environment variable. If your pipeline is using different keys to set the above attributes then the ones we're using above, for each such key, you can define the new key value in theBUILD_ID AGENT_NAME BRANCH_NAME
config.proprties
file of your automation framework like below:BUILD_ID=BUILD_BUILDID BRANCH_NAME=BUILD_SOURCEBRANCHNAME
- Set an environment variable