Screenshots Ruby Tutorial

1. 🤖 How it works

Applitools Screenshots SDKs work by taking screenshots of an image or a region and uploading them to our Eyes server. Our AI then compares them with previous test executions' screenshots (aka Baselines) and reports if there is a difference or not. It's that simple!

Applitools AI with RCA picture

1.1 Baseline vs. Checkpoint images

When you first run the test, our A.I. server stores those first set of screenshots as Baseline images. When you run the same test again (and everytime there after), the A.I. server compares the new set of screenshots, aka Checkpoint images, with the corresponding Baseline images and highlights differences in a pink color.

Baseline vs Checkpoint
The picture above is showing the Side-by-Side view of the baseline and checkpoint images

1.2 Marking the test as "Pass" or "Fail"

When the AI compares the baseline and the checkpoint image, if it finds a legitimate difference, it will mark the test as Unresolved. This is because the AI doesn't know if the difference is because of a new feature or a real bug and will wait for you to manually mark it as a Pass/Fail for the 1st time.

If you mark the unresolved checkpoint image as a "Fail", any further runs with similar difference will be automatically marked as "Failed".

Mark the checkpoint as a fail
The picture above is showing how to mark the checkpoint image as Failed

If you mark the unresolved checkpoint image as a "Pass", then it means that the difference is due to a new feature so we set the new checkpoint image as the new baseline and mark the current test as Pass. Going forward we'll compare any future tests with this new baseline.

Mark the checkpoint as a Pass
The picture above is showing how to mark the checkpoint image as Passed

Note:

  • Applitools AI has been trained with 100s of millions of images. It doesn't do pixel-to-pixel comparison because this can lead to a lot of false positives. It instead simulates human eyes that ignore differences humans can't detect and highlight differences that humans can detect.

  • ACCURACY: Our A.I.'s current accuracy rate is 99.9999%! Which means for most applications the odds that you'll see false-positives are 1 in a million!

A powerful test results dashboard

We provide a state-of-the-art dashboard that makes it very easy for you to analyze differences, report bugs and much more. For more information on the Applitools dashboard check out these articles.

Seeing test result summary
The picture above is showing the summary view
2. 🖼 Analyzing differences

The following Gifs show various tools Applitools provides to easily analyze various differences

Highlight differences between the baseline and checkpoint

Highlight diffs

Zoom into differences

Zoom into diffs

Toggle between baseline and checkpoint

Toggle differences between baseline and checkpoint

Show both the baseline and checkpoint side-by-side

Show both baseline and checkpoint side-by-side
3. 🐞 Reporting bugs (straight into Jira or Github)

You can select a section of the image and directly file a bug in Jira or Github. No need to manually take screenshots, write steps and explain things! To read more about bug regions check out this article.

Reporting bugs to Jira or Github
4. ✅ Prerequisites
  1. Create a free Applitools account and get your Applitools API KEY API-key

  2. Set the APPLITOOLS_API_KEY environment variable

    • Mac: export APPLITOOLS_API_KEY='YOUR_API_KEY'

    • Windows: set APPLITOOLS_API_KEY='YOUR_API_KEY'

    TIP

    1. You may skip this step if you want to hard code the API KEY inside the tutorial project's code.
    2. It's better to store APPLITOOLS_API_KEY in the system variables (in Windows) or in the ~/.bash_profile (in Mac) so that it is accessible from all Terminal shells
  3. Install git from https://git-scm.com​

    TIP

    Installing git is optional. You need this mainly to clone the demo project from the Github repository. Instead of installing git, you can simply download the Zip file from the repo. Further, If you are using Mac OSX, you already have git.

  4. Ruby Installed on your machine

5.1 🚀 - Run the existing demo app
  1. Get the code:

    • Option 1: git clone https://github.com/applitools/tutorial-ruby-screenshots
    • Option 2: Download it as a Zip file and unzip it.
  2. Navigate to the tutorial-ruby-screenshots folder

  3. Run command gem install bundler && bundle install to install the necessary ruby gems and dependencies.

  4. Run the test: bundle exec ruby simple_test_script.rb

5.2 🤓 - Add Applitools to an existing project

Install the SDK

gem install eyes_images
1

Example Test

require 'eyes_images'

runner = Applitools::ClassicRunner.new
eyes = Applitools::Images::Eyes.new(runner: runner)
batch = Applitools::BatchInfo.new('Applitools Screenshot example')

eyes.batch = batch

Applitools::EyesLogger.log_handler = Logger.new(STDOUT).tap do |l|
  l.level = Logger::INFO
end

begin
  file_path = './PNG_IMG1.png'
  image_bytes = File.read(file_path)
  image = Applitools::Screenshot.from_datastream(image_bytes)

  # Classic API
  eyes.open(app_name: 'Screenshot example app', test_name: 'Screenshot example classic api')
  eyes.check_image(tag: 'By file path', image_path: file_path)
  eyes.check_image(tag: 'By image bytes', image_bytes: image_bytes)
  eyes.check_image(tag: 'By Applitools Screenshot', image: image)
  eyes.check_region(tag: 'Check region example', image: image, region: Applitools::Region.new(200, 200, 100, 100))
  eyes.close

  # Fluent API
  eyes.open(app_name: 'Screenshot example app', test_name: 'Screenshot example fluent api')
  eyes.check('By file path', Applitools::Images::Target.path(file_path))
  eyes.check('By image bytes', Applitools::Images::Target.blob(image_bytes))
  eyes.check('By Applitools Screenshot', Applitools::Images::Target.screenshot(image))
  eyes.check(
    'Check region example',
    Applitools::Images::Target.screenshot(image).region(Applitools::Region.new(200, 200, 100, 100))
  )
  eyes.close
rescue => e
  puts e.message
  eyes.abort
ensure
  puts runner.get_all_test_results
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
⚙️ 6. Troubleshooting Common Issues
  1. Forgetting to set your API key (or getting 401 exception):

  2. Not properly loading the API key from the environment variable into your IDE (like Eclipse):

    • After setting the APPLITOOLS_API_KEY in the environment variable to hold your Applitools API key, open the IDE from the command line terminal (and not from the IDE directly). On Mac, it’d look like this: Open a Terminal and then type: open ~/Applications/Eclipse.app. This will load Eclipse with all the environment variables.
  3. Trying to run the test but nothing happens:

    • Check if the APPLITOOLS_API_KEY is null
  4. Debug logs:

    • See this article to enable debug logs to help file support ticket

Resources




Terms & Conditions Privacy Policy GDPR© 2019 Applitools. All rights reserved.

Last Updated: 1/17/2020, 2:45:59 PM