browsermob-proxy 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec", ">= 2.5.0"
23
23
  s.add_development_dependency "selenium-webdriver", "~> 2.7"
24
24
  s.add_development_dependency "rake", "~> 0.9.2"
25
+ s.add_development_dependency "rack"
25
26
 
26
27
  s.files = `git ls-files`.split("\n")
27
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -22,8 +22,27 @@ module BrowserMob
22
22
  @port = port
23
23
  end
24
24
 
25
- def new_har(ref = nil)
26
- previous = @resource["har"].put :initialPageRef => ref
25
+ #
26
+ # Examples:
27
+ #
28
+ # client.new_har("page-name")
29
+ # client.new_har("page-name", :capture_headers => true)
30
+ # client.new_har(:capture_headers => true)
31
+ #
32
+
33
+ def new_har(ref = nil, opts = {})
34
+ if opts.empty? && ref.kind_of?(Hash)
35
+ opts = ref
36
+ ref = nil
37
+ end
38
+
39
+ params = {}
40
+
41
+ params[:initialPageRef] = ref if ref
42
+ params[:captureHeaders] = true if opts[:capture_headers]
43
+
44
+
45
+ previous = @resource["har"].put params
27
46
  HAR::Archive.from_string(previous) unless previous.empty?
28
47
  end
29
48
 
@@ -93,4 +112,4 @@ module BrowserMob
93
112
  end # Client
94
113
 
95
114
  end # Proxy
96
- end # BrowserMob
115
+ end # BrowserMob
@@ -1,5 +1,5 @@
1
1
  module BrowserMob
2
2
  module Proxy
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -15,9 +15,12 @@ module BrowserMob
15
15
  class WebDriverListener < Selenium::WebDriver::Support::AbstractEventListener
16
16
  attr_reader :hars
17
17
 
18
- def initialize(client)
18
+ def initialize(client, opts = {})
19
19
  @client = client
20
20
  @hars = []
21
+
22
+ @new_har_opts = {}
23
+ @new_har_opts[:capture_headers] = true if opts[:capture_headers]
21
24
  end
22
25
 
23
26
  def reset
@@ -26,7 +29,7 @@ module BrowserMob
26
29
 
27
30
  def before_navigate_to(url, driver)
28
31
  save_har unless @hars.empty? # first request
29
- @client.new_har("navigate-to-#{url}")
32
+ @client.new_har("navigate-to-#{url}", @new_har_opts)
30
33
  end
31
34
 
32
35
  def before_navigate_back(driver = nil)
@@ -64,4 +67,4 @@ module BrowserMob
64
67
  end
65
68
  end
66
69
  end
67
- end
70
+ end
@@ -29,6 +29,17 @@ describe "Proxy + WebDriver" do
29
29
  har.pages.size.should == 2
30
30
  end
31
31
 
32
+ it "should fetch a HAR and capture headers" do
33
+ proxy.new_har("2", :capture_headers => true)
34
+
35
+ driver.get url_for("2.html")
36
+
37
+ entry = proxy.har.entries.first
38
+ entry.should_not be_nil
39
+
40
+ entry.request.headers.should_not be_empty
41
+ end
42
+
32
43
  it "should set whitelist and blacklist" do
33
44
  proxy.whitelist(/example\.com/, 201)
34
45
  proxy.blacklist(/bad\.com/, 404)
@@ -42,4 +53,4 @@ describe "Proxy + WebDriver" do
42
53
  proxy.limit(:downstream_kbps => 100, :upstream_kbps => 100, :latency => 2)
43
54
  end
44
55
 
45
- end
56
+ end
@@ -1,16 +1,25 @@
1
1
  require 'browsermob/proxy'
2
2
  require 'selenium-webdriver'
3
3
  require 'browsermob/proxy/webdriver_listener'
4
+ require 'rack'
4
5
 
5
6
  RestClient.log = STDOUT
6
7
 
7
8
  module BrowserMob
8
9
  module Proxy
9
10
  module SpecHelper
11
+ def self.httpd
12
+ @httpd ||= HttpServer.new(Rack::File.new(fixture_dir))
13
+ end
14
+
15
+ def self.fixture_dir
16
+ @fixture_dir ||= File.join(File.expand_path("../", __FILE__), "fixtures")
17
+ end
18
+
10
19
  def server
11
20
  $_bm_server ||= Server.new(
12
21
  File.join(home, "bin", "browsermob-proxy"),
13
- :port => Selenium::WebDriver::PortProber.random,
22
+ :port => Selenium::WebDriver::PortProber.above(3000),
14
23
  :log => true
15
24
  ).start
16
25
  end
@@ -28,11 +37,34 @@ module BrowserMob
28
37
  end
29
38
 
30
39
  def url_for(page)
31
- "file://#{fixture_path page}"
40
+ SpecHelper.httpd.url_for(page)
32
41
  end
33
42
 
34
43
  def fixture_path(name)
35
- File.join(File.expand_path("../", __FILE__), "fixtures", name)
44
+ File.join(SpecHelper.fixture_dir, name)
45
+ end
46
+
47
+ class HttpServer
48
+ def initialize(app)
49
+ @port = Selenium::WebDriver::PortProber.above(3000)
50
+
51
+ pid = fork do
52
+ Rack::Server.new(:app => app, :Port => @port).start
53
+ end
54
+
55
+ at_exit { Process.kill 'TERM', pid }
56
+
57
+ poller = Selenium::WebDriver::SocketPoller.new("localhost", @port, 10)
58
+
59
+ unless poller.connected?
60
+ raise "unable to start web server in 5 seconds"
61
+ end
62
+ end
63
+
64
+ def url_for(page)
65
+ # use 0.0.0.0 to avoid default no-proxy rules on localhost
66
+ "http://0.0.0.0:#{@port}/#{page}"
67
+ end
36
68
  end
37
69
 
38
70
  end
@@ -20,7 +20,7 @@ module BrowserMob
20
20
  end
21
21
  end
22
22
 
23
- it "creates a new har" do
23
+ it "creates a named har" do
24
24
  resource['har'].should_receive(:put).
25
25
  with(:initialPageRef => "foo").
26
26
  and_return('')
@@ -28,6 +28,14 @@ module BrowserMob
28
28
  client.new_har("foo").should be_nil
29
29
  end
30
30
 
31
+ it "creates a new har with no name" do
32
+ resource['har'].should_receive(:put).
33
+ with({}).
34
+ and_return('')
35
+
36
+ client.new_har.should be_nil
37
+ end
38
+
31
39
  it "returns the previous archive if one exists" do
32
40
  resource['har'].should_receive(:put).
33
41
  with(:initialPageRef => "foo").
@@ -36,6 +44,22 @@ module BrowserMob
36
44
  client.new_har("foo").should be_kind_of(HAR::Archive)
37
45
  end
38
46
 
47
+ it "turns on header capture when given a name" do
48
+ resource['har'].should_receive(:put).
49
+ with(:initialPageRef => "foo", :captureHeaders => true).
50
+ and_return('')
51
+
52
+ client.new_har("foo", :capture_headers => true).should be_nil
53
+ end
54
+
55
+ it "turns on header capture when not given a name" do
56
+ resource['har'].should_receive(:put).
57
+ with(:captureHeaders => true).
58
+ and_return('')
59
+
60
+ client.new_har(:capture_headers => true).should be_nil
61
+ end
62
+
39
63
  it "gets the current har" do
40
64
  resource['har'].should_receive(:get).
41
65
  and_return(fixture("google.har"))
@@ -137,4 +161,4 @@ module BrowserMob
137
161
  end
138
162
 
139
163
  end
140
- end
164
+ end
@@ -9,10 +9,10 @@ module BrowserMob
9
9
  let(:listener) { WebDriverListener.new(client) }
10
10
  let(:element) { mock(Selenium::WebDriver::Element, :ref => "some-id")}
11
11
  let(:har) { mock(HAR::Archive) }
12
+ let(:url) { "http://example.com" }
12
13
 
13
14
  it 'creates a new har on navigate.to' do
14
- url = "http://example.com"
15
- client.should_receive(:new_har).with("navigate-to-http://example.com")
15
+ client.should_receive(:new_har).with("navigate-to-http://example.com", {})
16
16
  client.should_receive(:har).and_return(:har)
17
17
 
18
18
  listener.before_navigate_to(url, driver)
@@ -44,6 +44,13 @@ module BrowserMob
44
44
  listener.before_quit(driver)
45
45
  listener.hars.size.should == 1
46
46
  end
47
+
48
+ it 'passes the :capture_headers option' do
49
+ listener = WebDriverListener.new(client, :capture_headers => true)
50
+ client.should_receive(:new_har).with("navigate-to-http://example.com", :capture_headers => true)
51
+
52
+ listener.before_navigate_to(url, driver)
53
+ end
47
54
  end
48
55
  end
49
- end
56
+ end
metadata CHANGED
@@ -1,135 +1,150 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: browsermob-proxy
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.7
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 8
10
+ version: 0.0.8
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - jari.bakken
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-06-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rest-client
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
22
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: childprocess
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
38
32
  type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: childprocess
39
36
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
41
38
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: multi_json
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '1.0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
54
46
  type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: multi_json
55
50
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
51
+ requirement: &id003 !ruby/object:Gem::Requirement
57
52
  none: false
58
- requirements:
53
+ requirements:
59
54
  - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- - !ruby/object:Gem::Dependency
63
- name: har
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
55
+ - !ruby/object:Gem::Version
56
+ hash: 15
57
+ segments:
58
+ - 1
59
+ - 0
60
+ version: "1.0"
70
61
  type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: har
71
65
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
66
+ requirement: &id004 !ruby/object:Gem::Requirement
73
67
  none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :runtime
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
79
78
  name: rspec
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: 2.5.0
86
- type: :development
87
79
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
80
+ requirement: &id005 !ruby/object:Gem::Requirement
89
81
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 27
86
+ segments:
87
+ - 2
88
+ - 5
89
+ - 0
93
90
  version: 2.5.0
94
- - !ruby/object:Gem::Dependency
95
- name: selenium-webdriver
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: '2.7'
102
91
  type: :development
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: selenium-webdriver
103
95
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
96
+ requirement: &id006 !ruby/object:Gem::Requirement
105
97
  none: false
106
- requirements:
98
+ requirements:
107
99
  - - ~>
108
- - !ruby/object:Gem::Version
109
- version: '2.7'
110
- - !ruby/object:Gem::Dependency
100
+ - !ruby/object:Gem::Version
101
+ hash: 13
102
+ segments:
103
+ - 2
104
+ - 7
105
+ version: "2.7"
106
+ type: :development
107
+ version_requirements: *id006
108
+ - !ruby/object:Gem::Dependency
111
109
  name: rake
112
- requirement: !ruby/object:Gem::Requirement
110
+ prerelease: false
111
+ requirement: &id007 !ruby/object:Gem::Requirement
113
112
  none: false
114
- requirements:
113
+ requirements:
115
114
  - - ~>
116
- - !ruby/object:Gem::Version
115
+ - !ruby/object:Gem::Version
116
+ hash: 63
117
+ segments:
118
+ - 0
119
+ - 9
120
+ - 2
117
121
  version: 0.9.2
118
122
  type: :development
123
+ version_requirements: *id007
124
+ - !ruby/object:Gem::Dependency
125
+ name: rack
119
126
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
127
+ requirement: &id008 !ruby/object:Gem::Requirement
121
128
  none: false
122
- requirements:
123
- - - ~>
124
- - !ruby/object:Gem::Version
125
- version: 0.9.2
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ type: :development
137
+ version_requirements: *id008
126
138
  description: Ruby client for the BrowserMob Proxy REST API
127
- email:
139
+ email:
128
140
  - jari.bakken@gmail.com
129
141
  executables: []
142
+
130
143
  extensions: []
144
+
131
145
  extra_rdoc_files: []
132
- files:
146
+
147
+ files:
133
148
  - .gitignore
134
149
  - .travis.yml
135
150
  - Gemfile
@@ -154,36 +169,37 @@ files:
154
169
  - spec/unit/webdriver_listener_spec.rb
155
170
  homepage: http://github.com/jarib/browsermob-proxy-rb
156
171
  licenses: []
172
+
157
173
  post_install_message:
158
174
  rdoc_options: []
159
- require_paths:
175
+
176
+ require_paths:
160
177
  - lib
161
- required_ruby_version: !ruby/object:Gem::Requirement
178
+ required_ruby_version: !ruby/object:Gem::Requirement
162
179
  none: false
163
- requirements:
164
- - - ! '>='
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ hash: 3
184
+ segments:
185
+ - 0
186
+ version: "0"
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
188
  none: false
169
- requirements:
170
- - - ! '>='
171
- - !ruby/object:Gem::Version
172
- version: '0'
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ hash: 3
193
+ segments:
194
+ - 0
195
+ version: "0"
173
196
  requirements: []
197
+
174
198
  rubyforge_project: browsermob-proxy-rb
175
- rubygems_version: 1.8.21
199
+ rubygems_version: 1.8.10
176
200
  signing_key:
177
201
  specification_version: 3
178
202
  summary: Ruby client for the BrowserMob Proxy REST API
179
- test_files:
180
- - spec/e2e/listener_spec.rb
181
- - spec/e2e/selenium_spec.rb
182
- - spec/fixtures/1.html
183
- - spec/fixtures/2.html
184
- - spec/fixtures/3.html
185
- - spec/fixtures/google.har
186
- - spec/spec_helper.rb
187
- - spec/unit/client_spec.rb
188
- - spec/unit/webdriver_listener_spec.rb
203
+ test_files: []
204
+
189
205
  has_rdoc: