1
votes

I'm using a JMeter (2.13 r1665067) to test a site with Google Kaptcha on log in and registration until they can be disabled in a test environment. I've recorded a session and set up a Save Responses to a file sampler to extract the kaptcha image. I then have a Beanshell sampler display it so I can enter the code as needed (thanks to this post).

The problem I'm running into now is the first image retrieved from the server is displayed repeatedly. I've tried setting any objects created in the Beanshell to null post-use, and checking the "Reset bsh.Interpreter before each call".

I was able to get around to issue by using the $__(Random) function to append a unique id to each image when created in the Save Responses to a file sampler, but results in a lot of files being created. I can verify the saved image file is changing on the filesystem. I can also restart JMeter, or clear the file from the filesystem for it to appear properly, but only the first time. Adding a timestamp via the Save Responses to a file sampler isn't unique enough, but creates additional files anyway.

I'd like to find out why JMeter seems to be caching the images and if there's a way to have a single file written and read each time, avoiding the slew of them I'd get by appending a unique ID. I imagine it has to do with my config.

Beanshell sampler code:

filenameOrURL = new URL("file://${FILE2}");
image = Toolkit.getDefaultToolkit().getImage(filenameOrURL);
icon = new javax.swing.ImageIcon(image);
pane = new JOptionPane("Enter Captcha", 0, 0, null);
String captcha = (String)pane.showInputDialog(null, "Captcha", "Captcha", 0, icon, null,null);
filenameOrURL = image = pane = icon = null;
log.info(captcha);
vars.putObject("captcha",captcha);

Save Responses to a file sampler parameters:

Filename prefix: /response/response_
Variable name: FILE

Thread Group:

I'd post an image if my reputation preceded me. :blush:

  Recording Controller
      login.html (GET)
        Save Responses to a file
      BeanShell Sampler
      login.html (POST)
      logout.html (GET)
1
As an aside, you can try deleting the saved response files in a beanshell postprocessor, once you're done with the captcha, to as to not keep a lot of files by the end of the test.RaGe
@RaGe Thanks, I did consider that, but I wanted to understand the "caching" I'm experiencing, rather than just working around my ignorance.ethesx

1 Answers

1
votes

Your issue is not really with JMeter, but with the Toolkit.getImage() function. From its documentation:

Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG. The underlying toolkit attempts to resolve multiple requests with the same filename to the same returned Image.

Since the mechanism required to facilitate this sharing of Image objects may continue to hold onto images that are no longer in use for an indefinite period of time, developers are encouraged to implement their own caching of images by using the createImage variant wherever available. If the image data contained in the specified file changes, the Image object returned from this method may still contain stale information which was loaded from the file after a prior call. Previously loaded image data can be manually discarded by calling the flush method on the returned Image.