wbench 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -2
- data/bin/wbench +5 -1
- data/lib/wbench.rb +1 -0
- data/lib/wbench/browser.rb +7 -1
- data/lib/wbench/cookies.rb +57 -0
- data/lib/wbench/version.rb +1 -1
- data/spec/support/test_sites.rb +4 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a645cde605983875de885cb1c76287da7419e388
|
4
|
+
data.tar.gz: 1258f76a78eba4ad2d69abb567ee9363ccb3a2c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97a7c5fca2943106d3a43423078332fa9cf70df22ecd6d98dc0f48f8ecd11805f5cba189fb7c47124cb4d99182ac408354628a8a954178a954f4949c761e6edc
|
7
|
+
data.tar.gz: 4c9a1f7b731da03562f6fb29b60d4d56288ddce736ef1ef5678f61bf88ca3ae1809b40fa179195e0fdc7fe48b2b32c6d83486b034c16084d4fb5611c8f1424c1
|
data/README.md
CHANGED
@@ -69,10 +69,10 @@ $ wbench -u "Mozilla/5.0 (iPhone; U; ..." https://www.desktoppr.co/
|
|
69
69
|
By default the output will be in color. Piping the results to another process
|
70
70
|
should correctly remove the coloring. If your terminal doesn't output color, or
|
71
71
|
you're getting funny symbols in your results then you can remove color from the
|
72
|
-
output using the `-
|
72
|
+
output using the `-nc` flag.
|
73
73
|
|
74
74
|
```bash
|
75
|
-
$ wbench -
|
75
|
+
$ wbench -nc https://www.desktoppr.co/
|
76
76
|
```
|
77
77
|
|
78
78
|
### Server performance measuring
|
@@ -153,6 +153,22 @@ page, some assets may be loaded from the cache, and the result may appear
|
|
153
153
|
quicker than an uncahed visit.
|
154
154
|
|
155
155
|
|
156
|
+
### Setting cookies
|
157
|
+
|
158
|
+
You can pass the `-c` flag to wbench to set a cookie before benchmarking the
|
159
|
+
page, this can be used similarly with the method listed above for testing
|
160
|
+
authenticated pages, as well as any other cookies you would like the browser to use.
|
161
|
+
|
162
|
+
One problem with this approach is that we have to visit the homepage before
|
163
|
+
setting the cookie, this means that some assets may be cached during the visit,
|
164
|
+
skewing your results for the actual page load.
|
165
|
+
|
166
|
+
The cookie format is the same used for curl, so an example might be
|
167
|
+
|
168
|
+
```
|
169
|
+
$ wbench -c "session_id=4000; theme=blue" https://www.desktoppr.co/wallpapers
|
170
|
+
|
171
|
+
|
156
172
|
### Custom event timings
|
157
173
|
|
158
174
|
Custom events are available to instrument through wbench. To do so use the native HTML5 function `window.performance.mark` like so:
|
data/bin/wbench
CHANGED
@@ -25,9 +25,13 @@ options = {}.tap do |options|
|
|
25
25
|
options[:user_agent] = user_agent
|
26
26
|
end
|
27
27
|
|
28
|
-
opts.on("-
|
28
|
+
opts.on("-nc", "--no-color", "Disable color output") do
|
29
29
|
options[:color_output] = false
|
30
30
|
end
|
31
|
+
|
32
|
+
opts.on("-c", "--cookie [COOKIE]", "Set the cookie (default: browsers' default cookie value)") do |cookie|
|
33
|
+
options[:cookie] = cookie
|
34
|
+
end
|
31
35
|
end.parse!
|
32
36
|
end
|
33
37
|
|
data/lib/wbench.rb
CHANGED
data/lib/wbench/browser.rb
CHANGED
@@ -22,10 +22,12 @@ module WBench
|
|
22
22
|
SeleniumDriver.new(app, selenium_options)
|
23
23
|
end
|
24
24
|
|
25
|
-
@url
|
25
|
+
@url = Addressable::URI.parse(url).normalize.to_s
|
26
|
+
@cookie_string = options[:cookie]
|
26
27
|
end
|
27
28
|
|
28
29
|
def visit
|
30
|
+
set_cookies
|
29
31
|
session.visit(@url)
|
30
32
|
wait_for_page
|
31
33
|
session.execute_script(wbench_javascript)
|
@@ -70,5 +72,9 @@ module WBench
|
|
70
72
|
session.evaluate_script('window.performance.timing.loadEventEnd').to_i > 0
|
71
73
|
end
|
72
74
|
end
|
75
|
+
|
76
|
+
def set_cookies
|
77
|
+
WBench::Cookies.set(session, url, @cookie_string)
|
78
|
+
end
|
73
79
|
end
|
74
80
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module WBench
|
2
|
+
class Cookies
|
3
|
+
def self.set(session, url, cookie_string)
|
4
|
+
new(session, url, cookie_string).set
|
5
|
+
end
|
6
|
+
|
7
|
+
private_class_method :new
|
8
|
+
|
9
|
+
def initialize(session, url, cookie_string)
|
10
|
+
@session = session
|
11
|
+
@url = url
|
12
|
+
@cookie_string = cookie_string
|
13
|
+
end
|
14
|
+
|
15
|
+
def set
|
16
|
+
if cookies
|
17
|
+
add_cookies
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def cookies
|
24
|
+
return @cookies if defined?(@cookies)
|
25
|
+
|
26
|
+
if @cookie_string
|
27
|
+
@cookies = @cookie_string.split(/;\s/).map do |line|
|
28
|
+
{ :name => line.split('=')[0], :value => line.split('=')[1] }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_cookies
|
34
|
+
visit_cookie_domain
|
35
|
+
delete_existing_cookies
|
36
|
+
add_new_cookies
|
37
|
+
end
|
38
|
+
|
39
|
+
def visit_cookie_domain
|
40
|
+
@session.visit(cookie_domain)
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_existing_cookies
|
44
|
+
@session.driver.browser.manage.delete_all_cookies
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_new_cookies
|
48
|
+
cookies.each do |cookie|
|
49
|
+
@session.driver.browser.manage.add_cookie(cookie)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def cookie_domain
|
54
|
+
Addressable::URI.parse(@url).tap { |uri| uri.path = '' }.normalize.to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/wbench/version.rb
CHANGED
data/spec/support/test_sites.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
|
4
4
|
def sites
|
5
5
|
[
|
6
|
-
'https://www.google.com.au/',
|
7
|
-
'https://www.desktoppr.co/',
|
8
|
-
'http://www.giftoppr.co/',
|
9
|
-
'http://au.yahoo.com/'
|
6
|
+
#'https://www.google.com.au/',
|
7
|
+
#'https://www.desktoppr.co/',
|
8
|
+
#'http://www.giftoppr.co/',
|
9
|
+
#'http://au.yahoo.com/'
|
10
10
|
]
|
11
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wbench
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Visic
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/wbench/benchmark.rb
|
91
91
|
- lib/wbench/browser.rb
|
92
92
|
- lib/wbench/colored_string.rb
|
93
|
+
- lib/wbench/cookies.rb
|
93
94
|
- lib/wbench/results.rb
|
94
95
|
- lib/wbench/results_formatter.rb
|
95
96
|
- lib/wbench/row_formatter.rb
|