domreactor-redglass 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,6 +13,7 @@ You will need a DomReactor account and an API token to use DomReactor's automate
13
13
  browsers = [:firefox, :chrome]
14
14
  archive_location = '/Users/you/Desktop/red_glass_snapshots'
15
15
  test_id = 1
16
+ page_url = 'http://google.com'
16
17
  opts = {
17
18
  baseline_browser: {name: 'firefox', version: '20.0', platform: 'darwin'},
18
19
  threshold: 0.02
@@ -23,16 +24,16 @@ browsers.each do |browser|
23
24
  listener = RedGlassListener.new
24
25
  driver = Selenium::WebDriver.for browser, :listener => listener
25
26
  red_glass = RedGlass.new driver, {listener: listener, archive_location: archive_location, test_id: test_id}
26
- driver.navigate.to 'http://google.com'
27
+ driver.navigate.to page_url
27
28
  red_glass.take_snapshot
28
29
  driver.quit
29
30
  end
30
31
 
31
32
  # Send the page archives to DomReactor.
32
33
  DomReactorRedGlass.auth_token = '12345'
33
- DomReactorRedGlass.create_chain_reaction("#{archive_location}/#{test_id}", opts)
34
+ DomReactorRedGlass.create_chain_reaction(page_url, "#{archive_location}/#{test_id}", opts)
34
35
  ```
35
36
 
36
37
  # License
37
38
 
38
- The MIT License - Copyright (c) 2013 Frank O'Hara
39
+ The MIT License - Copyright (c) 2013 Binary Mechanics
@@ -24,6 +24,6 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.add_development_dependency "bundler", "~> 1.3"
26
26
  s.add_development_dependency "rake"
27
- s.add_development_dependency "rspec", "~> 2.13.0"
27
+ s.add_development_dependency "rspec", "~> 2.14.0"
28
28
  s.add_development_dependency 'selenium-webdriver'
29
29
  end
@@ -31,41 +31,32 @@ module DomReactorRedGlass
31
31
  @info ||= create_chain_reaction(@opts)
32
32
  end
33
33
 
34
+
34
35
  def post_archives(archive_location)
35
- web_browser_ids = []
36
- #TODO: Cache the web prowser for each archive location.
37
- Dir.foreach(archive_location) do |file|
38
- next if file == '.' or file == '..'
39
- path = "#{archive_location}/#{file}"
40
- if is_valid_page_archive? path
41
- web_browser_ids << get_web_browser_info(parse_json_file("#{path}/metadata.json")[:browser])[:id]
42
- end
43
- end
44
- update_chain_reaction(web_browser_ids: web_browser_ids)
45
- dom_gun_reaction = create_dom_gun_reaction
46
36
  Dir.foreach(archive_location) do |file|
47
37
  next if file == '.' or file == '..'
48
38
  path = "#{archive_location}/#{file}"
49
39
  if is_valid_page_archive? path
50
40
  payload = create_payload(path)
51
- RestClient.put("#{chain_reaction_url}/dom_gun_reactions/#{dom_gun_reaction[:id]}", payload, content_type: 'application/json')
41
+ create_dom_gun_reaction(payload)
52
42
  end
53
43
  end
54
- start_reaction(dom_gun_reaction[:id])
44
+ start_reaction
55
45
  end
56
46
 
57
- def start_reaction(id)
47
+ private
48
+
49
+ def start_reaction
58
50
  params = {
59
51
  auth_token: auth_token,
60
52
  }
61
- RestClient.post("#{chain_reaction_url}/dom_gun_reactions/#{id}/start", params, content_type: 'application/json')
53
+ RestClient.post("#{chain_reaction_url}/start", params, content_type: 'application/json')
62
54
  end
63
55
 
64
- def baseline_browser
65
- get_web_browser_info(@opts[:baseline_browser])
66
- end
67
56
 
68
- private
57
+ def create_dom_gun_reaction(payload)
58
+ RestClient.post("#{chain_reaction_url}/dom_gun_reactions", payload, content_type: 'application/json')
59
+ end
69
60
 
70
61
  def get_web_browser_info(browser_info={})
71
62
  parameters = {auth_token: auth_token,content_type: 'application/json', accept: :json}.merge(browser_info)
@@ -74,8 +65,8 @@ module DomReactorRedGlass
74
65
  JSON.parse(response, symbolize_names: true)[:web_browsers].first
75
66
  end
76
67
 
77
- def update_chain_reaction(params)
78
- RestClient.put(chain_reaction_url, params.merge(auth_token: auth_token), content_type: 'application/json')
68
+ def baseline_browser
69
+ get_web_browser_info(@opts[:baseline_browser])
79
70
  end
80
71
 
81
72
  def create_chain_reaction(opts)
@@ -94,22 +85,13 @@ module DomReactorRedGlass
94
85
  JSON.parse(response, symbolize_names: true)[:chain_reaction]
95
86
  end
96
87
 
97
- def create_dom_gun_reaction
98
- payload = {
99
- chain_reaction_id: id,
100
- auth_token: auth_token,
101
- page_url: page_url
102
- }
103
- dom_gun = RestClient.post("#{chain_reaction_url}/dom_gun_reactions", payload, content_type: 'application/json')
104
- JSON.parse(dom_gun, symbolize_names: true)
105
- end
106
-
107
88
  def create_payload(path)
108
89
  meta_data = parse_json_file("#{path}/metadata.json")
109
90
  {
110
91
  auth_token: auth_token,
111
92
  meta_data: meta_data,
112
93
  web_browser_id: get_web_browser_info(meta_data[:browser])[:id],
94
+ page_url: meta_data[:page_url],
113
95
  dom_elements: File.open("#{path}/dom.json", 'rb') {|f| f.read},
114
96
  page_source: File.open("#{path}/source.html") {|f| f.read},
115
97
  file: File.open("#{path}/screenshot.png")
@@ -1,3 +1,3 @@
1
1
  module DomReactorRedGlass
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -24,15 +24,16 @@ describe DomReactorRedGlass::ChainReaction do
24
24
 
25
25
  describe '#post_archives' do
26
26
  before do
27
- chain_reaction.stub(:create_dom_gun_reaction) { {id: 81, stuff: true} }
28
- chain_reaction.stub(:get_web_browser_info).exactly(4).times.
29
- with({:name=>"firefox", :version=>"20.0", :platform=>"darwin"}) { {id: 22, browser: 'firefox'} }
30
- RestClient.should_receive(:put).exactly(3).times
31
- RestClient.should_receive(:post).once
32
- end
33
- it 'creates a dom gun reaction' do
27
+ chain_reaction.stub(:create_payload)
28
+ chain_reaction.stub(:create_dom_gun_reaction)
34
29
  chain_reaction.post_archives("#{SPEC_ROOT}/data/valid_archive")
35
30
  end
31
+ it 'creates the payload' do
32
+ expect(chain_reaction).to have_received(:create_payload).twice
33
+ end
34
+ it 'creates the dom gun reactions' do
35
+ expect(chain_reaction).to have_received(:create_dom_gun_reaction).twice
36
+ end
36
37
  end
37
38
  describe '#id' do
38
39
  it "gets the id from the info" do
@@ -1 +1 @@
1
- {"test_id":1,"time":1369614643,"page_url":"http://www.google.com/","browser":{"name":"firefox","version":"20.0","platform":"darwin"},"event_sequence":[],"doc_width":1004,"doc_height":1010}
1
+ {"test_id":1,"time":1369614643,"page_url":"http://www.google.com/","browser":{"name":"firefox","version":"19.0","platform":"darwin"},"event_sequence":[],"doc_width":1004,"doc_height":1010}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domreactor-redglass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -115,7 +115,7 @@ dependencies:
115
115
  requirements:
116
116
  - - ~>
117
117
  - !ruby/object:Gem::Version
118
- version: 2.13.0
118
+ version: 2.14.0
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
@@ -123,7 +123,7 @@ dependencies:
123
123
  requirements:
124
124
  - - ~>
125
125
  - !ruby/object:Gem::Version
126
- version: 2.13.0
126
+ version: 2.14.0
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: selenium-webdriver
129
129
  requirement: !ruby/object:Gem::Requirement