I worked with Browsermob Proxythrough the current version of browser-proxy.rb to write a few RSpec.
Unfortunately, it does not seem to accidentally register traffic. On some tests, traffic is recorded fine. In others, without any changes to the code or the environment, the har files that it issues are all empty. The tests themselves pass without problems, but nothing is recorded. Har files are always generated.
I know that all my code runs through my logs. So I don’t know where exactly the problem is. I have included some of the relevant code below:
Saving logic (this is called a block after(:all)at the end of tests)
def save_har(test_name,har_dir)
if @proxy.nil?
log_proxy_helper "Proxy instance already stopped, cannot save 'har' file"
else
log_proxy_helper "Saving har to #{har_dir}"
filename = ("#{test_name}.har").gsub(' ','_')
path = File.expand_path(File.join(har_dir , filename))
if path.match(/^C:\//)
path.gsub!(/\//, "\\")
end
begin
@proxy.har.save_to path
rescue Exception => e
log_proxy_helper "Error: #{e}"
end
log_proxy_helper "Saved har to #{path}"
end
end
The logic of creating a proxy server (in the same file and context as above)
def start_proxy
begin
log_proxy_helper "Starting proxy using port #{proxy_port}"
logs_path = 'logs/'
logs_path = ENV['WORKSPACE'] + '/logs/' if ENV['WORKSPACE']
@proxy_server = BrowserMob::Proxy::Server.new(browsermob_proxy_path,{:port => 9090,:log => false,:logs_path => logs_path, :use_little_proxy => false, :timeout => 30})
begin
@proxy_server.start
rescue Exception => e
log_proxy_helper "Error: #{e}"
end
@proxy = @proxy_server.create_proxy proxy_port
@proxy.new_har(:capture_binary_content => true)
log_proxy_helper "Server Started"
end if check_proxy_configured 'Can\'t start proxy'
end
har:
{
"log": {
"version": "1.2",
"creator": {
"name": "BrowserMob Proxy",
"version": "2.1.0-beta-3-littleproxy",
"comment": ""
},
"pages": [
{
"id": "Page 0",
"startedDateTime": "2015-11-17T16:18:16.695-05:00",
"title": "Page 0",
"pageTimings": {
"onLoad": 2916,
"comment": ""
},
"comment": ""
}
],
"entries": [],
"comment": ""
}
}
?
EDIT:
, Internet Explorer; Firefox Chrome