JMeter Beanshell sampler caches image - jmeter

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)

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.

Related

Outlook.MailItem.DownloadState What it is and what it is used for?

I have seen the property Outlook.MailItem.DownloadState which is explained here.
Anyway I am not able to understand what is it and what is it used for. Some can explain me that?
To decrease the capacity of the local storage and save the bandwidth users may not download large emails getting only a small subset of data (metadata) which contains the headers describing the email.
There are possible states for the MailItem.DownloadState property:
The olHeaderOnly means only the header has been downloaded.
The olFullItem value means the full item has been downloaded.
If the message was not fully downloaded in Outlook you can set the MailItem.MarkForDownload property. It returns or sets an OlRemoteStatus constant that determines the status of an item once it is received by a remote user.
if(obj.DownloadState == olHeaderOnly)
{
'Mark the item to be downloaded
obj.MarkForDownload = olMarkedForDownload;
}
Outlook has header-only mode when it downloads headers first and full item (body and attachment) only when the message is selected - see https://www.officetooltips.com/outlook_2016/tips/how_to_set_outlook_to_download_only_e-mail_headers.html

How to save response for particle users in output folder in JMeter

I created one thread group which has 25 users and a total of 3 samplers.
Here I used ${__threadNum} function to saw which user currently running. here request was not sequentially run. and for saving response/output I used listener 'Save Responses to a file' Here I also used counter to save every user outputs separately but problem is that when we check in output folder the saved output and response showed in the Response body are different actually this output is for another user .. so how to create a setup for every user where response and saved output is same
If you do something like:
textual version just in case:
outputFolder/response-for-user-${__threadNum}-iteration-${__jm__Thread Group__idx}.txt
and run your test with 2 users and 2 iterations you will see the following files generated under the outputFolder (it will be created in "bin" folder of your JMeter installation)
response-for-user-1-iteration-0.txt
response-for-user-1-iteration-1.txt
response-for-user-2-iteration-0.txt
response-for-user-2-iteration-1.txt
Also be aware that it's possible to amend JMeter's Results File Configuration so all the request and response details will be written to .jtl results file, add the next lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.requestHeaders=true
jmeter.save.saveservice.responseHeaders=true
jmeter.save.saveservice.url=true
or alternatively you can save the request and response data by using any Listener, example setup:
More information: How to Save Response Data in JMeter

SAP Script Recording and Playback - Cumulative data

If I am using the Script Recording and Playback feature on same transaction for instance ME25, multiple times, I am getting cumulative data as part of multiple scripts rather than incremental data.
Explanation :
If I open ME25 details and enter "100-310" as Material and "Ball Bearing" as Short Text and stop the recording, I get the following script, which is expected behavior.
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/ctxtEBAN-MATNR[3,0]").text = "100-310"
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/txtEBAN-TXZ01[4,0]").text = "Ball Bearing"
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/txtEBAN-TXZ01[4,0]").setFocus
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/txtEBAN-TXZ01[4,0]").caretPosition = 12
After this, I restart the recording and type Qty Requested as "100" and delivery date as "21.04.2021" and stop the recording. I get the following script:
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/ctxtEBAN-MATNR[3,0]").text = "100-310"
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/txtEBAN-TXZ01[4,0]").text = "Ball Bearing"
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/txtEBAN-MENGE[5,0]").text = "100"
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/ctxtRM06B-EEIND[8,0]").text = "21.04.2021"
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/ctxtEBAN-EKGRP[9,0]").setFocus
session.findById("wnd[0]/usr/tblSAPMM06BTC_0106/ctxtEBAN-EKGRP[9,0]").caretPosition = 0
Instead of getting the incremental part that I typed for the second recording instance, I am getting complete script. Is there a way to achieve incremental scripts?
I can reproduce in my SAP GUI 7.60 (whatever screen it is; whatever kind of field it is, I can reproduce even with very simple fields like in a Selection Screen).
It seems that it happens all the time, even if you write your own recorder (a VBS script which mainly uses session.record = True + event handlers). It's due to the fact that SAP GUI sends all the screen events (i.e. the user actions) since the screen was entered, when the user presses a button, a function key, closes a window, or stops the SAP GUI Recorder.
If you write your own recorder, I guess you can save the screen contents when you start the recorder, and when the "change" events occur you may ignore those ones where the new field value has not changed since the recorder started. But that's a lot of work.
I think that it's far more easy to append manually the last lines of the last script to the initial script.

Regarding WebDriver Sampler and Config/Listener Folder Path

While trying to write Webdriver sampler with Config/listener element ,I have below issue ,Could any team assist me for the same?
1:- In config /listener element/webdriver browser setup file , if we want to enter some value from external resource (' or if we want to save summary report in PC, Is there any procedure to give unique path that can be run in any workstation /pc/ any directory after giving file name only because if we execute in other station or move file in other directory, everytime we need to change file location?Could you please guide me for the same?
While writing webdriver sampler request,I am able to execute script but i am getting below error in log viewer window and also wanted to break functionality as very small unit label for one webdriver sampler request{launch site/login successfully,validate record, logout} so after searching on google , i used sub sample start or samplestart function multiple time , but i am not getting label name in view tree listener result after setting one jmeter property. Could you please guide me for the same?
3:- Could we run three thread group at same time(all three thread run at same time) or some interval (first and sec run on same time but third start after 10 minute)
Thanks you for giving valuable time in advance?
Thanks Amit
You can give only the filename and JMeter will look for the CSV file and write results file into JMeter's "bin" folder (or the place where you launched JMeter from). You can also use __P() function to parameterize the file name or even path, for example if you do set your CSV Data Set Config like:
${__P(testdata,TestData.csv)}
you will be able to override the path using -J command-line argument like:
jmeter -Jtestdata=/path/to/somefile.csv
If you don't provide the property, default value of TestData.csv will be used. More information: Apache JMeter Properties Customization Guide
You're getting this "Invalid call sequence" error because you have duplicate WDS.sampleResult.sampleStart() function call, just remove one of them and that would be it.
Add a Constant Timer as a child of the first request or Flow Control Action sampler at the beginning of the Thread Group 3 and configure them to sleep for 600000 milliseconds.

JMeter - Hitting specific endpoints based on user credentials via multiple CSV files

My JMeter test:
Iterate over a CSV file (logins.csv) with login credentials, and their unique identifier user a CsvDataSetConfig
Sign in
Based on the login credentials (unique identifier from logins.csv), identify and load a second file in the format of <user_identifier>_invoices.csv which then has the necessary path to view an invoice for that user.
Simplified test setup:
ThreadGroup
> CsvDataSetConfig - file: logins.csv, variables: user_identifier,email,password, sharing_mode: all threads
> `SignIn` TransactionController using email and password from above CSV file to login via series of HTTP Requests
> UserParameters - USER_IDENTIFIER,INVOICE_CSV_FOR_USER
> BeanShellSampler
props.setProperty("USER_IDENTIFIER", vars.get("user_identifier"));
props.setProperty("INVOICE_CSV_FOR_USER","${__P(USER_IDENTIFIER)}_invoices.csv");
> WhileController - condition: ${__javaScript("${invoice-id}" != "<EOF>",)}
> CsvDataSetConfig - file: ${__P(INVOICE_CSV_FOR_USER,)}, variables: invoice-id, sharing_mode: current thread
> `ViewInvoice` TransactionController with HTTP Request to url `../${invoice-id}`
# logins.csv
c7beaa99c6d99fa7754fc2213f9b17b8,foo#example.com,password321
9c8466bee65e39c9d3cf715e42933c3b,bar#example.com,password456
# c7beaa99c6d99fa7754fc2213f9b17b8_invoices.csv
f54eca1cbbba4a97c1dc459e0ba64970
0024f2cdf28dd7ebf3606988fd229afd
# 9c8466bee65e39c9d3cf715e42933c3b_invoices.csv
64f725fdeb2980b28bdf5e02076a55cd
60ac45a12ea3d6b59c2cb82f27da1722
Problem:
In local JMeter, seeing requests to invoice urls being made with incorrect invoice-id for the business. So seems the parameters are not being treat correctly between threads.
In BlazeMeter, seeing the content of the while controller never being hit.
I've tried loop controllers, having 50 rows per _invoices.csv file, but not got anywhere with that either. I also originally started off with
User Defined Variables rather than User Parameters, but the latter seems to be what I should be using for this use case.
Threads are running at the same time and sharing JMeter properties.
In your test plan each thread sets the property USER_IDENTIFIER. So this and other property can/will be overriden by different thread(s) and create inconsistency.
I suggest you save (and get) in variables which aren't shared by threads:
vars.put("USER_IDENTIFIER", vars.get("user_identifier"));
vars.put("INVOICE_CSV_FOR_USER"," ${USER_IDENTIFIER}_invoices.csv");
Also about beanshell, JMeter advice to change to JSR223
Since JMeter 3.1, we advise switching from BeanShell to JSR223 Test Elements (see JSR223 section below for more details), and switching from __Beanshell function to __groovy function.

Resources