Permalink
Browse files

XML writer now supports URLs with params. Removed flag to exclude tho…

…se URLs.
  • Loading branch information...
1 parent 254f9bc commit 0596fd2a6c5e2f600cf6a931b6bcfd36cb37c36e Mary Cook committed Oct 7, 2009
Showing with 92 additions and 20 deletions.
  1. +4 −2 README
  2. +56 −18 main.rb
  3. 0 1.txt → no_params1.txt
  4. 0 2.txt → no_params2.txt
  5. 0 3.txt → no_params3.txt
  6. +1 −0 params1.txt
  7. +3 −0 params2.txt
  8. +8 −0 params3.txt
  9. +8 −0 params4.txt
  10. +12 −0 params5.txt
View
@@ -8,11 +8,13 @@ By maryrosecook for the OTHER media
----
-Quick run: ruby main.rb "log.log" "urls.txt" "load_test.xml" false
+Quick run: ruby main.rb "log.log" "urls.txt" "load_test.xml"
The script takes four command-line arguments:
- filename for input log file (string, not nil)
- filename for url list (string, or nil to not write file)
- filename for load test xml (string, or nil to not write file)
-- whether to include URLs with params (true/false, not nil)
+
+Note that the script outputs twenty to thirty lines of XML per URL,
+so you might want to limit the log files you feed in to a few hundred unique URLs.
View
@@ -1,9 +1,14 @@
+require 'net/http'
+require 'uri'
+
LOG_FILENAME = ARGV[0]
URL_LIST_FILENAME = ARGV[1]
LOAD_TEST_XML_FILENAME = ARGV[2]
-EXCLUDE_URLS_WITH_QUESTION_MARKS = Boolean(ARGV[3])
-def read_file_to_str(filename)
+PARAMS = "params"
+NO_PARAMS = "no_params"
+
+def read(filename)
str = ""
file = File.new(filename, "r")
while line = file.gets
@@ -13,15 +18,16 @@ def read_file_to_str(filename)
return str
end
-def Boolean(string)
- return true if string == true || string =~ /^true$/i
- return false if string == false || string.nil? || string =~ /^false$/i
- raise ArgumentError.new("invalid value for Boolean: \"#{string}\"")
+def xml_frag(url_type, i)
+ return read(url_type + i.to_s + ".txt")
end
+
if LOG_FILENAME
# get all urls requested in log file
- urls = []
+ urls = {}
+ urls[PARAMS] = []
+ urls[NO_PARAMS] = []
file = File.new(LOG_FILENAME, "r")
i = 0
while line = file.gets
@@ -36,34 +42,64 @@ def Boolean(string)
line = line.gsub(/actionToken=[^\&]*\&/, "&")
line = line.strip
if line && line.length > 0
- urls << line.strip unless EXCLUDE_URLS_WITH_QUESTION_MARKS && line.match(/\?/)
+ line.match(/\?/) ? urls[PARAMS] << line.strip : urls[NO_PARAMS] << line.strip
end
end
i += 1
end
# retain unique urls
- unique_urls = urls.uniq
+ unique_urls = {}
+ for url_type in urls.keys
+ unique_urls[url_type] = urls[url_type].uniq
+ end
# write unique_urls to file
if URL_LIST_FILENAME
File.open(URL_LIST_FILENAME, 'w') do |f|
- for url in unique_urls
- f.write(url + "\n")
+ for url_type in urls.keys
+ for url in urls[url_type]
+ f.write(url + "\n")
+ end
end
end
end
- # put xml pieces into vars
- part_1 = read_file_to_str("1.txt")
- part_2 = read_file_to_str("2.txt")
- part_3 = read_file_to_str("3.txt")
+ # read in xml fragments for the different types of URL
+ no_params1 = xml_frag(NO_PARAMS, 1)
+ no_params2 = xml_frag(NO_PARAMS, 2)
+ no_params3 = xml_frag(NO_PARAMS, 3)
+ params1 = xml_frag(PARAMS, 1)
+ params2 = xml_frag(PARAMS, 2)
+ params3 = xml_frag(PARAMS, 3)
+ params4 = xml_frag(PARAMS, 4)
+ params5 = xml_frag(PARAMS, 5)
# for each url, make a new piece of xml and add it onto xml_str
+ i = 0
xml_str = ""
- for url in unique_urls
- xml_str += part_1 + url + part_2 + url + part_3 + "\n\n"
+ for url_type in urls.keys
+ for url in urls[url_type]
+ if url_type == NO_PARAMS
+ #xml_str += no_params1 + url + no_params2 + url + no_params3 + "\n\n"
+ elsif url_type == PARAMS
+ xml_str += params1 + url + params2
+
+ # add special xml for each param
+ uri = URI.parse(url)
+ for param_pair in uri.query.split("&")
+ name_and_value = param_pair.split("=")
+ param_name = name_and_value[0]
+ param_value = name_and_value[1]
+ xml_str += params3.gsub(/paramname/, param_name.to_s).gsub(/paramvalue/, param_value.to_s)
+ end
+
+ xml_str += params4 + url + params5 + "\n\n"
+ break if i > 20
+ i += 1
+ end
+ end
end
# write xml_str to file
@@ -72,4 +108,6 @@ def Boolean(string)
f.write(xml_str)
end
end
-end
+else
+ puts "You need to specify a log filename."
+end
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1 @@
+<HTTPSampler guiclass="HttpTestSampleGui" testclass="HTTPSampler" testname="
View
@@ -0,0 +1,3 @@
+enabled="true">
+ <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
+ <collectionProp name="Arguments.arguments">
View
@@ -0,0 +1,8 @@
+
+ <elementProp name="paramname" elementType="HTTPArgument">
+ <boolProp name="HTTPArgument.always_encode">false</boolProp>
+ <stringProp name="Argument.value">paramvalue</stringProp>
+ <stringProp name="Argument.metadata">=</stringProp>
+ <boolProp name="HTTPArgument.use_equals">true</boolProp>
+ <stringProp name="Argument.name">id</stringProp>
+ </elementProp>
View
@@ -0,0 +1,8 @@
+
+ </collectionProp>
+ </elementProp>
+ <stringProp name="HTTPSampler.domain"></stringProp>
+ <stringProp name="HTTPSampler.port"></stringProp>
+ <stringProp name="HTTPSampler.protocol"></stringProp>
+ <stringProp name="HTTPSampler.contentEncoding"></stringProp>
+ <stringProp name="HTTPSampler.path">
View
@@ -0,0 +1,12 @@
+</stringProp>
+ <stringProp name="HTTPSampler.method">GET</stringProp>
+ <boolProp name="HTTPSampler.follow_redirects">false</boolProp>
+ <boolProp name="HTTPSampler.auto_redirects">true</boolProp>
+ <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
+ <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
+ <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
+ <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
+ <stringProp name="HTTPSampler.mimetype"></stringProp>
+ <stringProp name="HTTPSampler.monitor">false</stringProp>
+ <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
+</HTTPSampler>

0 comments on commit 0596fd2

Please sign in to comment.