gridinit-jmeter 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Tired of using the JMeter GUI or looking at hairy XML files?
4
4
 
5
- This gem lets you write test plans for JMeter in your favourite text editor, and optionally run them on [Gridinit.com](http://gridinit.com). Here's some background on [why we think](http://www.slideshare.net/90kts/gridinit-jmeter) a DSL is necessary.
5
+ This gem lets you write test plans for JMeter in your favourite text editor, and optionally run them on [Gridinit.com](http://gridinit.com). Here's some background on [why we think](http://www.slideshare.net/90kts/gridinit-jmeter) a DSL is necessary. Don't have Ruby? No problems, you can try out this DSL online in our [sandbox](http://sandbox.gridinit.com)
6
6
 
7
7
  ## Installation
8
8
 
@@ -39,6 +39,6 @@ test do
39
39
 
40
40
  end
41
41
 
42
- # end.jmx
42
+ end.jmx
43
43
  # end.run(path: '/usr/share/jmeter/bin/')
44
- end.grid '4dy-zJLEIgpYkKe6p6JhSQ', { endpoint: endpoint }
44
+ # end.grid '4dy-zJLEIgpYkKe6p6JhSQ', { endpoint: endpoint }
@@ -0,0 +1,64 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'gridinit-jmeter'
3
+
4
+ test do
5
+
6
+ defaults domain: 'www.etsy.com'
7
+
8
+ cache clear_each_iteration: true
9
+
10
+ cookies
11
+
12
+ threads 1, {loops: 10} do
13
+
14
+ random_timer 1000, 3000
15
+
16
+ transaction '01_etsy_home' do
17
+ visit 'home', 'http://www.etsy.com/' do
18
+ assert 'contains', 'Etsy - Your place to buy and sell all things handmade, vintage, and supplies'
19
+ end
20
+ end
21
+
22
+ once do
23
+ transaction '02_etsy_signin' do
24
+ submit 'signin', 'https://www.etsy.com/signin', {
25
+ fill_in: {
26
+ username: 'tim.koops@gmail.com',
27
+ password: ARGV[0],
28
+ persistent: 1,
29
+ from_page: 'http://www.etsy.com/',
30
+ from_action: '',
31
+ from_overlay: 1
32
+ }
33
+ } do
34
+ assert 'contains', 'Tim'
35
+ extract 'random_category', 'a href="(/browse.+?)"'
36
+ end
37
+ end
38
+ end
39
+
40
+ exists 'random_category' do
41
+
42
+ transaction '03_etsy_browse_random_category' do
43
+ visit 'browse', '${random_category}' do
44
+ extract 'random_sub_category', 'a href="(http.+?subcat.+?)"'
45
+ end
46
+ end
47
+
48
+ transaction '04_etsy_browse_random_sub_category' do
49
+ visit 'browse', '${random_sub_category}' do
50
+ extract 'random_listing', 'a href="(/listing.+?)"'
51
+ end
52
+ end
53
+
54
+ transaction '05_etsy_view_random_listing' do
55
+ visit 'view', '${random_listing}'
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end.grid ARGV[1]
63
+ # end.jmx
64
+ # end.run(path: '/usr/share/jmeter/bin/')
@@ -9,11 +9,14 @@ require 'gridinit-jmeter/logger-colors'
9
9
  require 'gridinit-jmeter/strip-heredoc'
10
10
  require 'gridinit-jmeter/version'
11
11
  require 'gridinit-jmeter/test_plan'
12
+ require 'gridinit-jmeter/request_defaults'
12
13
  require 'gridinit-jmeter/auth_manager'
13
14
  require 'gridinit-jmeter/cookie_manager'
14
15
  require 'gridinit-jmeter/cache_manager'
15
16
  require 'gridinit-jmeter/thread_group'
16
17
  require 'gridinit-jmeter/transaction'
18
+ require 'gridinit-jmeter/once_only'
19
+ require 'gridinit-jmeter/if_controller'
17
20
  require 'gridinit-jmeter/http_sampler'
18
21
  require 'gridinit-jmeter/regex_extractor'
19
22
  require 'gridinit-jmeter/user_defined_variable'
@@ -38,51 +38,70 @@ module Gridinit
38
38
 
39
39
  def variables(params={}, &block)
40
40
  node = Gridinit::Jmeter::UserDefinedVariable.new(params)
41
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
41
+ last_node_from(caller) << node.doc.children << hash_tree
42
+ self.instance_exec(&block) if block
43
+ end
44
+
45
+ def defaults(params={}, &block)
46
+ node = Gridinit::Jmeter::RequestDefaults.new(params)
47
+ last_node_from(caller) << node.doc.children << hash_tree
42
48
  self.instance_exec(&block) if block
43
49
  end
44
50
 
45
51
  def cookies(params={}, &block)
46
52
  node = Gridinit::Jmeter::CookieManager.new(params)
47
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
53
+ last_node_from(caller) << node.doc.children << hash_tree
48
54
  self.instance_exec(&block) if block
49
55
  end
50
56
 
51
57
  def cache(params={}, &block)
52
58
  node = Gridinit::Jmeter::CacheManager.new(params)
53
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
59
+ last_node_from(caller) << node.doc.children << hash_tree
54
60
  self.instance_exec(&block) if block
55
61
  end
56
62
 
57
63
  def auth(params={}, &block)
58
64
  node = Gridinit::Jmeter::AuthManager.new(params)
59
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
65
+ last_node_from(caller) << node.doc.children << hash_tree
60
66
  self.instance_exec(&block) if block
61
67
  end
62
68
 
63
69
  def threads(num_threads=1, params={}, &block)
64
70
  node = Gridinit::Jmeter::ThreadGroup.new(num_threads, params)
65
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
71
+ last_node_from(caller) << node.doc.children << hash_tree
66
72
  self.instance_exec(&block) if block
67
73
  end
68
74
 
69
75
  def transaction(name="Transaction Contoller", params={}, &block)
70
76
  node = Gridinit::Jmeter::Transaction.new(name, params)
71
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
77
+ last_node_from(caller) << node.doc.children << hash_tree
78
+ self.instance_exec(&block) if block
79
+ end
80
+
81
+ def exists(var, params={}, &block)
82
+ params[:condition] = "'${#{var}}'.length > 0"
83
+ node = Gridinit::Jmeter::IfController.new("if #{var}", params)
84
+ last_node_from(caller) << node.doc.children << hash_tree
85
+ self.instance_exec(&block) if block
86
+ end
87
+
88
+ def once(name="do once", params={}, &block)
89
+ node = Gridinit::Jmeter::OnceOnly.new(name, params)
90
+ last_node_from(caller) << node.doc.children << hash_tree
72
91
  self.instance_exec(&block) if block
73
92
  end
74
93
 
75
94
  def visit(name="HTTP Request", url="", params={}, &block)
76
95
  params[:method] = 'GET'
77
96
  node = Gridinit::Jmeter::HttpSampler.new(name, url, params)
78
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
97
+ last_node_from(caller) << node.doc.children << hash_tree
79
98
  self.instance_exec(&block) if block
80
99
  end
81
100
 
82
101
  def submit(name="HTTP Request", url="", params={}, &block)
83
102
  params[:method] = 'POST'
84
103
  node = Gridinit::Jmeter::HttpSampler.new(name, url, params)
85
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
104
+ last_node_from(caller) << node.doc.children << hash_tree
86
105
  self.instance_exec(&block) if block
87
106
  end
88
107
 
@@ -90,7 +109,7 @@ module Gridinit
90
109
 
91
110
  def extract(name="", regex="", params={}, &block)
92
111
  node = Gridinit::Jmeter::RegexExtractor.new(name, regex, params)
93
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
112
+ last_node_from(caller) << node.doc.children << hash_tree
94
113
  self.instance_exec(&block) if block
95
114
  end
96
115
 
@@ -98,7 +117,7 @@ module Gridinit
98
117
 
99
118
  def random_timer(delay=0, range=0, &block)
100
119
  node = Gridinit::Jmeter::GaussianRandomTimer.new(delay, range)
101
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
120
+ last_node_from(caller) << node.doc.children << hash_tree
102
121
  self.instance_exec(&block) if block
103
122
  end
104
123
 
@@ -106,7 +125,7 @@ module Gridinit
106
125
 
107
126
  def assert(match="contains", pattern="", params={}, &block)
108
127
  node = Gridinit::Jmeter::ResponseAssertion.new(match, pattern, params)
109
- @root.at_xpath(xpath_from(caller)) << node.doc.children << hash_tree
128
+ last_node_from(caller) << node.doc.children << hash_tree
110
129
  self.instance_exec(&block) if block
111
130
  end
112
131
 
@@ -155,20 +174,30 @@ module Gridinit
155
174
  Nokogiri::XML::Node.new("hashTree", @root)
156
175
  end
157
176
 
177
+ def last_node_from(calling_method)
178
+ xpath = xpath_from(calling_method)
179
+ node = @root.xpath(xpath).last
180
+ node
181
+ end
182
+
158
183
  def xpath_from(calling_method)
159
184
  case calling_method.grep(/dsl/)[1][/`.*'/][1..-2]
160
185
  when 'threads'
161
- '//ThreadGroup[last()]/following-sibling::hashTree'
186
+ '//ThreadGroup/following-sibling::hashTree'
162
187
  when 'transaction'
163
- '//TransactionController[last()]/following-sibling::hashTree'
188
+ '//TransactionController/following-sibling::hashTree'
189
+ when 'once'
190
+ '//OnceOnlyController/following-sibling::hashTree'
191
+ when 'exists'
192
+ '//IfController/following-sibling::hashTree'
164
193
  when 'visit'
165
- '//HTTPSamplerProxy[last()]/following-sibling::hashTree'
194
+ '//HTTPSamplerProxy/following-sibling::hashTree'
166
195
  when 'submit'
167
- '//HTTPSamplerProxy[last()]/following-sibling::hashTree'
196
+ '//HTTPSamplerProxy/following-sibling::hashTree'
168
197
  when 'extract'
169
- '//RegexExtractor[last()]/following-sibling::hashTree'
198
+ '//RegexExtractor/following-sibling::hashTree'
170
199
  when 'random_timer'
171
- '//GaussianRandomTimer[last()]/following-sibling::hashTree'
200
+ '//GaussianRandomTimer/following-sibling::hashTree'
172
201
  else
173
202
  '//TestPlan/following-sibling::hashTree'
174
203
  end
@@ -40,10 +40,15 @@ module Gridinit
40
40
  end
41
41
 
42
42
  def parse_url(url, params)
43
- uri = parse_uri(url)
44
- params[:domain] = uri.host
45
- params[:port] = uri.port
46
- params[:path] = uri.path
43
+ if url[0] == '$'
44
+ params[:path] = url # special case for named expressions
45
+ else
46
+ uri = parse_uri(url)
47
+ params[:protocol] = uri.scheme
48
+ params[:domain] = uri.host
49
+ params[:port] = uri.port
50
+ params[:path] = uri.path
51
+ end
47
52
  end
48
53
 
49
54
  def fill_in(params)
@@ -65,4 +70,4 @@ module Gridinit
65
70
  end
66
71
 
67
72
  end
68
- end
73
+ end
@@ -0,0 +1,21 @@
1
+ module Gridinit
2
+ module Jmeter
3
+
4
+ class IfController
5
+ attr_accessor :doc
6
+ def initialize(name, params={})
7
+ @doc = Nokogiri::XML(<<-EOF.strip_heredoc)
8
+ <IfController guiclass="IfControllerPanel" testclass="IfController" testname="#{name}" enabled="true">
9
+ <stringProp name="IfController.condition">/stringProp>
10
+ <boolProp name="IfController.evaluateAll">false</boolProp>
11
+ </IfController>
12
+ EOF
13
+ params.each do |name, value|
14
+ node = @doc.children.xpath("//*[contains(@name,\"#{name.to_s}\")]")
15
+ node.first.content = value unless node.empty?
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module Gridinit
2
+ module Jmeter
3
+
4
+ class OnceOnly
5
+ attr_accessor :doc
6
+ def initialize(name, params={})
7
+ @doc = Nokogiri::XML(<<-EOF.strip_heredoc)
8
+ <OnceOnlyController guiclass="OnceOnlyControllerGui" testclass="OnceOnlyController" testname="#{name}" enabled="true">
9
+ </OnceOnlyController>
10
+ EOF
11
+ params.each do |name, value|
12
+ node = @doc.children.xpath("//*[contains(@name,\"#{name.to_s}\")]")
13
+ node.first.content = value unless node.empty?
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ module Gridinit
2
+ module Jmeter
3
+
4
+ class RequestDefaults
5
+ attr_accessor :doc
6
+ def initialize(params={})
7
+ @doc = Nokogiri::XML(<<-EOF.strip_heredoc)
8
+ <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true">
9
+ <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
10
+ <collectionProp name="Arguments.arguments"/>
11
+ </elementProp>
12
+ <stringProp name="HTTPSampler.domain"></stringProp>
13
+ <stringProp name="HTTPSampler.port"></stringProp>
14
+ <stringProp name="HTTPSampler.connect_timeout"></stringProp>
15
+ <stringProp name="HTTPSampler.response_timeout"></stringProp>
16
+ <stringProp name="HTTPSampler.protocol"></stringProp>
17
+ <stringProp name="HTTPSampler.contentEncoding"></stringProp>
18
+ <stringProp name="HTTPSampler.path"></stringProp>
19
+ <stringProp name="HTTPSampler.concurrentPool">4</stringProp>
20
+ </ConfigTestElement>
21
+ EOF
22
+ params.each do |name, value|
23
+ node = @doc.children.xpath("//*[contains(@name,\"#{name.to_s}\")]")
24
+ node.first.content = value unless node.empty?
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -6,7 +6,7 @@ module Gridinit
6
6
  def initialize(name, params={})
7
7
  @doc = Nokogiri::XML(<<-EOF.strip_heredoc)
8
8
  <TransactionController guiclass="TransactionControllerGui" testclass="TransactionController" testname="#{name}" enabled="true">
9
- <boolProp name="TransactionController.parent">false</boolProp>
9
+ <boolProp name="TransactionController.parent">true</boolProp>
10
10
  </TransactionController>
11
11
  EOF
12
12
  params.each do |name, value|
@@ -1,5 +1,5 @@
1
1
  module Gridinit
2
2
  module Jmeter
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridinit-jmeter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-26 00:00:00.000000000 Z
12
+ date: 2012-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -73,6 +73,7 @@ files:
73
73
  - examples/basic_testplan.jmx
74
74
  - examples/basic_testplan.rb
75
75
  - examples/basic_think_time.rb
76
+ - examples/etsy_login_browse.rb
76
77
  - gridinit-jmeter.gemspec
77
78
  - lib/gridinit-jmeter.rb
78
79
  - lib/gridinit-jmeter/auth_manager.rb
@@ -82,8 +83,11 @@ files:
82
83
  - lib/gridinit-jmeter/fallback_content_proxy.rb
83
84
  - lib/gridinit-jmeter/gaussian_random_timer.rb
84
85
  - lib/gridinit-jmeter/http_sampler.rb
86
+ - lib/gridinit-jmeter/if_controller.rb
85
87
  - lib/gridinit-jmeter/logger-colors.rb
88
+ - lib/gridinit-jmeter/once_only.rb
86
89
  - lib/gridinit-jmeter/regex_extractor.rb
90
+ - lib/gridinit-jmeter/request_defaults.rb
87
91
  - lib/gridinit-jmeter/response_assertion.rb
88
92
  - lib/gridinit-jmeter/strip-heredoc.rb
89
93
  - lib/gridinit-jmeter/test_plan.rb