ritsudo 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -12
- data/lib/ritsudo/benchmark.rb +11 -6
- data/lib/ritsudo/cli.rb +3 -1
- data/lib/ritsudo/driver.rb +27 -4
- data/lib/ritsudo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee2a6abdb855e2cdce4490dd6f35fcf71960388b4612e5ebb95508966567c2e5
|
4
|
+
data.tar.gz: b0cc172d1ebf2642a2ec1489f9906d8a0d4e2d204f1504579fb8a61ebad13bf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 366102b22ebca7f46296a93fb343d9c03cdd7299c22088bc7b0a764b7b6f8ec32545e64d0b445865b065fa5451fe35790074f39ff3e4e4cf62cdb3821ba157a3
|
7
|
+
data.tar.gz: 43a5a6a3efa8981bbdebdf5fda142beb82f19a45e2e46cf14c1b1c4490ae58e2652610e530ea600f328f367df9277d1e415f95b47dd7884da2cd10632cce6d76
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ require "ritsudo"
|
|
24
24
|
ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1"
|
25
25
|
collector = Ritsudo::Collector.new(match: /example\.com/)
|
26
26
|
benchmark = Ritsudo::Benchmark.new(collector: collector)
|
27
|
-
benchmark.do("
|
27
|
+
benchmark.do("https:/www.example.com", driver_options: { user_agent: ua })
|
28
28
|
benchmark.collector.documents.display
|
29
29
|
benchmark.collector.xhrs.display
|
30
30
|
```
|
@@ -43,20 +43,20 @@ Ritsudo requests 5 times: https://example.com
|
|
43
43
|
+------------------+--------+------+-----+-------+
|
44
44
|
|
45
45
|
[Document]
|
46
|
-
|
47
|
-
| url
|
48
|
-
|
49
|
-
|
|
50
|
-
|
46
|
+
+---------------------------+--------+--------+--------+-------+
|
47
|
+
| url | avg | max | min | count |
|
48
|
+
+---------------------------+--------+--------+--------+-------+
|
49
|
+
| https://www.example.com/ | 597.56 | 858.15 | 433.51 | 5 |
|
50
|
+
+---------------------------+--------+--------+--------+-------+
|
51
51
|
|
52
52
|
[XHR]
|
53
|
+
+-------------------------------------------+---------+---------+---------+-------+-------------+
|
54
|
+
| url | avg | max | min | count | uncompleted |
|
55
|
+
+-------------------------------------------+---------+---------+---------+-------+-------------+
|
56
|
+
| https://www.example.com/xhr_request | 300.39 | 500.39 | 250.39 | 4 | 1 |
|
53
57
|
+------------------------------------------+---------+---------+---------+-------+-------------+
|
54
|
-
|
|
55
|
-
|
56
|
-
| http://www.example.com/xhr_request | 300.39 | 500.39 | 250.39 | 4 | 1 |
|
57
|
-
+------------------------------------------+---------+---------+---------+-------+-------------+
|
58
|
-
| http://www.example.com/slow_xhr_request | - | - | - | - | 5 |
|
59
|
-
+------------------------------------------+---------+---------+---------+-------+-------------+
|
58
|
+
| https://www.example.com/slow_xhr_request | - | - | - | - | 5 |
|
59
|
+
+-------------------------------------------+---------+---------+---------+-------+-------------+
|
60
60
|
|
61
61
|
[Script]
|
62
62
|
+--------------------------------+-------+-------+-------+-------+-------------+
|
@@ -65,6 +65,16 @@ Ritsudo requests 5 times: https://example.com
|
|
65
65
|
| https//example.com/example.js | 25.88 | 43.15 | 14.96 | 5 | 0 |
|
66
66
|
+--------------------------------+-------+-------+-------+-------+-------------+
|
67
67
|
```
|
68
|
+
|
69
|
+
### Set Cookies
|
70
|
+
```
|
71
|
+
ritsudo -a https://example.com/page -m "example.com" -C "hoge=fuga"
|
72
|
+
```
|
73
|
+
|
74
|
+
#### Problem
|
75
|
+
Headless chrome doesn't support to set cookies before access.
|
76
|
+
So, Ritsudo access root path(e.g https://example.com") before benchmark.
|
77
|
+
|
68
78
|
## License
|
69
79
|
|
70
80
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/ritsudo/benchmark.rb
CHANGED
@@ -5,15 +5,20 @@ module Ritsudo
|
|
5
5
|
@collector = collector
|
6
6
|
end
|
7
7
|
|
8
|
-
def do(url, count: 5, wait: 1, sub_process_timeout: 3,
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def do(url, count: 5, wait: 1, sub_process_timeout: 3, driver_options: {})
|
9
|
+
if driver_options[:cookies]
|
10
|
+
puts <<-EOS
|
11
|
+
WARNING: headless chrome can not set cookie before access. Ritsudo accesses root path before requested path for set cookies.
|
12
|
+
|
13
|
+
EOS
|
14
|
+
end
|
15
|
+
|
16
|
+
default_driver_options = { timeout: 5, wait_time: 1 }
|
13
17
|
puts "Ritsudo requests #{count} times: #{url}"
|
14
18
|
count.times do
|
15
19
|
print(".")
|
16
|
-
collect(url, wait: wait, sub_process_timeout: sub_process_timeout,
|
20
|
+
collect(url, wait: wait, sub_process_timeout: sub_process_timeout,
|
21
|
+
driver_options: default_driver_options.merge(driver_options))
|
17
22
|
end
|
18
23
|
puts ""
|
19
24
|
end
|
data/lib/ritsudo/cli.rb
CHANGED
@@ -5,6 +5,7 @@ module Ritsudo
|
|
5
5
|
default_command :benchmark
|
6
6
|
option :url, required: true, aliases: ['-a']
|
7
7
|
option :count, default: 5, type: :numeric, aliases: ['-c']
|
8
|
+
option :cookies, type: :string, aliases: ['-C']
|
8
9
|
option :sub_process_timeout, default: 5, type: :numeric, aliases: ['-s']
|
9
10
|
option :timeout, default: 10, type: :numeric, aliases: ['-t']
|
10
11
|
option :wait_time, default: 1, type: :numeric, aliases: ['-w']
|
@@ -21,7 +22,8 @@ module Ritsudo
|
|
21
22
|
driver_options: {
|
22
23
|
timeout: options[:timeout],
|
23
24
|
wait_time: options[:wait_time],
|
24
|
-
user_agent: options[:ua]
|
25
|
+
user_agent: options[:ua],
|
26
|
+
cookies: options[:cookies]
|
25
27
|
}
|
26
28
|
)
|
27
29
|
benchmark.collector.report
|
data/lib/ritsudo/driver.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'selenium-webdriver'
|
2
2
|
require 'forwardable'
|
3
|
+
require 'webrick/cookie'
|
3
4
|
|
4
5
|
module Ritsudo
|
5
6
|
class Driver
|
6
7
|
extend Forwardable
|
7
|
-
def_delegators :@driver, :
|
8
|
+
def_delegators :@driver, :get_log, :manage
|
8
9
|
|
9
10
|
def driver
|
10
11
|
@driver
|
@@ -13,6 +14,7 @@ module Ritsudo
|
|
13
14
|
def initialize(logger_level: :warn, timeout: 60, wait_time: 5,
|
14
15
|
logger_output: "./ritsudo.selenium.log",
|
15
16
|
user_agent: nil,
|
17
|
+
cookies: nil,
|
16
18
|
args: ['--headless',
|
17
19
|
'--window-size=1920,1080',
|
18
20
|
'--ignore-certificate-errors',
|
@@ -24,17 +26,38 @@ module Ritsudo
|
|
24
26
|
args << "--user-agent=#{user_agent}"
|
25
27
|
end
|
26
28
|
|
29
|
+
if cookies
|
30
|
+
@cookie_templates = WEBrick::Cookie.parse(cookies).map do |cookie|
|
31
|
+
{ name: cookie.name, value: cookie.value, path: '/' }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
27
35
|
Selenium::WebDriver.logger.output = logger_output
|
28
36
|
Selenium::WebDriver.logger.level = logger_level
|
29
37
|
client = Selenium::WebDriver::Remote::Http::Default.new.tap { |c| c.read_timeout = timeout }
|
30
|
-
|
31
|
-
|
32
|
-
http_client: client,).tap do |d|
|
38
|
+
driver_options = { options: options(args), desired_capabilities: caps, http_client: client }
|
39
|
+
@driver = Selenium::WebDriver.for(:chrome, driver_options).tap do |d|
|
33
40
|
d.manage.timeouts.implicit_wait = timeout
|
34
41
|
end
|
35
42
|
#@wait = Selenium::WebDriver::Wait.new(timeout: wait_time)
|
36
43
|
end
|
37
44
|
|
45
|
+
def get(url)
|
46
|
+
if @cookie_templates
|
47
|
+
u = URI.parse(url)
|
48
|
+
base_url = u.to_s.sub(u.request_uri, '/')
|
49
|
+
@driver.get(base_url)
|
50
|
+
@driver.execute_script("return window.stop");
|
51
|
+
sleep(1)
|
52
|
+
@driver.manage.logs.get('performance')
|
53
|
+
@cookie_templates&.each do |cookie|
|
54
|
+
manage.add_cookie(cookie.merge(domain: URI.parse(url).host))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
puts @driver.manage.logs.get('performance').inspect
|
58
|
+
@driver.get(url)
|
59
|
+
end
|
60
|
+
|
38
61
|
def caps
|
39
62
|
Selenium::WebDriver::Remote::Capabilities.chrome(
|
40
63
|
loggingPrefs: { performance: 'ALL' },
|
data/lib/ritsudo/version.rb
CHANGED