ruby-jmeter 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.gitattributes +22 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +27 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +333 -0
  7. data/Rakefile +6 -0
  8. data/bin/grid +25 -0
  9. data/examples/basic_assertion.rb +13 -0
  10. data/examples/basic_auth.rb +11 -0
  11. data/examples/basic_cache.rb +11 -0
  12. data/examples/basic_cookies.rb +11 -0
  13. data/examples/basic_extract.rb +10 -0
  14. data/examples/basic_gc_dummy_sampler.rb +10 -0
  15. data/examples/basic_gc_results.rb +23 -0
  16. data/examples/basic_google.rb +8 -0
  17. data/examples/basic_grid.rb +8 -0
  18. data/examples/basic_header.rb +19 -0
  19. data/examples/basic_ldap_ext.rb +16 -0
  20. data/examples/basic_post.rb +15 -0
  21. data/examples/basic_query_params.rb +8 -0
  22. data/examples/basic_think_time.rb +15 -0
  23. data/examples/basic_throughput_controller.rb +14 -0
  24. data/examples/basic_throughput_shaping_timer.rb +21 -0
  25. data/examples/etsy_login_browse.rb +64 -0
  26. data/lib/ruby-jmeter.rb +18 -0
  27. data/lib/ruby-jmeter/DSL.md +237 -0
  28. data/lib/ruby-jmeter/dsl.rb +419 -0
  29. data/lib/ruby-jmeter/dsl/access_log_sampler.rb +32 -0
  30. data/lib/ruby-jmeter/dsl/aggregate_graph.rb +55 -0
  31. data/lib/ruby-jmeter/dsl/aggregate_report.rb +55 -0
  32. data/lib/ruby-jmeter/dsl/ajp13_sampler.rb +41 -0
  33. data/lib/ruby-jmeter/dsl/assertion_results.rb +55 -0
  34. data/lib/ruby-jmeter/dsl/beanshell_assertion.rb +28 -0
  35. data/lib/ruby-jmeter/dsl/beanshell_listener.rb +28 -0
  36. data/lib/ruby-jmeter/dsl/beanshell_postprocessor.rb +28 -0
  37. data/lib/ruby-jmeter/dsl/beanshell_preprocessor.rb +28 -0
  38. data/lib/ruby-jmeter/dsl/beanshell_sampler.rb +28 -0
  39. data/lib/ruby-jmeter/dsl/beanshell_timer.rb +28 -0
  40. data/lib/ruby-jmeter/dsl/bsf_assertion.rb +28 -0
  41. data/lib/ruby-jmeter/dsl/bsf_listener.rb +28 -0
  42. data/lib/ruby-jmeter/dsl/bsf_postprocessor.rb +28 -0
  43. data/lib/ruby-jmeter/dsl/bsf_preprocessor.rb +28 -0
  44. data/lib/ruby-jmeter/dsl/bsf_sampler.rb +28 -0
  45. data/lib/ruby-jmeter/dsl/bsf_timer.rb +28 -0
  46. data/lib/ruby-jmeter/dsl/compare_assertion.rb +27 -0
  47. data/lib/ruby-jmeter/dsl/comparison_assertion_visualizer.rb +55 -0
  48. data/lib/ruby-jmeter/dsl/constant_throughput_timer.rb +30 -0
  49. data/lib/ruby-jmeter/dsl/constant_timer.rb +25 -0
  50. data/lib/ruby-jmeter/dsl/counter.rb +31 -0
  51. data/lib/ruby-jmeter/dsl/cssjquery_extractor.rb +30 -0
  52. data/lib/ruby-jmeter/dsl/csv_data_set_config.rb +32 -0
  53. data/lib/ruby-jmeter/dsl/debug_postprocessor.rb +28 -0
  54. data/lib/ruby-jmeter/dsl/debug_sampler.rb +27 -0
  55. data/lib/ruby-jmeter/dsl/distribution_graphalpha.rb +55 -0
  56. data/lib/ruby-jmeter/dsl/duration_assertion.rb +25 -0
  57. data/lib/ruby-jmeter/dsl/foreach_controller.rb +29 -0
  58. data/lib/ruby-jmeter/dsl/ftp_request.rb +34 -0
  59. data/lib/ruby-jmeter/dsl/ftp_request_defaults.rb +32 -0
  60. data/lib/ruby-jmeter/dsl/gaussian_random_timer.rb +26 -0
  61. data/lib/ruby-jmeter/dsl/generate_summary_results.rb +23 -0
  62. data/lib/ruby-jmeter/dsl/graph_results.rb +55 -0
  63. data/lib/ruby-jmeter/dsl/html_assertion.rb +30 -0
  64. data/lib/ruby-jmeter/dsl/html_link_parser.rb +23 -0
  65. data/lib/ruby-jmeter/dsl/html_parameter_mask.rb +32 -0
  66. data/lib/ruby-jmeter/dsl/http_authorization_manager.rb +33 -0
  67. data/lib/ruby-jmeter/dsl/http_cache_manager.rb +26 -0
  68. data/lib/ruby-jmeter/dsl/http_cookie_manager.rb +27 -0
  69. data/lib/ruby-jmeter/dsl/http_header_manager.rb +30 -0
  70. data/lib/ruby-jmeter/dsl/http_request.rb +41 -0
  71. data/lib/ruby-jmeter/dsl/http_request_defaults.rb +44 -0
  72. data/lib/ruby-jmeter/dsl/http_url_rewriting_modifier.rb +29 -0
  73. data/lib/ruby-jmeter/dsl/if_controller.rb +27 -0
  74. data/lib/ruby-jmeter/dsl/include_controller.rb +25 -0
  75. data/lib/ruby-jmeter/dsl/java_request.rb +69 -0
  76. data/lib/ruby-jmeter/dsl/java_request_defaults.rb +69 -0
  77. data/lib/ruby-jmeter/dsl/jdbc_connection_configuration.rb +37 -0
  78. data/lib/ruby-jmeter/dsl/jdbc_postprocessor.rb +31 -0
  79. data/lib/ruby-jmeter/dsl/jdbc_preprocessor.rb +31 -0
  80. data/lib/ruby-jmeter/dsl/jdbc_request.rb +31 -0
  81. data/lib/ruby-jmeter/dsl/jms_pointtopoint.rb +40 -0
  82. data/lib/ruby-jmeter/dsl/jms_publisher.rb +41 -0
  83. data/lib/ruby-jmeter/dsl/jms_subscriber.rb +35 -0
  84. data/lib/ruby-jmeter/dsl/jsr223_assertion.rb +29 -0
  85. data/lib/ruby-jmeter/dsl/jsr223_listener.rb +29 -0
  86. data/lib/ruby-jmeter/dsl/jsr223_postprocessor.rb +29 -0
  87. data/lib/ruby-jmeter/dsl/jsr223_preprocessor.rb +29 -0
  88. data/lib/ruby-jmeter/dsl/jsr223_sampler.rb +29 -0
  89. data/lib/ruby-jmeter/dsl/jsr223_timer.rb +29 -0
  90. data/lib/ruby-jmeter/dsl/junit_request.rb +37 -0
  91. data/lib/ruby-jmeter/dsl/keystore_configuration.rb +27 -0
  92. data/lib/ruby-jmeter/dsl/ldap_extended_request.rb +42 -0
  93. data/lib/ruby-jmeter/dsl/ldap_extended_request_defaults.rb +42 -0
  94. data/lib/ruby-jmeter/dsl/ldap_request.rb +35 -0
  95. data/lib/ruby-jmeter/dsl/ldap_request_defaults.rb +40 -0
  96. data/lib/ruby-jmeter/dsl/login_config_element.rb +26 -0
  97. data/lib/ruby-jmeter/dsl/loop_controller.rb +26 -0
  98. data/lib/ruby-jmeter/dsl/mail_reader_sampler.rb +37 -0
  99. data/lib/ruby-jmeter/dsl/mailer_visualizer.rb +64 -0
  100. data/lib/ruby-jmeter/dsl/md5hex_assertion.rb +25 -0
  101. data/lib/ruby-jmeter/dsl/module_controller.rb +23 -0
  102. data/lib/ruby-jmeter/dsl/monitor_results.rb +55 -0
  103. data/lib/ruby-jmeter/dsl/once_only_controller.rb +23 -0
  104. data/lib/ruby-jmeter/dsl/os_process_sampler.rb +34 -0
  105. data/lib/ruby-jmeter/dsl/poisson_random_timer.rb +26 -0
  106. data/lib/ruby-jmeter/dsl/random_controller.rb +25 -0
  107. data/lib/ruby-jmeter/dsl/random_order_controller.rb +23 -0
  108. data/lib/ruby-jmeter/dsl/random_variable.rb +30 -0
  109. data/lib/ruby-jmeter/dsl/recording_controller.rb +23 -0
  110. data/lib/ruby-jmeter/dsl/regex_user_parameters.rb +27 -0
  111. data/lib/ruby-jmeter/dsl/regular_expression_extractor.rb +31 -0
  112. data/lib/ruby-jmeter/dsl/response_assertion.rb +31 -0
  113. data/lib/ruby-jmeter/dsl/response_time_graph.rb +55 -0
  114. data/lib/ruby-jmeter/dsl/result_status_action_handler.rb +25 -0
  115. data/lib/ruby-jmeter/dsl/runtime_controller.rb +25 -0
  116. data/lib/ruby-jmeter/dsl/save_responses_to_a_file.rb +29 -0
  117. data/lib/ruby-jmeter/dsl/simple_config_element.rb +23 -0
  118. data/lib/ruby-jmeter/dsl/simple_controller.rb +23 -0
  119. data/lib/ruby-jmeter/dsl/simple_data_writer.rb +55 -0
  120. data/lib/ruby-jmeter/dsl/smime_assertion.rb +35 -0
  121. data/lib/ruby-jmeter/dsl/smtp_sampler.rb +51 -0
  122. data/lib/ruby-jmeter/dsl/soapxmlrpc_request.rb +33 -0
  123. data/lib/ruby-jmeter/dsl/spline_visualizer.rb +55 -0
  124. data/lib/ruby-jmeter/dsl/summary_report.rb +55 -0
  125. data/lib/ruby-jmeter/dsl/switch_controller.rb +25 -0
  126. data/lib/ruby-jmeter/dsl/synchronizing_timer.rb +25 -0
  127. data/lib/ruby-jmeter/dsl/tcp_sampler.rb +33 -0
  128. data/lib/ruby-jmeter/dsl/tcp_sampler_config.rb +31 -0
  129. data/lib/ruby-jmeter/dsl/test_action.rb +27 -0
  130. data/lib/ruby-jmeter/dsl/test_plan.rb +31 -0
  131. data/lib/ruby-jmeter/dsl/thread_group.rb +36 -0
  132. data/lib/ruby-jmeter/dsl/throughput_controller.rb +32 -0
  133. data/lib/ruby-jmeter/dsl/transaction_controller.rb +26 -0
  134. data/lib/ruby-jmeter/dsl/uniform_random_timer.rb +26 -0
  135. data/lib/ruby-jmeter/dsl/user_defined_variables.rb +32 -0
  136. data/lib/ruby-jmeter/dsl/user_parameters.rb +29 -0
  137. data/lib/ruby-jmeter/dsl/view_results_in_table.rb +55 -0
  138. data/lib/ruby-jmeter/dsl/view_results_tree.rb +55 -0
  139. data/lib/ruby-jmeter/dsl/while_controller.rb +25 -0
  140. data/lib/ruby-jmeter/dsl/xml_assertion.rb +23 -0
  141. data/lib/ruby-jmeter/dsl/xml_schema_assertion.rb +25 -0
  142. data/lib/ruby-jmeter/dsl/xpath_assertion.rb +30 -0
  143. data/lib/ruby-jmeter/dsl/xpath_extractor.rb +30 -0
  144. data/lib/ruby-jmeter/helpers/fallback_content_proxy.rb +54 -0
  145. data/lib/ruby-jmeter/helpers/helper.rb +41 -0
  146. data/lib/ruby-jmeter/helpers/jmeter.properties +28 -0
  147. data/lib/ruby-jmeter/helpers/logger-colors.rb +48 -0
  148. data/lib/ruby-jmeter/helpers/parser.rb +106 -0
  149. data/lib/ruby-jmeter/helpers/strip-heredoc.rb +5 -0
  150. data/lib/ruby-jmeter/helpers/user-agents.rb +27 -0
  151. data/lib/ruby-jmeter/idl.rb +70 -0
  152. data/lib/ruby-jmeter/idl.xml +1513 -0
  153. data/lib/ruby-jmeter/plugins/gc_console_status_logger.rb +14 -0
  154. data/lib/ruby-jmeter/plugins/gc_dummy_sampler.rb +23 -0
  155. data/lib/ruby-jmeter/plugins/gc_latencies_over_time.rb +48 -0
  156. data/lib/ruby-jmeter/plugins/gc_response_codes_per_second.rb +48 -0
  157. data/lib/ruby-jmeter/plugins/gc_response_times_distribution.rb +47 -0
  158. data/lib/ruby-jmeter/plugins/gc_response_times_over_time.rb +48 -0
  159. data/lib/ruby-jmeter/plugins/gc_response_times_percentiles.rb +48 -0
  160. data/lib/ruby-jmeter/plugins/gc_transactions_per_second.rb +48 -0
  161. data/lib/ruby-jmeter/plugins/gc_variable_throughput_timer.rb +26 -0
  162. data/lib/ruby-jmeter/version.rb +3 -0
  163. data/ruby-jmeter.gemspec +22 -0
  164. data/spec/dsl_spec.rb +491 -0
  165. data/spec/spec_helper.rb +10 -0
  166. data/spec/stub.rb +31 -0
  167. metadata +244 -0
data/.gitattributes ADDED
@@ -0,0 +1,22 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
3
+
4
+ # Custom for Visual Studio
5
+ *.cs diff=csharp
6
+ *.sln merge=union
7
+ *.csproj merge=union
8
+ *.vbproj merge=union
9
+ *.fsproj merge=union
10
+ *.dbproj merge=union
11
+
12
+ # Standard to msysgit
13
+ *.doc diff=astextplain
14
+ *.DOC diff=astextplain
15
+ *.docx diff=astextplain
16
+ *.DOCX diff=astextplain
17
+ *.dot diff=astextplain
18
+ *.DOT diff=astextplain
19
+ *.pdf diff=astextplain
20
+ *.PDF diff=astextplain
21
+ *.rtf diff=astextplain
22
+ *.RTF diff=astextplain
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.log
20
+ *.jmx
21
+ *.jtl
22
+ *.bak
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby-jmeter.gemspec
4
+ gemspec
5
+
6
+ gem 'nokogiri'
7
+ gem 'rest-client'
8
+ gem 'json'
9
+
10
+ platforms :jruby do
11
+ gem 'json-jruby'
12
+ end
13
+
14
+ group :development do
15
+ gem 'pry', :require => 'pry'
16
+ gem 'pry-nav', :require => 'pry-nav'
17
+ gem 'pry-debugger', :require => 'pry-debugger'
18
+ gem 'awesome_print', :require => 'ap'
19
+ end
20
+
21
+ group :test do
22
+ gem 'rake'
23
+ gem 'rspec'
24
+ gem 'sinatra'
25
+ gem 'haml'
26
+ gem 'pry-debugger', :require => 'pry-debugger'
27
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # RubyJmeter
2
+
3
+ Tired of using the JMeter GUI or looking at hairy XML files?
4
+
5
+ This gem lets you write test plans for JMeter in your favourite text editor, and optionally run them on [flood.io](http://flood.io).
6
+
7
+ ## Installation
8
+
9
+ Install it yourself as:
10
+
11
+ $ gem install ruby-jmeter
12
+
13
+ ## Basic Usage
14
+
15
+ *RubyJmeter* exposes easy-to-use domain specific language for fluent communication with [JMeter](http://jmeter.apache.org/).It also includes API integration with [flood.io](https://flood.io), a cloud based load testing service.
16
+
17
+ To use the DSL, first let's require the gem:
18
+
19
+ ```ruby
20
+ require 'rubygems'
21
+ require 'ruby-jmeter'
22
+ ```
23
+
24
+ ### Basic Example
25
+ Let's create a `test` and save the related `jmx` testplan to file, so we can edit/view it in JMeter.
26
+
27
+ ```ruby
28
+ test do
29
+ threads count: 10 do
30
+ visit name: 'Google Search', url: 'http://google.com'
31
+ end
32
+ end.jmx
33
+ ```
34
+
35
+ So in this example, we just created a test plan, with 10 threads, each of which visited the search page at Google.
36
+
37
+ ### Generating a JMeter Test Plan (JMX)
38
+ Note also how we called the `jmx` method of the test. Calling this method will write the contents of the JMeter test plan to file like this.
39
+
40
+ ```
41
+ $ ruby testplan.rb
42
+ [2013-04-23T10:29:03.275743 #42060] INFO -- : Test plan saved to: jmeter.jmx
43
+ ```
44
+
45
+ ```xml
46
+ <?xml version="1.0" encoding="UTF-8"?>
47
+ <jmeterTestPlan version="1.2" properties="2.1">
48
+ <hashTree>
49
+ <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
50
+ ...
51
+ </TestPlan>
52
+ </hashTree>
53
+ </jmeterTestPlan>
54
+ JMX saved to: jmeter.jmx
55
+ ```
56
+
57
+ The file that is created can then be executed in the JMeter GUI. If you want to create the file with a different filename and/or path, just add the `file` parameter to the `jmx` method call like this.
58
+
59
+ ```ruby
60
+ test do
61
+ threads count: 10 do
62
+ visit name: 'Google Search', url: 'http://google.com'
63
+ end
64
+ end.jmx(file: "/tmp/my_testplan.jmx")
65
+ ```
66
+
67
+ Windows users should specify a path like this.
68
+
69
+ ```ruby
70
+ .jmx(file: "C:\\TEMP\\MyTestplan.jmx")
71
+ ```
72
+
73
+ ### Running a JMeter Test Plan locally
74
+ You can execute the JMeter test plan by calling the `run` method of the test like this.
75
+
76
+ ```ruby
77
+ test do
78
+ threads count: 10 do
79
+ visit name: 'Google Search', url: 'http://google.com'
80
+ end
81
+ end.run
82
+ ```
83
+
84
+ This will launch JMeter in headless (non-GUI mode) and execute the test plan. This is useful for shaking out the script before you push it to the Grid. There are a few parameters that you can set such as the `path` to the JMeter binary, the `file` path/name for the JMX file, the `log` path/name to output JMeter logs and the `jtl` path/name for JMeter results like this.
85
+
86
+ ```ruby
87
+ test do
88
+ threads count: 10 do
89
+ visit name: 'Google Search', url: 'http://google.com'
90
+ end
91
+ end.run(
92
+ path: '/usr/share/jmeter/bin/',
93
+ file: 'jmeter.jmx',
94
+ log: 'jmeter.log',
95
+ jtl: 'results.jtl')
96
+ ```
97
+
98
+ ### Running a JMeter Test Plan on flood.io
99
+
100
+ You can also execute JMeter test plans on flood.io using our API. To do so, you require an account and API token. If you don't know your token, sign in to [flood.io](https://flood.io/api) and check your account settings.
101
+
102
+ To execute the test on flood.io, call the `grid` method on the test and pass it the API token like this.
103
+
104
+ ```ruby
105
+ test do
106
+ threads count: 10 do
107
+ visit name: 'Google Search', url: 'http://google.com'
108
+ end
109
+ end.grid('OxtZ-4v-v0koSz5Y0enEQQ')
110
+ ```
111
+
112
+ This will then provide you with a link to the live test results on flood.io like this.
113
+
114
+ ```
115
+ Results at: http://prod.flood.io/shared?testguid=73608030311611e2962f123141011033&run_id=339&tags=jmeter&domain=altentee.com&cluster=54.251.48.129&status=running&view=
116
+ ```
117
+
118
+ ## Advanced Usage
119
+
120
+ ### Blocks
121
+
122
+ Each of the methods take an optional block delimited by `do` and `end` or braces `{}`
123
+
124
+ Blocks let you nest methods within methods, so you can scope the execution of methods as you would in a normal JMeter test plan. For example.
125
+
126
+ ```ruby
127
+ test do
128
+ threads count: 100 do
129
+ visit name: 'Home', url: 'http://altentee.com' do
130
+ extract regex: "content='(.+?)' name='csrf-token'", name: 'csrf-token'
131
+ end
132
+ end
133
+ end
134
+ ```
135
+
136
+ This would create a new test plan, with a 100 user thread group, each user visiting the "Home" page and extracting the CSRF token from the response of each visit.
137
+
138
+ All methods are nestable, but you should only have one test method, and typically only one threads method. For example, it wouldn't make sense to have a test plan within a test plan, or a thread group within a thread group. You can have multiple thread groups per test plan though. This implies *some* knowlege of how JMeter works.
139
+
140
+ All methods take a parameter hash to configure related options.
141
+
142
+ ### Threads
143
+
144
+ You can use the `threads` method to define a group of users:
145
+
146
+ ```ruby
147
+ threads count: 100
148
+ threads count: 100, continue_forever: true
149
+ threads count: 100, loops: 10
150
+ threads count: 100, ramup: 30, duration: 60
151
+ threads count: 100, scheduler: true,
152
+ start_time: Time.now.to_i * 1000,
153
+ end_time: (Time.now.to_i * 1000) + (3600 * 1000)
154
+ ```
155
+
156
+ ### Cookies
157
+
158
+ You can use the `cookies` method to define a Cookie Manager:
159
+
160
+ ```ruby
161
+ test do
162
+ cookies
163
+ end
164
+ ```
165
+
166
+ This methods takes an optional parameters hash. This is based on the [HTTP Cookie Manager](http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Cookie_Manager).
167
+
168
+ ```ruby
169
+ test do
170
+ cookies clear_each_iteration: false
171
+ end
172
+
173
+ test do
174
+ cookies policy: 'rfc2109', clear_each_iteration: true
175
+ end
176
+ ```
177
+
178
+ ### Cache
179
+
180
+ You can use the `cache` method to define a Cache Manager:
181
+
182
+ ```ruby
183
+ test do
184
+ cache
185
+ end
186
+ ```
187
+
188
+ This methods takes an optional parameters hash. This is based on the [HTTP Cache Manager](http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Cache_Manager).
189
+
190
+ ```ruby
191
+ test do
192
+ cache clear_each_iteration: false
193
+ end
194
+
195
+ test do
196
+ cache use_expires: true, clear_each_iteration: true
197
+ end
198
+ ```
199
+
200
+ ### Authorization
201
+
202
+ You can use the `auth` method to define an Authorization Manager:
203
+
204
+ ```ruby
205
+ test do
206
+ auth
207
+ end
208
+ ```
209
+
210
+ This methods takes an optional parameters hash. This is based on the [HTTP Authorization Manager](http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Authorization_Manager).
211
+
212
+ ```ruby
213
+ test do
214
+ auth url: '/', username: 'tim', password: 'secret', domain: 'altentee.com'
215
+ end
216
+ ```
217
+
218
+ ### Navigating
219
+
220
+ You can use the `visit` method to navigate to pages:
221
+
222
+ ```ruby
223
+ visit name: 'Google Search', url: 'http://google.com'
224
+ visit name: 'Google Search', url: 'http://google.com'
225
+ visit name: 'Google Search', url: 'http://google.com',
226
+ method: 'POST',
227
+ 'DO_MULTIPART_POST': 'true'
228
+ visit name: 'Google Search', url: 'http://google.com',
229
+ use_keepalive: 'false'
230
+ visit name: 'Google Search', url: 'http://google.com',
231
+ connect_timeout: '1000',
232
+ response_timeout: '60000'
233
+ visit name: 'View Login', url: '/login',
234
+ protocol: "https",
235
+ port: 443
236
+ ```
237
+
238
+ ### Submitting a Form
239
+
240
+ You can use the `submit` method to POST a HTTP form:
241
+
242
+ ```ruby
243
+ submit name: 'Submit Form', url: 'http://altentee.com/',
244
+ fill_in: {
245
+ username: 'tim',
246
+ password: 'password',
247
+ 'csrf-token' => '${csrf-token}'
248
+ }
249
+ ```
250
+
251
+ This method makes a single request. The fill_in parameter lets you specify key/value pairs for form field parameters. You can also use the built in JMeter `${expression}` language to access run time variables extracted from previous responses.
252
+
253
+ ### Think Time
254
+
255
+ You can use the `think_time` method to insert pauses into the simulation. This method is aliased as `random_timer`.
256
+
257
+ ```ruby
258
+ think_time 3000
259
+ ```
260
+
261
+ This method takes 2 parameters: the constant delay, and an optional variable delay. Both are specified in milliseconds. This is based on the [Gaussian Random Timer](http://jmeter.apache.org/usermanual/component_reference.html#Gaussian_Random_Timer). This timer pauses each thread request for a random amount of time, with most of the time intervals ocurring near a particular value. The total delay is the sum of the Gaussian distributed value (with mean 0.0 and standard deviation 1.0) times the deviation value you specify, and the offset value.
262
+
263
+ ```ruby
264
+ # constant delay of 3 seconds
265
+ think_time 3000
266
+ # constant delay of 1 seconds with variance up to 6 seconds.
267
+ random_timer 1000,5000
268
+ ```
269
+
270
+ ### Response Extractor
271
+
272
+ You can use the `extract` method to extract values from a server response using a regular expression. This is aliased as the `web_reg_save_param` method. This method is typically used inside a `visit` or `submit` block.
273
+
274
+ ```ruby
275
+ extract regex: "content='(.+?)' name='csrf-token'", name: 'csrf-token'
276
+
277
+ visit name: 'Google', url: "http://google.com/" do
278
+ extract regex: 'aria-label="(.+?)"', name: 'button_text'
279
+ extract xpath: '//button', name: 'button'
280
+ end
281
+ ```
282
+
283
+ This is based on the [Regular Expression Extractor](http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor) and [XPath Extractor](http://jmeter.apache.org/usermanual/component_reference.html#XPath_Extractor)
284
+
285
+ ```ruby
286
+ visit name: "Altentee", url: "http://altentee.com" do
287
+ extract regex: "content='(.+?)' name='csrf-token'", name: 'csrf-token'
288
+ extract regex: 'value="(.+?)" name="JESSIONSID"', name: 'JSESSIONID'
289
+ web_reg_save_param regex: 'value="(.+?)" name="VIEWSTATE"', name: 'VIEWSTATE'
290
+ extract name: 'username', regex: 'value="(.+?)", name="username"',
291
+ default: 'Tim Koopmans',
292
+ match_number: 1
293
+ extract name: 'shopping_item', regex: 'id="(.+?)" name="book"',
294
+ match_number: 0 # random
295
+ end
296
+ ```
297
+
298
+ ### Response Assertion
299
+
300
+ You can use the `assert` method to extract values from a server response using a regular expression. This is aliased as the `web_reg_find` method. This method is typically used inside a `visit` or `submit` block.
301
+
302
+ ```ruby
303
+ visit "Altentee", "http://altentee.com" do
304
+ assert contains: "We test, tune and secure your site"
305
+ end
306
+ ```
307
+
308
+
309
+ This method takes 3 parameters: the matching rule, the test string, and an optional parameters hash. This is based on the [Response Assertion](http://jmeter.apache.org/usermanual/component_reference.html#Response_Assertion).
310
+
311
+ ```ruby
312
+ visit "Altentee", "http://altentee.com" do
313
+ assert "contains": "We test, tune and secure your site"
314
+ assert "not-contains": "We price gouge on cloud services"
315
+ assert "matches": "genius"
316
+ assert "not-matches": "fakers"
317
+ assert "contains": "magic"
318
+ assert "not-contains": "unicorns", scope: 'all'
319
+ end
320
+ ```
321
+
322
+ ## Roadmap
323
+
324
+ This is very much a work-in-progress. Future work is being sponsored by flood.io. Get in touch with us if you'd like to be involved.
325
+
326
+ ## Contributing
327
+
328
+ 1. Fork it
329
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
330
+ 3. Create some specs, make them pass
331
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
332
+ 5. Push to the branch (`git push origin my-new-feature`)
333
+ 6. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => [:spec]
data/bin/grid ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'ruby-jmeter'
5
+
6
+ def usage(why = nil)
7
+ puts "failed for reason: #{why}" if why
8
+ puts "usage: grid [testplan.rb] "
9
+ puts " The tesplan is optional, if you leave it off you'll get an interactive shell."
10
+ exit(1)
11
+ end
12
+
13
+ @testplan = ARGV.shift
14
+
15
+ require 'irb'
16
+ require 'irb/completion'
17
+
18
+ if File.exists? ".irbrc"
19
+ ENV['IRBRC'] = ".irbrc"
20
+ end
21
+
22
+ ARGV.clear
23
+
24
+ IRB.start
25
+ exit!