Screenshots Ruby Tutorial

Getting Started with Applitools

Want to learn more about the Applitools platform and how it works? First get started with one of the following:

Running Tests with Applitools

Prerequisites
  1. A free Applitools account and Applitools API KEY

Tip: Unsure how to set up your API key?

Learn how to get started at Setting Up

  1. Ruby https://www.ruby-lang.org/en/documentation/installation/

  2. Git https://git-scm.com​

Note: Installing `git` is optional

Installing git is used to clone the demo project from the Github repository. Instead of installing git, you can simply download the Zip file from the repository. Further, if you are Mac, you already have git.

Running the Example Project

  1. Clone or download the repository and navigate to that folder
git clone https://github.com/applitools/tutorial-ruby-screenshots.git
cd tutorial-ruby-screenshots
1
2

Note: you can alternatively download the project as a Zip file and extract it

  1. Install the dependencies
gem install bundler && bundle install
1
  1. Run the example test
APPLITOOLS_API_KEY="[Your API Key]" bundle exec ruby simple_test_script.rb
1

Adding Applitools Eyes to an Existing Project

Install Applitools Eyes dependencies:

gem install eyes_images
1

Sample test

require 'eyes_images'

runner = Applitools::ClassicRunner.new
eyes = Applitools::Images::Eyes.new(runner: runner)
batch = Applitools::BatchInfo.new('Demo Batch - Images - Ruby')

eyes.batch = batch

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

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

  eyes.open(app_name: 'Demo App - Images Ruby', test_name: 'Smoke Test - Images Ruby')
  
  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.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

Resources




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

Last Updated: 6/24/2021, 10:09:59 AM