Selenium Ruby overview
This SDK allows you to work with Applitools Eyes using Selenium Ruby.
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 set the environment variable APPLITOOLS_API_KEY
to the API key provided from Applitools Eyes. For details how to retrieve your API key, see the Applitools documentation.
Entering the API Key on Linux or a Mac
export APPLITOOLS_API_KEY=<API_key>
Entering the API Key on Windows
set APPLITOOLS_API_KEY=<API_key>
Eyes server URL
If the Eyes server is not deployed in https://eyes.applitools.com
, you need to set the Server URL in the environment variable APPLITOOLS_SERVER_URL
before running tests.
The server URL of your Applitools Eyes dashboard is in the format https://<MY_COMPANY>.applitools.com
Entering the server URL on Linux or a Mac
export APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>
Entering the server URL on Windows
set APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>
Recommended practice for using the SDK
A test in Applitools Eyes always starts with a eyes.open
call and ends with eyes.close
. The steps in the test are calls to eyes.check
between eyes.open
and eyes.close
calls.
A test is structured as following:
eyes.open
[step 1]
[step 2]
...
eyes.close
Runner
This SDK uses the following Runner classes:
- ClassicRunner - Used when running multiple Eyes sessions.
- VisualGridRunner - Used to manage sessions when working with the Ultrafast Grid.
ClassicRunner class
An object of this class is used to manage multiple Eyes sessions when working without the Ultrafast Grid
Constructor
To define the class:
runner = Applitools::ClassicRunner.new
VisualGrid runner
An object of this class is used to manage multiple Eyes sessions when working with the Ultrafast Grid.
Constructor
To define the class:
test_concurrency = 5
runner = Applitools::Selenium::VisualGridRunner.new(test_concurrency)
GetAllTestResults
This command returns an object with the results from a test or test file. This command should be called after all Eyes tests have been completed.
Example
all_test_results = runner.get_all_test_results
puts all_test_results
Eyes class
Eyes Class enables visual testing with Applitools Eyes.
Constructor
To define the class:
eyes = Applitools::Selenium::Eyes.new(runner: runner)
eyes.open
This method creates an Eyes test. This will start a session with the Applitools server.
eyes.open(driver: driver, app_name: 'app name', test_name: 'test name', viewport_size: {width: width, height: height})
Where:
-
driver - Your web driver
-
"app name" - The application name, this may be any string. You can set the application name for all tests using the
Configuration.setAppName
. -
"test name" - The name of the test. This name must be unique within the scope of the application name. It may be any string.
-
viewport_size:
{width: width, height: height}
(Optional) - Defines the viewport size of the browser that will be set before the start of the test. If this parameter is not provided, the viewport size will be based on the current browser window size.
eyes.check
This command generate a screenshot of the current page and adds it to the Eyes test.
eyes.check(Applitools::Selenium::Target.window)
eyes.close_async
Closes the Eyes test but does not wait for the Eyes server to return a result. This command enables your system to continue running tests while Eyes completes its comparisons in the background. You should call this command at the end of each test, symmetrically to eyes.open
.
After executing all Eyes tests, your code should call Runner.getAllTestResults
to retrieve all test results as a TestResultsSummary
.
eyes.close_async()
eyes.close
Closes the Eyes test and waits for the Eyes Server to return a single result. The close
command then returns a TestResults
object with detailed test result data. This method takes an optional boolean parameter, if false
it will not throw an exception if the test found differences (default is true
). You should call this command at the end of each test, symmetrically to eyes.open
.
This is a legacy API as it only returns a single result. We recommend using eyes.close_async
and eyes.get_result
instead of this API.
eyes.close()
\\or
eyes.close(false)
Return value: TestResults
Logs
Log files are automatically saved in the temp directory of the machine the tests ran on.
By default, the log directory is <os temp directory>/applitools-logs
You can locate it as follows:
- Mac/Linux:
$TMPDIR/applitools-logs/
- Windows:
%Temp%/applitools-logs/
When running the tests remotely, you can specify the path to the logs using the environment variable APPLITOOLS_LOG_DIR=<full path to log_dir>
Other Significant class
When working with this SDK, you should be familiar with the following class:
-
BatchInfo class - To configure the batch for one or more test, use the following to call the
BatchInfo
method with an object of this class:config = Configuration.new
config.batch = BatchInfo("Name of the batch") -
Configuration class - Creates a configuration object that is used to configure an Eyes object by passing it to the
Eyes.set_configuration
method:eyes = Eyes.new
eyes.set_configuration(config)