watir-get-image-content 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWJmNzYwYzMxNWVmYmQyNmI3NTU4MmY0MmQwMjNlYTc0NTk4ZGI3ZQ==
5
+ data.tar.gz: !binary |-
6
+ MTcxM2Y0ZThhMzNlNjdiYTA5NTI5NTQxNTIwZTczZjYxZmRiMzU4MA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDU3NzBlNGIxM2JiZDQyMWQ4OThjNGVkYWZlOTY3YzRkNjhmZjEzMGEzZjdm
10
+ ZWFjNmQyNDM1NzFmNjJiZTUxOWY5ZjdiMmFjMzQyNWVmNDcyODFiNTZlNGU1
11
+ YjYxNDY3OTk3MGU1ZGFjZGU2ZDQ4YjlkMDAwMTcyMTIwNDM0OTI=
12
+ data.tar.gz: !binary |-
13
+ NTBiNGVkZTVkMWFiNmVjM2E0NmIzYzE2MzJlZWQ1M2ZkYmFkMzc5YTczMWFj
14
+ MTAxNjdkMWMxNjAxMDVlYzIxYjg5ZjE2N2Y2ZTM3OTYwN2VmOWM5MDQ4NTU4
15
+ NGE2MDQ5ODkxNGZlZjljZWMxNTQ4MWY1Njk2OWU1YzU1Y2FhZGU=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ before_install:
5
+ - "export DISPLAY=:99.0"
6
+ - "sh -e /etc/init.d/xvfb start"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in watir-get-image-content.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 orangeudav
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ Return content of image as base64-encoded png
2
+
3
+ [![Build Status](https://travis-ci.org/orangeudav/watir-get-image-content.png?branch=master)](https://travis-ci.org/orangeudav/watir-get-image-content)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'watir-get-image-content'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install watir-get-image-content
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'watir-webdriver'
23
+ require 'watir-get-image-content'
24
+ browser = Watir::Browser.new
25
+ browser.goto 'http://for_example.com/page_with_images'
26
+
27
+ browser.image(:index, 1).to_png_base64
28
+ browser.image(:alt, 'Alt text').to_png_base64
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.rspec_opts = %w(--color)
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task default: :spec
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ module Watir
3
+ class Image
4
+
5
+ def to_png_base64
6
+ assert_exists
7
+ js = %q{var canvas = document.createElement("canvas");
8
+ canvas.width = arguments[0].width;
9
+ canvas.height = arguments[0].height;
10
+ var ctx = canvas.getContext("2d");
11
+ ctx.drawImage(arguments[0], 0, 0);
12
+ var dataURL = canvas.toDataURL("image/png");
13
+ return dataURL.replace(/^data:image\/(png|jpg|gif);base64,/, "");}
14
+ driver.execute_script js, @element
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+ require "watir-webdriver"
2
+ require "watir-get-image-content/image"
Binary file
Binary file
Binary file
data/spec/spec.html ADDED
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ </head>
4
+ <body>
5
+ <img src="./images/gif.gif" alt="gif"/>
6
+ <img src="./images/jpg.jpg" alt="jpg"/>
7
+ <img src="./images/png.png" alt="png"/>
8
+ </body>
9
+ </html>
@@ -0,0 +1,35 @@
1
+ require 'RMagick'
2
+ require 'rspec/expectations'
3
+ require 'watir-get-image-content'
4
+
5
+ RSpec.configure do |spec|
6
+ spec.before(:all) do
7
+ @browser = Watir::Browser.new
8
+ @browser.goto "file://#{Dir.pwd}/spec/spec.html"
9
+ end
10
+
11
+ spec.after(:all) do
12
+ @browser.quit
13
+ end
14
+
15
+ spec.after(:each) do
16
+ @browser.refresh
17
+ end
18
+ end
19
+
20
+ RSpec::Matchers.define :be_similar_to_file do |dst_file|
21
+ match do |src_base64|
22
+ src_img = Magick::Image.read_inline(src_base64)
23
+ dst_img = Magick::Image.read(dst_file)
24
+ @diff_img, @diff_metric = src_img[0].compare_channel(dst_img[0], Magick::MeanSquaredErrorMetric)
25
+ @diff_metric <= @mse.to_f
26
+ end
27
+
28
+ chain :with_mse_less_then do |mse|
29
+ @mse = mse
30
+ end
31
+
32
+ failure_message_for_should do |actual|
33
+ "expected that mse #{@diff_metric} would be less or equal #{@mse.to_f}"
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+
4
+ describe "watir-get-image-content" do
5
+ describe "#to_png_base64" do
6
+ it "return png image similar to the original png" do
7
+ src_file = "#{Dir.pwd}/spec/images/png.png".sub("file://", '')
8
+ enc_base64 = @browser.image(:alt, 'png').to_png_base64
9
+ expect(enc_base64).to be_similar_to_file(src_file)
10
+ end
11
+
12
+ it "return png image similar to the original gif" do
13
+ src_file = "#{Dir.pwd}/spec/images/gif.gif".sub("file://", '')
14
+ enc_base64 = @browser.image(:alt, 'gif').to_png_base64
15
+ expect(enc_base64).to be_similar_to_file(src_file)
16
+ end
17
+
18
+ it "return png image similar to the original jpg with mse <= 0.0000001" do
19
+ src_file = "#{Dir.pwd}/spec/images/jpg.jpg".sub("file://", '')
20
+ enc_base64 = @browser.image(:alt, 'jpg').to_png_base64
21
+ expect(enc_base64).to be_similar_to_file(src_file).with_mse_less_then(0.0000001)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "watir-get-image-content"
7
+ spec.version = "0.0.2"
8
+ spec.authors = ["orangeudav"]
9
+ spec.email = ["orangeudav@gmail.com"]
10
+ spec.description = %q{Get Watir::Image's content copy without external download}
11
+ spec.summary = %q{Get Watir::Image's content copy without external download}
12
+ spec.homepage = "https://github.com/orangeudav/watir-get-image-content"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "watir-webdriver"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rmagick", '2.13.2'
26
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watir-get-image-content
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - orangeudav
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: watir-webdriver
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rmagick
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.13.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.13.2
83
+ description: Get Watir::Image's content copy without external download
84
+ email:
85
+ - orangeudav@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/watir-get-image-content.rb
97
+ - lib/watir-get-image-content/image.rb
98
+ - spec/images/gif.gif
99
+ - spec/images/jpg.jpg
100
+ - spec/images/png.png
101
+ - spec/spec.html
102
+ - spec/spec_helper.rb
103
+ - spec/watir-get-image-content_spec.rb
104
+ - watir-get-image-content.gemspec
105
+ homepage: https://github.com/orangeudav/watir-get-image-content
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.1.11
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Get Watir::Image's content copy without external download
129
+ test_files:
130
+ - spec/images/gif.gif
131
+ - spec/images/jpg.jpg
132
+ - spec/images/png.png
133
+ - spec/spec.html
134
+ - spec/spec_helper.rb
135
+ - spec/watir-get-image-content_spec.rb