Reputation: 3
I am having trouble parsing Jmeter varibles to OS Process Samplers.
I currently have a beanshell sampler that get the sampleresult of the previous sampler like so:
String uploadResults="";
if(sampleResult.isSuccessful()){
uploadResults = "true";
vars.put("uploadResults", uploadResults);
} else {
uploadResults = "false";
vars.put("uploadResults", uploadResults);
}
I then have an OS Process Sampler that runs a .ps1 script with the following configuration:
Command:
${powershellPath}
Command parameter:powershell.exe -noexit ""& `${shellScriptPath}` '`${loginResults}`' 'Upload'""
My .ps1 script outputs the result like so:
Write-Host "${result}"
When I started the script, the OS Process Sampler returned an output like so when the condition is "false": False result
And like so when the condition is "true": True result
Not sure what is going here, I suspect that is has something to do with the jmeter variable encoding. Any help would be appreciate.
EDIT: Here is the .ps1 code. I have redacted some information but the main functionality is there.
param (
[string]$result,
[string]$transaction,
[string]$eventSource = "JMeterEventSource",
[string]$logName = "Application",
[int]$eventID = 4200
)
# Check if the event source exists, if not, create it
if (-not [System.Diagnostics.EventLog]::SourceExists($eventSource)) {
New-EventLog -LogName $logName -Source $eventSource
}
if($result -eq "false"){
switch ($transaction) {
"Upload" { $eventMessage = "FunctionalTransactions Script - upload-verification Sampler - The transaction ${transaction} is unavailable"
$eventType = "Error"
$eventID = 4211
}
"Login" { $eventMessage = "FunctionalTransactions Script - login-verification Sampler - The transaction ${transaction} is unavailable"
$eventType = "Error"
$eventID = 4211
}
}
}
else {
switch ($transaction) {
"Upload" { $eventMessage = "FunctionalTransactions Script - upload-verification Sampler - The transaction ${transaction} is available"
$eventType = "Information"
$eventID = 4210
}
"Login" { $eventMessage = "FunctionalTransactions Script - login-verification Sampler - The transaction ${transaction} is available"
$eventType = "Information"
$eventID = 4210
}
}
}
# Write the event to the log
Write-EventLog -LogName $logName -Source $eventSource -EntryType $eventType -EventID $eventID -Message $eventMessage
Write-Host "${result}"
Upvotes: 0
Views: 55
Reputation: 2872
I cannot reproduce your issue using the following OS Process Sampler configuration:
and the following Powershell script:
Write-Host "Result is: "$args[0]
So I guess nothing is wrong with "encoding" of JMeter Variables, you should take a closer look into your powershell script and the way you're handling the variables there.
So far I can only give you one piece of advice: using Beanshell is some form of a performance anti-pattern, consider switching to JSR223 Test Elements and Groovy language. See Apache Groovy: What Is Groovy Used For? article for more details.
Upvotes: 1