jmeter vars.put with an object javascript - variables

I'm trying to use vars.put to write the result of the property of an object in a jmeter variable in javascript, but i have an issue...
Here is my code:
eval('var obj = ' + prev.getResponseDataAsString());
var meta_key = vars.get("MetaKey"); //meta_key is a variable
This works fine:
vars.put("content_metakey", obj[meta_key]);
but when i do this, it's doesn't work:
vars.put("taille", obj.meta_key[0].id); //meta_key variable
vars.put("taille", obj.tag[0].id); //tag is the value
Do you have any clue?
Thanks for your help.

i don't know if it's possible, so i used another way to do this: i used another eval.
my code:
obj2 = eval(obj[meta_key]);
vars.put("id_metakey"+meta_type,obj2[0].id);

Related

Cannot serialize a string object with Microsoft.Bond

I am using Microsoft.Bond to serialize a class object which works perfectly fine. However, when I try to serialize a simple System.String object, the CompactBinaryWriter writes almost nothing to the output buffer. I am using this code:
string v = "test data";
var outputBuffer = new OutputBuffer();
var writer = new CompactBinaryWriter<OutputBuffer>(outputBuffer);
Serialize.To(writer, v);
var output = outputBuffer.Data;
output in this case is a one element array : {0}, irrespective of the value of v. Can someone point out why this doesn't work?
Bond requires a top-level Bond struct to perform serialization/deserialization.
If only one value needs to be passed/returned, the type bond.Box<T> can be used to quickly wrap a value in a Bond struct. (There's nothing special about bond.Box<T>, except that it ships with Bond.)
Try this:
Serialize.To(writer, Bond.Box.Create(v));
You'll need to deserialize into a bond.Box<string>.
There's an open issue about having better behavior in cases like this.

How to Set Variable from Request in Postman

I am trying to write some tests for Postman. Many of the requests require an API key that gets returned by an initial GET request.
To set something hard-coded that is not dynamic, it looks like the test code is of the form
let variable = pm.iterationData.get("variable");
console.log("Variable will be set to", variable);
How do I set a return value as a global variable and then set that as a header parameter?
#Example if you setting ApiToken that is dynamic.
Under Tests tab in postman.
Put the following code.
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("Token", jsonData.token);
Under specific environment put variable name as "Token" and current value will be set automatically.
access the variable using {{variable_name}}
#Example: {{token}}
You can specify that variable value in the request Headers by using the {{var_name}} syntax. Instead of any hardcoded value that you may have been using.
You would previously have had to set the value using the pm.globals.set()syntax.
If you do not have the SDK active (monthly payment required to Postman). You can retrieve the values through __environment and __globals.
//Use of environment
postman.setEnvironmentVariable("my_value", "This is a value");
//...
let myValueVar = postman.__environment["my_value"];
console.log("Variable value is:", myValueVar);
//shows: Variable value is: This is a value
//Use of Globals
postman.setGlobalVariable("my_value2", "This is a value of globals");
//...
let myValueVar2 = postman.__globals["my_value2"];
console.log("Variable value is:", myValueVar2);
//shows: Variable value is: This is a value of globals
Also you can see your globals variables in Environments->Globals of your Posmant client.

request.setAttribute is not working with chain.doFilter

I have two servlet ReplayFilter and VideoReplayServlet. From ReplayFilter, I am calling VideoReplayServlet using chain.doFilter. I am able to call VideoReplayServlet from ReplayFilter but I am not able to get userId variable from request object in VideoReplayServlet, which I have already set in request object before calling chain.doFilter. You can find my code below -
In ReplayFilter -
request.setAttribute("userId", userId);
request.setAttribute("uname", "mari");
chain.doFilter(request, response);
In VideoReplayServlet -
String uname = request.getParameter("uname");
String user_Id = request.getParameter("userId");
In VideoReplayServlet replay, I am getting both uname and user_Id null.
Can anybody help me?
I think the issue here is that you are setting it as an attribute and expecting it as a parameter which is contradicting.
Try the below code instead
request.getAttribute("userId", userId); //Note the getAttribute() instead of getParameter()

dojo 1.7 QueryReadStore parameters

I am new to Dojo, I am using QueryReadStore as the store for loading my TreeGrid, working fine. But the QueryReadStore appends some paramters to the url, parameters like parentId, count, sort etc., I have looked at this link http://dojotoolkit.org/reference-guide/1.7/dojox/data/QueryReadStore.html, but not able to understand.
Parameters are getting passed like this servlet/DataHandler?start=0&count=25
How to manipulate the parameters, like I want to set the value for parentId paramters so that I only get that particular row details.
In theory you wold have to create a new class by extending the "dojox.data.QueryReadStore", in the link you posted have an example for doing exactly what you want. See if you get it now(changed a bit):
dojo.require("dojox.data.QueryReadStore");
dojo.declare("custom.MyReadStore", dojox.data.QueryReadStore, {
fetch:function(request){
//append here your custom parameters:
var qs = {p1:"This is parameter 1",
q:request.query.name
}
request.serverQuery = qs;
// Call superclasses' fetch
return this.inherited("fetch", arguments);
}
});
So When come to create the QueryReadStore you actually create a object with the class you defined. something like this:
var queryReadStore = new custom.MyReadStore({args...})
Explore the request parameter passed to the function to see what else you can do.

OOP in Corona, accessing vars from outside class

looking for some help with accessing variables from outside a Corona OOP class. Here's the bare-bones code:
module(..., package.seeall)
local widget = require "widget"
picker = {}
picker.__index = picker
function picker.new()
local picker_object = {}
setmetatable(picker_object,picker)
picker_object.theHour = 12
picker_object.theMin = 0
picker_object.am = true
return picker_object
end
function picker:getHour()
return self.theHour
end
function picker:getMin()
return self.theMin
end
self is coming back as nil when I try and call getHour and getMin from outside the class. What syntax should I use instead to return my theHour and theMin variables?
Thanks!!
I tried out your code and there's nothing wrong with it. The problem is probably in the way you're accessing this module. Here's my main.lua that works with your code (I gonna guess your file is named picker.lua):
local picker = require "picker"
local picker_obj = picker.picker.new()
-- the first picker is the module (picker.lua)
-- the second is the picker class in the file
print("minute: " .. picker_obj:getMin())
print("hour: " .. picker_obj:getHour())
Also, The module(..., package.seeall) command has been deprecated, see this blog post for a better way to make your module. If you use this method to create your module and still call your file picker.lua, the first two lines in my main.lua would change to:
local picker = require "picker"
local picker_obj = picker.new()
Here's the simplest way I would modify your code to use the new way of creating modules. Only the beginning and end change, everything else stays the same:
-- got rid of module(), made picker local
local picker = {}
picker.__index = picker
... -- all the functions stay the same
return picker