Skip to content

Commit 14b6a04

Browse files
author
Nikita Andreyev
committed
Initial commit
0 parents  commit 14b6a04

5 files changed

Lines changed: 112 additions & 0 deletions

File tree

.gitignore

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
*.gem
2+
*.rbc
3+
/.config
4+
/coverage/
5+
/InstalledFiles
6+
/pkg/
7+
/spec/reports/
8+
/spec/examples.txt
9+
/test/tmp/
10+
/test/version_tmp/
11+
/tmp/
12+
13+
# Used by dotenv library to load environment variables.
14+
# .env
15+
16+
## Specific to RubyMotion:
17+
.dat*
18+
.repl_history
19+
build/
20+
*.bridgesupport
21+
build-iPhoneOS/
22+
build-iPhoneSimulator/
23+
24+
## Specific to RubyMotion (use of CocoaPods):
25+
#
26+
# We recommend against adding the Pods directory to your .gitignore. However
27+
# you should judge for yourself, the pros and cons are mentioned at:
28+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29+
#
30+
# vendor/Pods/
31+
32+
## Documentation cache and generated files:
33+
/.yardoc/
34+
/_yardoc/
35+
/doc/
36+
/rdoc/
37+
38+
## Environment normalization:
39+
/.bundle/
40+
/vendor/bundle
41+
/lib/bundler/man/
42+
43+
# for a library or gem, you might want to ignore these files since the code is
44+
# intended to run in multiple environments; otherwise, check them in:
45+
# Gemfile.lock
46+
# .ruby-version
47+
# .ruby-gemset
48+
49+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50+
.rvmrc

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'eyes_images'

PNG_IMG1.png

375 KB
Loading

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Pre-requisites:
2+
3+
1. Ruby is installed on your machine.
4+
* [See instructions here](https://www.ruby-lang.org/en/documentation/installation/)
5+
6+
# Steps to run this example
7+
8+
1. Git clone this repo
9+
* `git clone git@github.com:applitools/tutorial-ruby-screenshots.git`
10+
2. Open the folder `tutorial-ruby-screenshots`
11+
3. Run command `gem install bundler && bundle install`. This will install necessary ruby gems and dependencies
12+
4. Obtain your API_KEY:
13+
* Login to Applitools > Click on the Person icon > My API Key
14+
5. Export the API_KEY:
15+
* For Mac, Linux: `export APPLITOOLS_API_KEY=MY_API_KEY`
16+
* For Windows: `SET APPLITOOLS_API_KEY=MY_API_KEY`
17+
6. Run the test: `bundle exec ruby simple_test_script.rb`

simple_test_script.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'eyes_images'
2+
3+
runner = Applitools::ClassicRunner.new
4+
eyes = Applitools::Images::Eyes.new(runner: runner)
5+
batch = Applitools::BatchInfo.new('Applitools Screenshot example')
6+
7+
eyes.batch = batch
8+
9+
Applitools::EyesLogger.log_handler = Logger.new(STDOUT).tap do |l|
10+
l.level = Logger::INFO
11+
end
12+
13+
begin
14+
file_path = './PNG_IMG1.png'
15+
image_bytes = File.read(file_path)
16+
image = Applitools::Screenshot.from_datastream(image_bytes)
17+
18+
# Classic API
19+
eyes.open(app_name: 'Screenshot example app', test_name: 'Screenshot example classic api')
20+
eyes.check_image(tag: 'By file path', image_path: file_path)
21+
eyes.check_image(tag: 'By image bytes', image_bytes: image_bytes)
22+
eyes.check_image(tag: 'By Applitools Screenshot', image: image)
23+
eyes.check_region(tag: 'Check region example', image: image, region: Applitools::Region.new(200, 200, 100, 100))
24+
eyes.close
25+
26+
# Fluent API
27+
eyes.open(app_name: 'Screenshot example app', test_name: 'Screenshot example fluent api')
28+
eyes.check('By file path', Applitools::Images::Target.path(file_path))
29+
eyes.check('By image bytes', Applitools::Images::Target.blob(image_bytes))
30+
eyes.check('By Applitools Screenshot', Applitools::Images::Target.screenshot(image))
31+
eyes.check(
32+
'Check region example',
33+
Applitools::Images::Target.screenshot(image).region(Applitools::Region.new(200, 200, 100, 100))
34+
)
35+
eyes.close
36+
rescue => e
37+
eyes.abort
38+
ensure
39+
puts runner.get_all_test_results
40+
end
41+
42+

0 commit comments

Comments
 (0)