wbench 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f7c3ab6f6b1bb434b62f44eb6a9582418755f78
4
+ data.tar.gz: 51108410717cd0394a47c0a9789363077d2ac6aa
5
+ SHA512:
6
+ metadata.gz: 61e348f82ba38fc6d287d2108b517420e0b10b4d84edbd1ab625d4d19b0755197b1043a33da5749bb5a9286ec2e94bcbd54e9a6ee1d56d23695e964e717bafc3
7
+ data.tar.gz: 9a4145da2076f46482d3723f696183d2f0068650e5bedb30281b88e5149192152a58db8dc36719d9288ee58e870f22561caa097dfe4f05d1ed017184c93fdd6f
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'rake'
6
+
5
7
  group :test do
6
8
  gem 'rspec'
7
9
  gem 'capybara'
data/README.md CHANGED
@@ -10,6 +10,12 @@ You can install the latest stable gem by running:
10
10
  $ gem install wbench
11
11
  ```
12
12
 
13
+ If you're running an older version (1.8) of ruby, you'll need the JSON gem.
14
+
15
+ ```bash
16
+ $ gem install json
17
+ ```
18
+
13
19
  You will need to install [Google Chrome](http://www.google.com/chrome) as well as the chromedriver utility.
14
20
  You can install chromedriver (on OSX) with homebrew:
15
21
 
@@ -39,6 +45,13 @@ Chrome is the default browser that is used. You can also use firefox by specifyi
39
45
  wbench -b firefox https://www.desktoppr.co/
40
46
  ```
41
47
 
48
+ ### Setting the user agent
49
+ You can also pass the `-u/--user-agent` option to change the browsers user agent (This can be useful for mobile testing).
50
+
51
+ ```bash
52
+ wbench -u "Mozilla/5.0 (iPhone; U; ..." https://www.desktoppr.co/
53
+ ```
54
+
42
55
  ### Ruby API
43
56
 
44
57
  You can programatically run the benchmarks. Simply specify the URL and
@@ -72,5 +85,12 @@ results.latency # =>
72
85
  "ssl.google-analytics.com"=>[497, 14, 14], "www.desktoppr.co"=>[191, 210, 203]}
73
86
  ```
74
87
 
75
- ## TODO
76
- - Add ability to [gist](https://gist.github.com/) results
88
+ ### Gisting results
89
+
90
+ You can install the [Github gist gem](https://github.com/defunkt/gist) and pipe in the results of wbench
91
+
92
+ ```
93
+ gem install gist
94
+
95
+ wbench http://www.google.com.au/ | gist -d "Google homepage"
96
+ ```
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ puts "rspec no available"
8
+ end
9
+
10
+ task :default => ['spec']
data/bin/wbench CHANGED
@@ -21,6 +21,10 @@ options = {}.tap do |options|
21
21
  options[:browser] = browser
22
22
  end
23
23
 
24
+ opts.on("-u", "--user-agent [USER AGENT]", "Set the user-agent (default: browsers' default user-agent value)") do |ua|
25
+ options[:ua] = ua
26
+ end
27
+
24
28
  end.parse!
25
29
  end
26
30
 
data/lib/wbench.rb CHANGED
@@ -5,6 +5,7 @@ require 'benchmark'
5
5
  require 'delegate'
6
6
  require 'colorize'
7
7
  require 'capybara'
8
+ require 'addressable/uri'
8
9
  require 'selenium/webdriver'
9
10
 
10
11
  require 'wbench/timings/app_server'
@@ -1,12 +1,12 @@
1
1
  module WBench
2
2
  class Benchmark
3
3
  def self.run(url, options = {})
4
- new(url, options[:browser]).run(options[:loops] || DEFAULT_LOOPS)
4
+ new(url, options).run(options[:loops] || DEFAULT_LOOPS)
5
5
  end
6
6
 
7
- def initialize(url, browser)
7
+ def initialize(url, options = {})
8
8
  @url = url
9
- @browser = Browser.new(url, browser || DEFAULT_BROWSER)
9
+ @browser = Browser.new(url, options)
10
10
  end
11
11
 
12
12
  def run(loops)
@@ -2,24 +2,27 @@ module WBench
2
2
  class Browser
3
3
  attr_accessor :url
4
4
 
5
- def initialize(url, browser)
5
+ def initialize(url, options = {})
6
+ browser = options[:browser] || DEFAULT_BROWSER
7
+
6
8
  Capybara.register_driver(CAPYBARA_DRIVER) do |app|
7
9
  http_client = Selenium::WebDriver::Remote::Http::Default.new
8
10
  http_client.timeout = CAPYBARA_TIMEOUT
9
11
 
10
- SeleniumDriver.new(app, :browser => browser.to_sym, :http_client => http_client)
12
+ opts = { :browser => browser.to_sym, :http_client => http_client }
13
+ opts[:args] = ["--user-agent='#{options[:ua]}'"] if options[:ua]
14
+
15
+ SeleniumDriver.new(app, opts)
11
16
  end
12
17
 
13
- @url = url
18
+ @url = Addressable::URI.parse(url).normalize.to_s
14
19
  end
15
20
 
16
21
  def visit
17
22
  session.visit(@url)
18
- session.has_css?('body')
23
+ wait_for_page
19
24
  session.execute_script(wbench_javascript)
20
-
21
25
  yield if block_given?
22
-
23
26
  close
24
27
  end
25
28
 
@@ -48,5 +51,11 @@ module WBench
48
51
 
49
52
  @script = jquery.read + stringify.read + wbench.read
50
53
  end
54
+
55
+ def wait_for_page
56
+ Selenium::WebDriver::Wait.new(:timeout => CAPYBARA_TIMEOUT).until do
57
+ session.evaluate_script('document.readyState') == 'complete'
58
+ end
59
+ end
51
60
  end
52
61
  end
@@ -2,7 +2,7 @@ module WBench
2
2
  module Timings
3
3
  class AppServer
4
4
  def initialize(browser)
5
- uri = URI.parse(browser.url)
5
+ uri = Addressable::URI.parse(browser.url)
6
6
  @http = Net::HTTP.new(uri.host, uri.port)
7
7
  @http.use_ssl = uri.scheme == 'https'
8
8
  @request = Net::HTTP::Get.new(uri.request_uri)
@@ -1,3 +1,3 @@
1
1
  module WBench
2
- VERSION = '0.2.3'
2
+ VERSION = '0.3.0'
3
3
  end
data/wbench.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.add_dependency 'capybara'
16
16
  gem.add_dependency 'colorize'
17
+ gem.add_dependency 'addressable'
17
18
 
18
19
  gem.files = `git ls-files`.split($/)
19
20
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,46 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wbench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mario Visic
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-26 00:00:00.000000000 Z
11
+ date: 2013-03-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: capybara
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: colorize
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  description: WBench is a tool that uses the HTML5 performance timing API to benchmark
@@ -86,27 +95,26 @@ files:
86
95
  - wbench.gemspec
87
96
  homepage: ''
88
97
  licenses: []
98
+ metadata: {}
89
99
  post_install_message:
90
100
  rdoc_options: []
91
101
  require_paths:
92
102
  - lib
93
103
  required_ruby_version: !ruby/object:Gem::Requirement
94
- none: false
95
104
  requirements:
96
- - - ! '>='
105
+ - - '>='
97
106
  - !ruby/object:Gem::Version
98
107
  version: '0'
99
108
  required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
109
  requirements:
102
- - - ! '>='
110
+ - - '>='
103
111
  - !ruby/object:Gem::Version
104
112
  version: '0'
105
113
  requirements: []
106
114
  rubyforge_project:
107
- rubygems_version: 1.8.24
115
+ rubygems_version: 2.0.0
108
116
  signing_key:
109
- specification_version: 3
117
+ specification_version: 4
110
118
  summary: Benchmark website loading times
111
119
  test_files:
112
120
  - spec/spec_helper.rb