jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Ide <flyingrhenqu...@gmail.com>
Subject Re: search-and-replace in binary AMF3 POST data
Date Mon, 25 Apr 2011 22:22:26 GMT
My example is in groovy. To see if groovy works for you, write a test with a
"View results tree" listener and a BSF sampler with the scripting language
set to "groovy" and the line:

SampleResult.setResponseData("Hello World");

in it. If it works when you run the script  you're good to go. Otherwise if
you want to use groovy to do this, you need to install groovy first. The
instructions at
http://jroller.com/isaaclevin/entry/using_groovy_in_jmeterare what I
used to set jmeter up for this.

Once you've verified that groovy works, reading and writing files is quite
easy. If you create a test file named "C:\test_file" and put in it "This is
a test file" and then create a jmeter test with a BSF sampler that has the
following script in it, a new_test_file should be created with "this is a
blarg file" in it:

String filebytes = new File("C:/test_file").text.replace("test", "blarg");
new File("C:/new_test_file").write(filebytes);
SampleResult.setResponseData(filebytes);

Now the methods in this example _may_ fail, depending on just _how_ binary
your file is, but I think if perl can read it, groovy should be able as
well! If this has trouble, something more advanced may be called for.

Since Groovy is Java (more or less), the "replace" method on the first line
takes a regexp. So you could put your session-id-recognizing regexp as the
first parameter and "${DSid}" as your second parameter and that should work,
assuming the session ID is recognizable in the file. I believe you said you
were already doing this with perl, which is the foundation of my optimism
that this will simply work.

If you need to actually decode the file and then re-encode it, that's beyond
the scope of this particular example.

If you don't want to clobber your template file, I suggest you follow my
example and write a new file which you can then post. If you have many
sessions going at once, you may be able to write the session ID as part of
the new file name (BSF samplers do jmeter variable substitution) and then
post the file with the session ID in your HTTP client request. I'm not sure
if HTTP client requests do variable substitution in the file name field, but
most samplers do so again I'm optimistic that will work.

There are a lot of "ifs" in here, but that's what makes testing fun, isn't
it?

-- 
Bruce Ide
FlyingRhenquest@gmail.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message