Using result from the first request and passing in the second request- POSTMAN - api

I want to use the result which is "id" and use it in the second request POST
Saving it as environmental variable in the first request(under tests)
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("id", jsonData.token);
Here is the second request looks like, not sure what I am doing wrong here

Your request is correct.
As long as you set an environment variable, you may USE this environment. From your print screen I see "no environment" on the top right corner.
I suggest either you create an environment where to save your environment variables and then use it or you use a global variable, postman.setGlobalVariable("id", ...) instead
Alex

Related

How to save result from OS Process Sampler to a variable?

JMeter OS Process Sampler is set up, works fine and saves result (a token as result of powershell srcipt execution) to a file.
Is it possible somehow to save result from powershell script directly into a JMeter variable instead?
What should I add for that?
Normally you should be using JMeter Post-Processors in order to extract data from Sampler's responses
If the token is the only thing that your powershell script returns you can extract it using i.e. Boundary Extractor, just provide desired variable name and leave everything else empty
Demo:
If there is some other text surrounding the token - adjust the boundaries accordingly or go for Regular Expression Extractor

SOAP UI - Set a node value in all test step's requests of all test cases in a test suites

I'm trying to set a node value in all test step's requests xml of all test cases in a test suite.
The groovy script is in the first test case and I get an error (XmlException: Unexpected Element: CDATA) as soon as the script try to edit the same tag in the second test case.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def AlltestCases = testRunner.testCase.testSuite.project.testSuites[testRunner.testCase.testSuite.name]
0.upto(AlltestCases.getTestCaseCount()) {
AlltestCases.getTestCaseList().each{
it.getTestStepList().each{ if(it.getClass()==com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep){
if(it.getName().toLowerCase().contains("verify")){
step = groovyUtils.getXmlHolder("${it.getName()}"+"#Request")
step.setNodeValue("//*:Name/text()", "\$"+"{#TestSuite#NAME_ID}")
step.updateProperty()
}
}
}
}
}
If I understand your question correctly, you want to "inject" a value in a number of requests?
I would advise against that. I would rather set some project property, and then let each of the requests simply use that particular variable.
The most important reason for me to prefer this approach, is to make it more tranparent what is happening in your testcase, should someone else at some point - like if you get a different job - would need to take over your SoapUI projects. Currently you have requests, which hold values that appear to come out of nowhere. I would advise to make it clear that the request contains some sort of variable, and where that variable comes from.
Besides you will then also get more flexibility. If a few reqeusts at some point changes the path or name of the entity you want to change, you will need to make your code above handle that kind of situation. Not so, if you are merely using a variable in each of your requests.

Postman: How to use global variable defined in Pre-request Script in Tests Script

I have defined one global variable in a Pre-request Script.
I want to compare this global variable with variable present in the response.
As the warning message says, you're running a very old version of Postman and it's probably the chrome extension.
This is now several major versions behind and the pm.* functionality is not included in that old version of the chrome extension.
Download the native application and start using the newest version of Postman. By not doing this, you're missing out on so many new features.
As #Danny mentioned, it is recommended to update to the latest version.
Now to your question, if you want to compare the global variable with workkard_number present in response, you need to first parse the response and get the workkard_number in it, which you can then compare with your global variable. You could try something like this in your test script:
var jsonData = JSON.parse(responseBody);
var responseWorkkardNumber = jsonData.wokkard_number;
You can retreive the workkard_number in the response like this(assuming that your response is a json with "workkard_number" as a key in it. Then you can compare it as follows:
tests["workkard_numbers are equal"] = responseWorkkardNumber === globals.workkard_number;
or
tests["workkard_numbers are equal"] = responseWorkkardNumber === pm.globals.get("workkard_number");
Also note - "Warning - Environment and global variables will always be stored as strings. If you're storing objects/arrays, be sure to JSON.stringify() them before storing, and JSON.parse() them while retrieving." - https://www.getpostman.com/docs/v6/postman/environments_and_globals/manage_environments

BeanShell PreProcessor updates User define variables

I'm very new at JMeter issues.
In a test script i have a BeanShell PreProcessor element that updates some variables previously defined at a "User Defined Variables" element.
Latter those variables are used in "Http Requests". However, the value that is used in the http request is the default one.
The scripts seems to be working due to some debug print();
My question is if it's necessary to delay the script to be sure that the BeanShell finishes?
Thanks a lot for your attention
There is no need to put any delay to Beanshell Pre-Processor as it's being executed before request. I'd recommend to check your jmeter.log file to see if there are any scripting issues as Beanshell Pre-Processor does not report errors anywhere including View Results Tree listener.
There are at least 2 ways to assure that everything is fine with your Beanshell script:
Put your debug print code after variables replace logic to see if it fires
Use JMeter __Beahshell function right in your HTTP request. If it's ok - View Results Tree will demonstrate beanshell-generated value. If not - the field will be blank and relevant error will be displayed in the log.
Example test case:
Given following Test Plan structure:
Thread Group with 1 user and 1 loop
HTTP GET Request to google.com with path of / and parameter q
If you provide as parameter "q" following beanshell function:
${__BeanShell(System.currentTimeMillis())}
and look into View Results Tree "Request" tab you should see something like:
GET http://www.google.com/?q=1385206045832
and if you change function to something incorrect like:
${__BeanShell(Something.incorrect())}
you'll see a blank request.
The correct way of changing existing variable (or creating new if variable doesn't exist) looks like
vars.put("variablename", "variablevalue");
*Important: * JMeter Variables are Java Strings, if you're trying to set something else (date, integer, whatever) to JMeter Variable you need to cast it to String somehow.
Example:
int i = 5;
vars.put("int_i", String.valueOf(i));
Hope this helps.
You can update the vale of a "user defined variable".
You have to create a bean shell sampler
vars.put("user_defined_variable", "newvalue");
#theINtoy got it right.
http://www.blazemeter.com/blog/queen-jmeters-built-componentshow-use-beanshell
I'm new to jmeter too but as I know variables defined in "User defined variables" are constants, so you can't change them. I recommend to use "User Parameters" in preprocessors or CSV Data Set Config.

Reference a variable within a variable in JMeter

I'm working with JMeter. I'd like to specify the test host using user defined variables, like this:
variable name value
localhost localhost
test 192.168.0.1
hostname ${localhost}
Executing the test, I see that the hostname value is not substituted, and obviously the test fails. I know I can use properties and pass the hostname from the command line, or simply change the hostname value. Is it possible to it like I've explained?
Thanks.
I've managed to solve my problem. I've changed the hostname variable value to: ${__evalVar(${localhost})}, but I've got this error:
ERRROR jmeter.functions.EvalVarFunction: Variables have not yet been defined
So I've moved the hostname variable declaration in a "User defined variable" child node of my Sampler node. That solved it.
To solve this you should use hostname = ${__eval(${localhost})}
http://jmeter.apache.org/usermanual/functions.html#__eval
Carlos' answer has a mistake (which I can't comment on due to rep) as it uses evalVar, this requires as an argument a plain string:
This works: ${__evalVar(localhost)})
This works: ${__eval(${localhost})}
This doesn't work (the current answer): ${__evalVar(${localhost})}
http://jmeter.apache.org/usermanual/functions.html#__evalVar
Check this forum:
from Blazemeter
For example: getting value of varible "listid_XXX" where the XXX number comes from an index variable:
${__V(listid_${idx1})}
New newer versions (from 2.2), you can use ${__V(${...})}/.
Ex: ${__V(${SERVER_CONTEXT})}/rest
As #Alies Belik mentioned, if you get
ERRROR jmeter.functions.EvalVarFunction: Variables have not yet been defined
then define the 2nd variable in next other UDV (User Defined Variables) node.