why my while loop doesn't work in Jmeter? - javascript

please click the link to view the images.
I have a Json Extractor, which saves the value returned in "status"
it's working:
and I also have a "Controller while" with this condition:
$ {__ javaScript ("${status}". indexOf ("string") != 500 ,)}
But something strange is happening
2021-11-25 14:30:46,258 DEBUG o.a.j.c.WhileController: Condition string: '$ {__ javaScript ("ERROR". indexOf ("string") != 500 ,)}'
2021-11-25 14:30:46,258 DEBUG o.a.j.c.WhileController: Condition value: 'false'
2021-11-25 14:30:46,258 DEBUG o.a.j.t.p.AbstractProperty: Running version, executing function
Wasn't it supposed to give "true" and end the loop?

Your condition is not very correct, if you want to end the loop when your ${status} variable becomes 500 you should use something like:
${__javaScript("${status}" != "500",)}
Also from performance perspective it's better to consider using __jexl3() function like:
${__jexl3("${status}" != "500",)}
or __groovy() function like:
${__groovy(vars.get("status") != "500",)}
as this is something that __javaScript() function documentation suggests

Related

js doesn't execute 'else' statement

I have an if-else statement in JavaScript which returns false, but doesn't execute the code inside 'else'.
part of the script inside the cshtml file:
if (#Session["mission"].ToString() != "1") {
setInterval(function () { myTimer(ctxPoints, ctxLines); }, 1000 / #ViewBag.rate);
} else {
alert("hi");
}
In the debug the '#Session["mission"].ToString() != "1"' statement returns false, but nothing jumps to the screen.
You should open your web browser Developer console and see the real script which reaches the browser.
The Razor parts, #Session["mission"].ToString() doesn't exists in the browser script, because they are evaluated in the server, before sending them to the browser. So it makes no sense to try #Session["mission"].ToString() != "1" this in the console. In the browser you will get something like:
if (1 != "1")
or even like
if ( != "1")
which would provoke an error.
JavaScript does coalescing, so 1 is equal to "1" when you use the comparers == or !=, so you don't need to include the qoutes around the value (unless you get the error mentioned above: in this case, if you included the quotes, you'd get if ("" != "1")).
Coalescing is avoided by using the !== or === which would consider 1 not equal to "1", so, including the quotes doesn't make any difference in this case.
I think you should clear Js code and c# code
if ("#Session["mission"].ToString()" != "1")
Session["mission"].ToString() this print string in c#, but you need to encapsulate it in quote to make this value get type string

Short circuit in JS stopping on first input

I'm having some problems trying to use short circuiting on a web page I am making.
I am trying to use
document.webkitExitFullscreen() || document.mozCancelFullScreen() || document.exitFullScreen();
But it seems to stop on the first try, despite that I would have though it would continue after the first argument comes up as undefined.
If I simply type in
document.mozCancelFullScreen()
then it works fine
I was wondering if anyone could point me to what I'm doing wrong here
The screenshot is taken in firefox btw.
Thanks in advance
Your code is trying to call document.webkitExitFullscreen and if it returns a falsy value, call document.mozCancelFullScreen, etc.
But if document.webkitExitFullscreen itself is undefined you'll get an error trying to call it, and the code will stop running at that point.
Perhaps:
var exitFullScreen = document.webkitExitFullscreen || document.mozCancelFullScreen || document.exitFullScreen;
if (exitFullScreen) {
exitFullScreen.call(document); // Just `exitFullScreen();` may work as well
}
Or alternatively:
["webkitExitFullscreen", "mozCancelFullScreen", "exitFullScreen"].some(function(name) {
if (document[name]) {
document[name]();
return true;
}
});
...which avoids the whole "do I need call or not?" issue.
The problem is that you're already calling the function, so if it doesn't exist, you get an error.
You coudl try something like:
(document.webkitExitFullscreen || document.mozCancelFullScreen || document.exitFullScreen)();

Boolean value in javascript

Ok, I've got an issue I don't understand.
I have a boolean value which I test and if true I do something.
BUT javascript never go in it even if the var is true.
I try this :
if(isConfigD)
handleConfigurationD;
this :
if(isConfigD == true)
handleConfigurationD;
And this :
if(isConfigD === true)
handleConfigurationD;
But nothing work whereas isConfigD is always set on true :(
What am I missing ?
You condition works well, but if you call a function, then you need parenthesis for the call.
handleConfigurationD();
// ^^
handleConfigurationD is just an identifier. That statement is going to have one of two outcomes:
A ReferenceError
"Yup, that's a bit of data"
Presumably you have stored a function in it and want to call the function.
handleConfigurationD();

Boolean in IF Condition causing Errors in JavaScript

I am developing a webpage with fairly simple JavaScript. My entire JavaScript code is:
function showUnlockPopup(isViolated,instId,unlock_done,unlock_total,period,endDate){
alert(isViolated);
if(isViolated){
if(unlock_done < unlock_total){
showInfoPopup(instId,unlock_done,unlock_total,period);
} else {
showNoUnlocksPopup(instId,unlock_done,unlock_total,period,endDate);
}
} else {
showNotViolatedModal();
}
}
However, irrespective of the value of the 'isViolated' variable, my 'showInfoPopup' function is called.
I have checked the code for the method call too:
<button onClick="showUnlockPopup(isViolated)">Unlock</button>
The alert shows 'true' or 'false' values correctly, but the logic runs for only 'true' irrespective of the value.
I think I am missing something fairly basic here. I tried a lot, but of no use. Kindly help me with the same.
it is because isViolated is returned as a string. so unless the string is null it will be true if it has some contents. You should change your check to isViolated == 'true', make a new variable that is a boolean and assign it depending on isViolated or something third.

Meteor cursor.fetch().property returns "undefined"

I have a simple helper that returns an array to an #each block inside my template. This works ok and the tags are displaying.
However, i don't understand why i can't console.log a property of the userTags, for instance userTags.BusinessContact. But i can console.log the complete object so (console.log(userTags)) will work.
Template.profileTags.helpers({
tag:function(){
var userTags = tikiUser.find({}).fetch()
//this returns "undefined" 2 times
Meteor.setTimeout(function(){console.log(userTags.BusinessContact)}, 500)
return userTags
}
})
Why is that?
thx,
You are trying to get the BusinessContact property of an array - try doing
userTags[0].BusinessContact
PS: Try to make a meteorpad.com when posting a problem
Just try this.
if(userTags)
{
Console.log(userTags.BusinessContact)
}
In meteor some time we will not get value for the first time so,If we write a if condition than it will check the value there Only.
Hope this helps you.

Categories

Resources