When I am trying to execute my created script on another system then it's throwing this error like "Displaying DigestEncodeFunction Error in JMeter". PFA Screenshot for the same.enter image description here
Please don't post jmeter.log file in form of a screenshot
You forgot to include your __digest() function call itself
The first problem is that you're using wrong algorithm name, it should be SHA-256, for possible algorithms check out Algorithms section of MessageDigest class JavaDoc
Just in case here how it looks now for Java 8:
If you have troubles when it comes to coming up with proper JMeter Function syntax - go for the Functions Helper Dialog
Here is the function which generates SHA-256 hash of string foo using bar as the salt:
${__digest(SHA-256,foo,bar,,)}
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
Related
I am new to the beanshell scripting.So my query might have basic syntactical issue.
I am getting "DocConnectionId" from regular expression extractor which is the number of elements in app screen. I have GetNewReferralId which the variablevalue i want to match with DocConnectionId.
I have written the below code:
int DocConnectionId = Integer.parseInt(vars.get("connectionIDWithDoc_matchNr"));
int GetNewReferralId = Integer.parseInt(vars.get("GetNewReferral"));
for(int i = 1;i<=DocConnectionId;i++)
{
if(GetNewReferralId.equals(vars.get("connectionIDWithDoc_"+i))){
Integer.parseInt(vars.put("ConnectionWithDoc"));
break;
}
}
But I am getting the below error in error log.
jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``int DocConnectionId = Integer.parseInt(vars.get("connectionIDWithDoc_matchNr")); . . . '' : Typed variable declaration : Method Invocation Integer.parseInt
Integer.parseInt(vars.put("ConnectionWithDoc"));
This line is wrong, and is guaranteed to generate a Integer parse exception. vars.put returns void value, so you're effectively trying to parse an integer from void, which will throw an exception.
I cant really tell from your code, but are you trying to store the value of i in variable ConenctionWithDoc? In which case, you should do:
vars.put("ConnectionWithDoc", Integer.toString(i));
Most probably connectionIDWithDoc_matchNr is not defined or you made a mistake in its case.
Could you show you full test plan.
Your code does not make a lot of sense, try elaborating what needs to be done so we could come up with more elegant solution in explanations.
Till that time here is a piece of advice:
If you add debug(); line at the very beginning of your Beanshell script - you'll get extra debug output to STDOUT (console, where you launched JMeter from)
If you surround your code in try/catch block like:
try {
//your code here
}
catch (Throwable ex) {
log.error("Error in script", ex);
}
you'll be able to see more readable and understandable stacktrace in jmeter.log file (usually being generated in the folder, you launch JMeter form)
Familiarize yourself with JMeter API w.r.t. classes you're targeting to use. Copy-pasting from stackoverflow without understanding what does the code do can lead to undefined results
See How to Use BeanShell: JMeter's Favorite Built-in Component article for a little bit more detailed explanations and several real-life examples of using Beanshell in JMeter test scripts.
How do I want to generate a hash using beanshell(SHA1) in JMeter to sign up to a application?
I'm not able to get a substantial answer yet from net
Generating a hash is pretty easy, just use DigestUtils class from Apache Commons Codec library (it's a part of JMeter so you won't need to install anything external)
Something like:
import org.apache.commons.codec.digest.DigestUtils;
String foo = "bar";
String sha1Hex = DigestUtils.sha1Hex(foo);
Usually SHA1 is being required for signing requests to OAuth-protected applications, if it is your case, I believe How to Run Performance Tests on OAuth Secured Apps with JMeter will be extremely helpful.
There's a new JMeter function __digest, currently in nightly builds which can be used to encode strings
In your case to save in sha1Value variable the result of myVar variable use the following:
${__digest(SHA-1,${myVar},,,sha1Value)}
4th parameter is uppercase, so you can send true to automatically uppercase it.
I am using javascript for cucumber javascript for automation.My concern is can i generate .js file for step definitions automatically? as of now am copy pasting them(steps) from command line window so can I skip it and directly generate the step file?
Two Suggestions:
1.
You can create a new gherkin file, and run it with cucumber.js, it will generate JavaScript stub automatically for you. For example:
"cucumber-js math.feature"
It will output something like:
1) Scenario: easy maths - math.feature:7
Step: Given a variable set to 1 - math.feature:8
Message:
Undefined. Implement with the following snippet:
this.Given(/^a variable set to (\d+)$/, function (arg1, callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
It has the parameter automatically generated based on your tests. You can then copy the snippet into your code file.
2.
If you are using Windows 10, you can also try a BDD development tool CukeTest, and it provide some convenient features like code generation from step text, or navigate between code and steps etc.
You can use 'Live Template'/'Code snippets' in your IDE. It's the best way to improve performace.
https://www.jetbrains.com/help/idea/creating-code-constructs-by-live-templates.html
If you use VC Code then you can use extension Cucumber (Gherkin) Syntax and Snippets:
https://marketplace.visualstudio.com/items?itemName=stevejpurves.cucumber
Is there a way to capture and store (or write to a file) the values returned in the Response? (Checkpoint values)
Using HP UFT 11.52
Thanks,
Lynn
I figured it out. In UFT API under Standard Activities, there are File function modules including "Write to File". I added the module to the test, set the path and other properties, passed the variable to the file and it worked! Couldn't be easier.
I mentioned this on my other answer , you can also write it programatically if you have dynamic array response please refer below:
https://stackoverflow.com/a/28012383/3972994
After running a test, in the test folder, you can find a Snapshots/LastIteration directory.
In it you can find the return value for each step saved in a txt file.
Pay attention that if you data drive the step, only the last iteration will be saved to file.
However, in the Test's log (Test dir/Log/vtd_user.log) you can find all the iterations persisted
Thanks,
Yossi
You do not need to use the standard activities if you do this
var iResponse = this.Activity.responsebody;
System.IO.File.WriteLines(#"directorypath&FileName);
the above will write the response to the file and rewrite it for every run
Is there a way to use a wildcard inside an assertion in a XPath test with SoapUI?
I took a look at SoapUI's documentation and they say you can do something like this
<path1>
<path2>*</path2>
</path1>
I checked the 'Allow Wildcards' checkbox.
My question is : I want to assert my date starts with 2012-08-22 but i dont care about the minutes and seconds. I guess my the expression should be something like 2012-08-22* but it doesn't work.
What you are doing sounds like it should work. Here is a quick example i cooked up using a rest service from http://www.geonames.org/export/web-services.html#timezone. I'm using the demo they have supplied
http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo
output is
<geonames>
<timezone tzversion="tzdata2012c">
<countryCode>AT</countryCode>
<countryName>Austria</countryName>
<lat>47.01</lat>
<lng>10.2</lng>
<timezoneId>Europe/Vienna</timezoneId>
<dstOffset>2.0</dstOffset>
<gmtOffset>1.0</gmtOffset>
<rawOffset>1.0</rawOffset>
<time>2012-07-25 04:39</time>
<sunrise>2012-07-25 05:50</sunrise>
<sunset>2012-07-25 21:00</sunset>
</timezone>
</geonames>
If you do an xpath match on the result and use the select from current button you get
//geonames/timezone/time
2012-07-25 04:39
If you update this to
//geonames/timezone/time
2012-07-25*
this will work fine and when updating the rest request with a new lat and lng the assertion will still pass since it is not checking the time. If this doesn't help, please supply your full assertion and maybe i could help more.
*note: for soap requests, make sure to declare the namespace and then use the proper format
//ns1:message
It will be sort of a pain, but here is what you can do:
1) Figure out an Xpath 'base' using the assertion tab (sounds like you are here already). I used this public site to test against: http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl
I used the CornerPoints method with 'hawaii' as the single param.
I created this 'base' xpath:
declare namespace ns1='http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl';
declare namespace SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/';
declare namespace SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/';
/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:CornerPointsResponse/listLatLonOut
(it will write the declare statements for you if you click declare)
(which you can test out in the assertions window)
2) Create a Properties step
3) Create a Property transfer step
4) Create a groovy script
5) add a property... i called mine misc
6) add a transfer step
* transfer from the CornerPoints - Request 1 --- Response
* paste the Xpath stuff in the box under the 'transfer from'
* Transfer to your property
(You can test with the little play button)
7) Add something like this to your groovy script:
def x = context.expand( '${Properties#misc}' )
def parts = x.tokenize(',')
for (def part in parts)
{
log.info(part)
if (part.startsWith("-153"))
log.info("good")
}
In the groovy step you can do anything you need to get at your (partial) data. The sample code I added gets lat/lons out of a long line wrapped in CDATA and then checks for just the starting part of some of the data.. just an example.
Remember that you can use groovy and java string methods:
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html
More groovy tips:
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html