eyes_selenium_ruby 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +13 -0
  5. data/README.md +66 -0
  6. data/Rakefile +1 -0
  7. data/eyes_selenium_ruby.gemspec +30 -0
  8. data/lib/eyes_selenium_ruby/capybara.rb +21 -0
  9. data/lib/eyes_selenium_ruby/eyes/agent_connecter.rb +39 -0
  10. data/lib/eyes_selenium_ruby/eyes/batch_info.rb +14 -0
  11. data/lib/eyes_selenium_ruby/eyes/driver.rb +145 -0
  12. data/lib/eyes_selenium_ruby/eyes/element.rb +78 -0
  13. data/lib/eyes_selenium_ruby/eyes/environment.rb +13 -0
  14. data/lib/eyes_selenium_ruby/eyes/eyes.rb +179 -0
  15. data/lib/eyes_selenium_ruby/eyes/eyes_keyboard.rb +25 -0
  16. data/lib/eyes_selenium_ruby/eyes/eyes_mouse.rb +60 -0
  17. data/lib/eyes_selenium_ruby/eyes/failure_reports.rb +4 -0
  18. data/lib/eyes_selenium_ruby/eyes/match_level.rb +7 -0
  19. data/lib/eyes_selenium_ruby/eyes/match_window_data.rb +18 -0
  20. data/lib/eyes_selenium_ruby/eyes/match_window_task.rb +71 -0
  21. data/lib/eyes_selenium_ruby/eyes/mouse_trigger.rb +19 -0
  22. data/lib/eyes_selenium_ruby/eyes/region.rb +22 -0
  23. data/lib/eyes_selenium_ruby/eyes/screenshot_taker.rb +18 -0
  24. data/lib/eyes_selenium_ruby/eyes/session.rb +14 -0
  25. data/lib/eyes_selenium_ruby/eyes/start_info.rb +33 -0
  26. data/lib/eyes_selenium_ruby/eyes/target_app.rb +17 -0
  27. data/lib/eyes_selenium_ruby/eyes/test_results.rb +21 -0
  28. data/lib/eyes_selenium_ruby/eyes/text_trigger.rb +15 -0
  29. data/lib/eyes_selenium_ruby/eyes/viewport_size.rb +109 -0
  30. data/lib/eyes_selenium_ruby/eyes_logger.rb +18 -0
  31. data/lib/eyes_selenium_ruby/utils/image_delta_compressor.rb +147 -0
  32. data/lib/eyes_selenium_ruby/utils.rb +5 -0
  33. data/lib/eyes_selenium_ruby/version.rb +3 -0
  34. data/lib/eyes_selenium_ruby.rb +41 -0
  35. data/spec/capybara_spec.rb +33 -0
  36. data/spec/driver_spec.rb +10 -0
  37. data/spec/eyes_spec.rb +156 -0
  38. data/spec/spec_helper.rb +29 -0
  39. data/spec/test_app.rb +11 -0
  40. data/test_script.rb +22 -0
  41. metadata +225 -0
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'capybara/rspec'
3
+ require 'eyes_selenium_ruby/capybara'
4
+ require 'test_app'
5
+
6
+ Capybara.app = TestApp
7
+
8
+ describe Applitools::Eyes do
9
+ init_eyes
10
+ describe 'capybara' do
11
+ before do
12
+ eyes.agent_connector.stub(:stop_session).and_return(double("TestResults", mismatches: 0, missing: 0))
13
+ @navigation = double("navigation")
14
+ @navigation.stub(:to)
15
+ end
16
+ it 'should invoke eyes driver when calling capybara visit inside of eyes.open' do
17
+ Capybara.current_driver.should == :rack_test
18
+
19
+ eyes.driver.should_receive(:navigate).and_return(@navigation)
20
+ eyes.test(app_name: 'test', test_name: 'test') do |eyes|
21
+ Capybara.current_driver.should == :selenium
22
+ eyes.driver.should == Capybara.current_session.driver.instance_variable_get(:@browser)
23
+ Capybara.current_session.visit '/'
24
+ eyes.check_window('test')
25
+ end
26
+ Capybara.current_driver.should == :rack_test
27
+ end
28
+ it 'should not invoke eyes driver when calling capybara visit outside of eyes.open' do
29
+ eyes.driver.should_not_receive(:navigate)
30
+ Capybara.current_session.visit '/'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Applitools::Driver do
4
+ describe "#driver" do
5
+ let(:driver) { Applitools::Driver.new }
6
+
7
+ it "has a selenium driver" do
8
+ end
9
+ end
10
+ end
data/spec/eyes_spec.rb ADDED
@@ -0,0 +1,156 @@
1
+ require 'spec_helper'
2
+
3
+ describe Applitools::Eyes do
4
+ init_eyes
5
+
6
+ before do
7
+ eyes.open(app_name: 'test_app', test_name: 'test_app_test')
8
+ fake_session = Applitools::Session.new(1,"http://fake_url.com", false)
9
+ eyes.session = fake_session
10
+ eyes.agent_connector.stub(:stop_session).and_return(double("TestResults", mismatches: 0, missing: 0))
11
+ end
12
+
13
+ describe "#new" do
14
+ context "doesn't have an apikey" do
15
+ before do
16
+ Applitools::Eyes.config[:apikey] = nil
17
+ end
18
+ it {expect {Applitools::Eyes.new }.to raise_error }
19
+ after do
20
+ Applitools::Eyes.config[:apikey] = 'YOUR_API_KEY_HERE'
21
+ end
22
+ end
23
+ context "has an apikey url" do
24
+ it {expect {Applitools::Eyes.new }.to_not raise_error }
25
+ end
26
+ end
27
+
28
+ describe ".open" do
29
+ context "already open" do
30
+ it "aborts session" do
31
+ eyes.should_receive(:abort_if_not_closed)
32
+ expect {eyes.open}.to raise_error
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ describe ".abort_if_not_closed" do
39
+ it "closes eyes" do
40
+ expect(eyes).to be_open
41
+ eyes.send(:abort_if_not_closed)
42
+ expect(eyes).to_not be_open
43
+ end
44
+
45
+ it "clears session" do
46
+ eyes.send(:abort_if_not_closed)
47
+ expect(eyes.session).to be_nil
48
+ end
49
+
50
+ it "stops session" do
51
+ expect(eyes.agent_connector).to receive(:stop_session)
52
+ eyes.send(:abort_if_not_closed)
53
+ end
54
+ end
55
+
56
+ describe ".close" do
57
+ it "stops the session" do
58
+ eyes.agent_connector.stub(:stop_session).and_return(double("TestResults", mismatches: 0, missing: 0))
59
+ expect(eyes.agent_connector).to receive(:stop_session)
60
+ expect(eyes.close)
61
+ end
62
+
63
+ context "new_session" do
64
+ before { eyes.session.stub(:new_session?).and_return(true) }
65
+ it "raises NewTestError" do
66
+ eyes.session_start_info = double().as_null_object
67
+ expect { eyes.close }.to raise_error(Applitools::NewTestError)
68
+ end
69
+ end
70
+
71
+ context "not new_session" do
72
+ before do
73
+ eyes.stub(:session_start_info).and_return double().as_null_object
74
+ eyes.session.new_session = false
75
+ end
76
+
77
+ it "raises TestFailedError if results have mismatches" do
78
+ eyes.agent_connector.stub(:stop_session).and_return(double("TestResults", mismatches: 2))
79
+ expect { eyes.close }.to raise_error(Applitools::TestFailedError)
80
+ end
81
+
82
+ it "raises TestFailedError if results have missing" do
83
+ eyes.agent_connector.stub(:stop_session).and_return(double("TestResults", mismatches: 0, missing: 2))
84
+ expect { eyes.close }.to raise_error(Applitools::TestFailedError)
85
+ end
86
+
87
+ it "doesn't raise if old session without mismatches" do
88
+ eyes.stub_chain(:agent_connector, :stop_session).and_return(double("TestResults", mismatches: 0, missing: 0))
89
+ expect(eyes.close).to_not raise_error
90
+ end
91
+ end
92
+ end
93
+
94
+ describe ".check_window" do
95
+ it "raises EyesError if eyes aren't open"
96
+ context "no session" do
97
+ it "creates new session if no session exists"
98
+ it "creates new MatchWindowTask"
99
+ end
100
+
101
+ context "results are as expected" do
102
+ it "doesn't raise"
103
+ end
104
+ context "results are not as expected" do
105
+ context "new session" do
106
+ specify "next check_window will run once on time out"
107
+ end
108
+ context "not new session" do
109
+ context "immediate failreports" do
110
+ it "raises TestFailedError"
111
+ end
112
+
113
+ context "not immediate failreports" do
114
+ it "doesn't raise"
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ describe ".test" do
121
+ it "opens and closes the eyes around the block execution" do
122
+ eyes.should_receive(:open).ordered
123
+ eyes.should_receive(:close).ordered
124
+ eyes.test { "foo" }
125
+ end
126
+
127
+ it "always closes eyes even if there were exceptions" do
128
+ eyes.stub(:open)
129
+ eyes.should_receive(:abort_if_not_closed)
130
+ eyes.test { raise Applitools::EyesError }
131
+ end
132
+
133
+ context "testing .test" do
134
+ let!(:eyes) do
135
+ Applitools::Eyes.new
136
+ end
137
+ it "catches triggers" do
138
+ #eyes.send(:abort_if_not_closed)
139
+ eyes.test(app_name: 'my app1', test_name: 'my test') do |eyes, driver|
140
+ driver.get "http://www.applitools.com"
141
+ eyes.check_window("initial")
142
+ driver.find_element(:css, "li.pricing a").click
143
+ # return false unless user_inputs.map(&:to_hash) == [{"$type"=>"Applitools.Models.MouseTrigger, Core", :mouseAction=>1, :control=>{"$type"=>"Applitools.Utils.Geometry.MutableRegion, Core", :left=>555, :top=>0, :height=>69, :width=>50}, :location=>{:latitude=>25, :longitude=>34, :altitude=>nil}}]
144
+ driver.check_window("pricing page")
145
+ el = driver.find_elements(:css, ".footer-row a").first
146
+ driver.action.double_click(el).perform
147
+ # return false unless user_inputs.map(&:to_hash) == [{"$type"=>"Applitools.Models.MouseTrigger, Core", :mouseAction=>3, :control=>{"$type"=>"Applitools.Utils.Geometry.MutableRegion, Core", :left=>0, :top=>0, :height=>115, :width=>376}, :location=>{:x=>115, :y=>376}}]
148
+ eyes.check_window("in forms")
149
+ other_el = driver.find_elements(:css, ".s2member-pro-paypal-registration-email").first
150
+ driver.action.move_to(other_el).click(other_el).send_keys("text1",:space,"text2").perform
151
+ # return false unless user_inputs.map(&:to_hash) == [{"$type"=>"Applitools.Models.MouseTrigger, Core", :mouseAction=>4, :control=>{"$type"=>"Applitools.Utils.Geometry.MutableRegion, Core", :left=>0, :top=>0, :height=>230, :width=>331}, :location=>{:x=>230, :y=>331}}, {"$type"=>"Applitools.Models.MouseTrigger, Core", :mouseAction=>1, :control=>{"$type"=>"Applitools.Utils.Geometry.MutableRegion, Core", :left=>0, :top=>0, :height=>230, :width=>331}, :location=>{:x=>230, :y=>331}}, {"$type"=>"Applitools.Models.TextTrigger, Core", :text=>"text1", :control=>{"$type"=>"Applitools.Utils.Geometry.MutableRegion, Core", :left=>230, :top=>331, :height=>367, :width=>35}}, {"$type"=>"Applitools.Models.TextTrigger, Core", :text=>"", :control=>{"$type"=>"Applitools.Utils.Geometry.MutableRegion, Core", :left=>230, :top=>331, :height=>367, :width=>35}}, {"$type"=>"Applitools.Models.TextTrigger, Core", :text=>"text2", :control=>{"$type"=>"Applitools.Utils.Geometry.MutableRegion, Core", :left=>230, :top=>331, :height=>367, :width=>35}}]
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,29 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'eyes_selenium_ruby'
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
19
+
20
+
21
+ def init_eyes
22
+ before(:all) do
23
+ Applitools::Eyes.config[:apikey] = 'YOUR_API_KEY'
24
+ Applitools::Eyes.config[:server_url] = 'http://eyesbeta.cloudapp.net:8080'
25
+ end
26
+ let!(:eyes) do
27
+ Applitools::Eyes.new
28
+ end
29
+ end
data/spec/test_app.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'sinatra/base'
2
+ require 'rack'
3
+
4
+ class TestApp < Sinatra::Base
5
+ set :root, File.dirname(__FILE__)
6
+ set :static, true
7
+
8
+ get '/' do
9
+ 'Hello world!'
10
+ end
11
+ end
data/test_script.rb ADDED
@@ -0,0 +1,22 @@
1
+ ## Before running this, please install ruby(installtion changes depending on machine)
2
+ ## Then install rake via `gem install rake` (all ruby developers use this gem)
3
+ ## run `./rake install` in applitools root directory (here), this should install the gem (after we release the gem, users will run `gem install eyes` instead
4
+
5
+ require 'eyes_selenium_ruby'
6
+
7
+ Applitools::Eyes.config[:apikey] = 'YOUR_API_KEY_HERE'
8
+
9
+ eyes = Applitools::Eyes.new
10
+
11
+ eyes.test(app_name: 'my app', test_name: 'my test') do |eyes, driver|
12
+ driver.get "http://www.applitools.com"
13
+ eyes.check_window("initial")
14
+ driver.find_element(:css, "li.pricing a").click
15
+ eyes.check_window("pricing page")
16
+ el = driver.find_elements(:css, ".footer-row a").first
17
+ driver.action.double_click(el).perform
18
+ eyes.check_window("in forms")
19
+ other_el = driver.find_elements(:css, ".s2member-pro-paypal-registration-email").first
20
+ driver.action.move_to(other_el).click(other_el).send_keys("applitools").perform
21
+ eyes.check_window("end")
22
+ end
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eyes_selenium_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Applitools team
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: selenium-webdriver
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: oily_png
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 2.2.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 2.2.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: capybara
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.1.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 2.1.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: sinatra
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Applitools Ruby SDK
143
+ email:
144
+ - team@applitools.com
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - .gitignore
150
+ - .rspec
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - eyes_selenium_ruby.gemspec
156
+ - lib/eyes_selenium_ruby.rb
157
+ - lib/eyes_selenium_ruby/capybara.rb
158
+ - lib/eyes_selenium_ruby/eyes/agent_connecter.rb
159
+ - lib/eyes_selenium_ruby/eyes/batch_info.rb
160
+ - lib/eyes_selenium_ruby/eyes/driver.rb
161
+ - lib/eyes_selenium_ruby/eyes/element.rb
162
+ - lib/eyes_selenium_ruby/eyes/environment.rb
163
+ - lib/eyes_selenium_ruby/eyes/eyes.rb
164
+ - lib/eyes_selenium_ruby/eyes/eyes_keyboard.rb
165
+ - lib/eyes_selenium_ruby/eyes/eyes_mouse.rb
166
+ - lib/eyes_selenium_ruby/eyes/failure_reports.rb
167
+ - lib/eyes_selenium_ruby/eyes/match_level.rb
168
+ - lib/eyes_selenium_ruby/eyes/match_window_data.rb
169
+ - lib/eyes_selenium_ruby/eyes/match_window_task.rb
170
+ - lib/eyes_selenium_ruby/eyes/mouse_trigger.rb
171
+ - lib/eyes_selenium_ruby/eyes/region.rb
172
+ - lib/eyes_selenium_ruby/eyes/screenshot_taker.rb
173
+ - lib/eyes_selenium_ruby/eyes/session.rb
174
+ - lib/eyes_selenium_ruby/eyes/start_info.rb
175
+ - lib/eyes_selenium_ruby/eyes/target_app.rb
176
+ - lib/eyes_selenium_ruby/eyes/test_results.rb
177
+ - lib/eyes_selenium_ruby/eyes/text_trigger.rb
178
+ - lib/eyes_selenium_ruby/eyes/viewport_size.rb
179
+ - lib/eyes_selenium_ruby/eyes_logger.rb
180
+ - lib/eyes_selenium_ruby/utils.rb
181
+ - lib/eyes_selenium_ruby/utils/image_delta_compressor.rb
182
+ - lib/eyes_selenium_ruby/version.rb
183
+ - spec/capybara_spec.rb
184
+ - spec/driver_spec.rb
185
+ - spec/eyes_spec.rb
186
+ - spec/spec_helper.rb
187
+ - spec/test_app.rb
188
+ - test_script.rb
189
+ homepage: http://www.applitools.com
190
+ licenses:
191
+ - Apache License, Version 2.0
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ segments:
203
+ - 0
204
+ hash: -3642816426594908165
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ! '>='
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ segments:
212
+ - 0
213
+ hash: -3642816426594908165
214
+ requirements: []
215
+ rubyforge_project:
216
+ rubygems_version: 1.8.25
217
+ signing_key:
218
+ specification_version: 3
219
+ summary: Applitools Ruby SDK
220
+ test_files:
221
+ - spec/capybara_spec.rb
222
+ - spec/driver_spec.rb
223
+ - spec/eyes_spec.rb
224
+ - spec/spec_helper.rb
225
+ - spec/test_app.rb