XCUI overview
This SDK allows you to work with Applitools Eyes using XCUI.
Installation
Using Swift Package Manager
In Xcode, select File > Add Packages... then add the GitHub URL of EyesXCUI:
https://github.com/applitools/eyes-xcui-swift-package.git
Using CocoaPods
Add EyesXCUI
to your podfile:
target ‘YOUR_APPLICATION_TARGET_NAME’ do
target ‘YOUR_UNIT_TESTING_TARGET_NAME’ do
pod 'EyesXCUI'
end
end
Getting started
To get started with this SDK, you need to set the following:
- Applitools API key
- Eyes server URL - Required only if the Eyes server is not deployed on the Eyes public server.
Entering the Applitools API key
To authenticate via the Applitools server and run tests, you need to assign the API key provided from Applitools Eyes to the XCUI Eyes instance. For details how to retrieve your API key, see the Applitools documentation.
let eyes = Eyes()
eyes.apiKey = <API_key>
Eyes server URL
If the Eyes server is not deployed at https://eyes.applitools.com
, you need to assign the server URL to the XCUI Eyes instance before running tests.
The server URL of your Applitools Eyes dashboard is in the format https://<MY_COMPANY>.applitools.com
eyes.serverURL = <YOUR_SERVER_URL>
Recommended practice for using the SDK
A test in Applitools Eyes always starts with an eyes.open()
call and ends with eyes.close()
. The steps in the test are calls to eyes.check()
between the eyes.open()
and eyes.close()
calls.
A test is structured as follows:
eyes.open(...)
[step 1]
[step 2]
...
eyes.close()
Common methods
Open
Creates an Eyes test and starts a session with the Applitools server.
Syntax
eyes.open(withApplicationName: appName, testName: testName)
example
eyes.open(withApplicationName: "Hello World!", testName: "My first test using EyesXCUI SDK")
Check
Generates a screenshot of the current page and add it to the Eyes test.
Syntax
eyes.check(withTag: tag, andSettings: checkSettings);
Example
eyes.check(withTag: "Hello", andSettings: Target.window().fully())
For a description of common actions with this class, see check Settings
Close
Closes the Eyes test and validates all screenshots. Make sure to call this method at the end of each test, corresponding to the initial open
call.
try eyes.close()
Visual tests and baselines
Using the open
, check
, and close
methods of Eyes
creates visual tests in Applitools Eyes. A visual test compares a sequence of screenshots against a baseline. The baseline is determined based on:
- App name
- Test name
- Operating system version
- Viewport size (defined by device size and orientation)
The baseline is automatically created during the first test execution with specific parameter values. For example, if you run a test on iOS 16 and specify the app name and test name via eyes.open(withApplicationName:"some app", testName:"some test")
, the first time the test runs with these parameters, on this specific operating system version and viewport size combination, a baseline will be created. Any subsequent execution with the same values will compare screenshots against this baseline. The test is finalized after running eyes.close()
, and the results of the test are returned as a TestResults
object.
For more information, see How Eyes compares checkpoints and baseline images