Skip to main content

Using Applitools Eyes with Katalon Studio

Katalon is a powerful solution that helps you automate Web, API, Mobile, and Desktop apps. The software is built on top of the open-source automation frameworks Selenium and Appium so this means that you can easily add Applitools visual testing into your Katalon test scripts.

Below are two complete examples of how to add Applitools Eyes to your Katalon tests.

Test Web application

This example includes 2 modes of running Eyes

  1. ClassicRunner - use your driver to run the test and grab screenshots locally
  2. VisualGridRunner - use your driver to run the test and grab screenshots using Applitools Ultrafast Grid on multiple browsers, viewport sizes, and devices.

To switch between the 2 modes simply change the runOnGrid boolean flag in the example.

Configuration

  1. Add gradle.build file to your Katalon project

  2. Add Applitools dependency to the gradle.build file

    dependencies {
    compile ('com.applitools:eyes-selenium-java3:+')
    }
  3. Open your terminal, navigate to the root of your Katalon project, run the following command gradle katalonCopyDependencies

  4. Restart Katalon Studio (Do not skip this step)

Katalon Test Script

import org.openqa.selenium.WebDriver
import org.openqa.selenium.remote.RemoteWebDriver
import org.openqa.selenium.support.events.EventFiringWebDriver
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import com.applitools.eyes.EyesRunner
import com.applitools.eyes.RectangleSize
import com.applitools.eyes.TestResultsSummary
import com.applitools.eyes.selenium.BrowserType
import com.applitools.eyes.selenium.ClassicRunner
import com.applitools.eyes.selenium.Configuration
import com.applitools.eyes.selenium.Eyes
import com.applitools.eyes.selenium.StitchMode
import com.applitools.eyes.selenium.fluent.Target
import com.applitools.eyes.visualgrid.model.DeviceName
import com.applitools.eyes.visualgrid.services.VisualGridRunner


WebUI.openBrowser('')

WebUI.navigateToUrl('https://demo.applitools.com/')

// Cast Katalon's WebDriver into EventFiringWebDriver
EventFiringWebDriver eventFiring = (EventFiringWebDriver) DriverFactory.getWebDriver()

// Get the driver wrapped inside
WebDriver wrappedWebDriver = eventFiring.getWrappedDriver()

// Cast the wrapped driver into RemoteWebDriver
RemoteWebDriver innerDriver = (RemoteWebDriver) wrappedWebDriver

EyesRunner runner = null

// set this flag to true to make it run on Applitools Visual Grid
boolean runOnGrid = false

String testName = "My Katalon Web Test Name"
String appName = "My Katalon Web App Name"

if(runOnGrid == true)
{
runner = new VisualGridRunner(10)
testName += " (Grid)"
}
else
{
runner = new ClassicRunner()
}

Eyes eyes = new Eyes(runner)

Configuration config = eyes.getConfiguration()

config.setApiKey("YOUR_APPLITOOLS_API_KEY")
config.setViewportSize(new RectangleSize(1200,600))
config.setAppName(appName)
config.setTestName(testName)

if(runOnGrid == true)
{
config.addBrowser(1200,600,BrowserType.CHROME)
config.addBrowser(1200,600,BrowserType.FIREFOX)

config.addDeviceEmulation(DeviceName.iPhone6_7_8_Plus)
}
else
{
config.setForceFullPageScreenshot(true)
config.setStitchMode(StitchMode.CSS)
}

eyes.setConfiguration(config)

eyes.open(innerDriver)

eyes.check(Target.window().fully().withName("My First Screenshot"))

eyes.closeAsync()

TestResultsSummary result = runner.getAllTestResults(false);

WebUI.comment(result.toString())

WebUI.closeBrowser()

Test Native Mobile Application

Configuration

  1. Add gradle.build file to your Katalon project

  2. Add Applitools dependency to the gradle.build file

    dependencies {
    compile ('com.applitools:eyes-appium-java4:+')
    }

    OR (in case you get conflict errors due to an already existing jersey library in your project use this configuration instead)

    dependencies {
    compile ('com.applitools:eyes-appium-java4:+')
    {
    exclude module: 'eyes-connectivity-java4-jersey2x'
    }
    compile ('com.applitools:eyes-connectivity-java4-jersey1x:+')
    }
  3. Open your terminal, navigate to the root of your Katalon project, run the following command gradle katalonCopyDependencies

  4. Restart Katalon Studio (Do not skip this step)

Katalon Test Script

import org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.deleteClause_scope
import org.openqa.selenium.By as By
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
import io.appium.java_client.AppiumDriver as AppiumDriver

import com.applitools.eyes.appium.Eyes
import com.applitools.eyes.appium.Target

Mobile.startApplication("YOUR_APP.apk", true)

AppiumDriver<?> driver = MobileDriverFactory.getDriver()

Eyes eyes = new Eyes()

eyes.setForceFullPageScreenshot(true)

eyes.setApiKey('YOUR_APPLITOOLS_API_KEY')

eyes.open(driver, 'My Katalon Native App Name', 'My Katalon Native App Test Name')

eyes.checkWindow("My First Screenshot")

eyes.close(false)

Mobile.closeApplication()