gridinit-jmeter 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -239,6 +239,10 @@ visit 'Google Search', 'http://altentee.com', {
239
239
  connect_timeout: '1000',
240
240
  response_timeout: '60000',
241
241
  }
242
+ visit 'View Login', '/login', {
243
+ protocol: "https",
244
+ port: 443
245
+ }
242
246
  ```
243
247
 
244
248
  ### Submitting a Form
@@ -281,7 +285,17 @@ You can use the `extract` method to extract values from a server response using
281
285
  extract 'csrf-token', "content='(.+?)' name='csrf-token'"
282
286
  ```
283
287
 
284
- This method takes 3 parameters: the extracted value name, the PCRE regular expression and an optional parameters hash. This is based on the [Regular Expression Extractor](http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor).
288
+ This method takes 4 parameters: the selector (xpath or regex), the extracted value name, the PCRE regular expression and an optional parameters hash. The selector is optional and defaults to regex. You can specify regex or xpath extractors as follows.
289
+
290
+ ```
291
+ visit 'Google', "http://google.com/" do
292
+ extract 'button_text', 'aria-label="(.+?)"'
293
+ extract :regex, 'button_text', 'aria-label="(.+?)"'
294
+ extract :xpath, 'button', '//button'
295
+ end
296
+ ```
297
+
298
+ 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)
285
299
 
286
300
  ```ruby
287
301
  visit "Altentee", "http://altentee.com" do
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'gridinit-jmeter'
3
+
4
+ test do
5
+
6
+ threads 100 do
7
+
8
+ visit 'Google', "http://google.com/" do
9
+ extract 'button_text', 'aria-label="(.+?)"'
10
+ extract :regex, 'button_text', 'aria-label="(.+?)"'
11
+ extract :xpath, 'button', '//button'
12
+ end
13
+
14
+ end
15
+
16
+ end.jmx
@@ -107,8 +107,15 @@ module Gridinit
107
107
 
108
108
  alias_method :post, :submit
109
109
 
110
- def extract(name="", regex="", params={}, &block)
111
- node = Gridinit::Jmeter::RegexExtractor.new(name, regex, params)
110
+ def extract(*args, &block)
111
+ node = case args.first
112
+ when :regex
113
+ Gridinit::Jmeter::RegexExtractor.new(*args.last(2))
114
+ when :xpath
115
+ Gridinit::Jmeter::XpathExtractor.new(*args.last(2))
116
+ else
117
+ Gridinit::Jmeter::RegexExtractor.new(*args)
118
+ end
112
119
  last_node_from(caller) << node.doc.children << hash_tree
113
120
  self.instance_exec(&block) if block
114
121
  end
@@ -44,10 +44,10 @@ module Gridinit
44
44
  params[:path] = url # special case for named expressions
45
45
  else
46
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
47
+ params[:protocol] ||= uri.scheme
48
+ params[:domain] ||= uri.host
49
+ params[:port] ||= uri.port
50
+ params[:path] ||= uri.path
51
51
  end
52
52
  end
53
53
 
@@ -5,7 +5,7 @@ module Gridinit
5
5
  attr_accessor :doc
6
6
  def initialize(name, regex, params={})
7
7
  @doc = Nokogiri::XML(<<-EOF.strip_heredoc)
8
- <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor" enabled="true">
8
+ <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="#{name}" enabled="true">
9
9
  <stringProp name="RegexExtractor.useHeaders">false</stringProp>
10
10
  <stringProp name="RegexExtractor.refname">#{name}</stringProp>
11
11
  <stringProp name="RegexExtractor.regex">#{CGI.escapeHTML regex}</stringProp>
@@ -1,5 +1,5 @@
1
1
  module Gridinit
2
2
  module Jmeter
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -0,0 +1,25 @@
1
+ module Gridinit
2
+ module Jmeter
3
+
4
+ class XpathExtractor
5
+ attr_accessor :doc
6
+ def initialize(name, xpath, params={})
7
+ @doc = Nokogiri::XML(<<-EOF.strip_heredoc)
8
+ <XPathExtractor guiclass="XPathExtractorGui" testclass="XPathExtractor" testname="#{name}" enabled="true">
9
+ <stringProp name="XPathExtractor.default"></stringProp>
10
+ <stringProp name="XPathExtractor.refname">#{name}</stringProp>
11
+ <stringProp name="XPathExtractor.xpathQuery">#{xpath}</stringProp>
12
+ <boolProp name="XPathExtractor.validate">false</boolProp>
13
+ <boolProp name="XPathExtractor.tolerant">false</boolProp>
14
+ <boolProp name="XPathExtractor.namespace">false</boolProp>
15
+ </XPathExtractor>
16
+ EOF
17
+ params.each do |name, value|
18
+ node = @doc.children.xpath("//*[contains(@name,\"#{name.to_s}\")]")
19
+ node.first.content = value unless node.empty?
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -19,6 +19,7 @@ require 'gridinit-jmeter/once_only'
19
19
  require 'gridinit-jmeter/if_controller'
20
20
  require 'gridinit-jmeter/http_sampler'
21
21
  require 'gridinit-jmeter/regex_extractor'
22
+ require 'gridinit-jmeter/xpath_extractor'
22
23
  require 'gridinit-jmeter/user_defined_variable'
23
24
  require 'gridinit-jmeter/gaussian_random_timer'
24
25
  require 'gridinit-jmeter/response_assertion'
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.4
4
+ version: 0.0.5
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-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -65,6 +65,7 @@ files:
65
65
  - examples/basic_auth.rb
66
66
  - examples/basic_cache.rb
67
67
  - examples/basic_cookies.rb
68
+ - examples/basic_extract.rb
68
69
  - examples/basic_google.rb
69
70
  - examples/basic_grid.rb
70
71
  - examples/basic_proxy.rb
@@ -95,6 +96,7 @@ files:
95
96
  - lib/gridinit-jmeter/transaction.rb
96
97
  - lib/gridinit-jmeter/user_defined_variable.rb
97
98
  - lib/gridinit-jmeter/version.rb
99
+ - lib/gridinit-jmeter/xpath_extractor.rb
98
100
  - spec/dsl_spec.rb
99
101
  - spec/spec_helper.rb
100
102
  - spec/stub.rb