Nested conditionals or some such - tinybutstrong

I need to do something like:
[onshow;if [onload.project.sortBy]='Id';then if [onload.project.sortAscending]=1;then '↓';else '↑']
But, perhaps as expected, ↑ is always displayed.
What's the alternative here?
Thank you and be well.

The expression then if is not support by TBS.
You're trying to perform a AND operation between ([onload.project.sortBy]='Id') and ([onload.project.sortAscending]=1) but TBS does not support logical operators.
So here are 3 workarounds:
1) Solution using multiple if/then parameters :
[onshow;if '[onload.project.sortBy]'!='Id';then '↑';if [onload.project.sortAscending]=1;then '↓';else '↑']
2) Solution by simulating AND with concatenation :
[onshow;if '[onload.project.sortBy]-[onload.project.sortAscending]'='Id-1';then '↓';else '↑']
3) Solution using custom variable :
[onshow;if '[onload.project.sortByIdAscending]'='1';then '↓';else '↑']

Related

Using IF, AND/OR (many condition) with Array formula in Google sheets

Could someone help me?
I'd like to use the Array formula with AND/OR as follows but it doesn't work
=ArrayFormula(if(AND(AG2:AG="Yes",AI2:AI<>""),"Ok","Blank"))
It similar to OR
How can I use this in case I need to put more than 2 conditions in the AND/OR when using the Array formula?
Thanks so much.
Do not use AND/OR with ARRAYFORMULA, use + instead of OR and * instead of AND with IF
Try
=ArrayFormula(if((AG2:AG="Yes")*(AI2:AI<>""),"Ok","Blank"))
You can add other conditions if you respect the syntax with + or *

Wrap all the strings with single quotas

Let's assume that my template is like a following
string1=${obj.firstString}
string2=${obj.secondString}
number1=${obj.firstNumber}
I'm looking for some automatic way to wrap all my string parameters with single quotas? The expected output is
string1='A'
string2='B'
number1=42
I understand that I can write string1=${"'" + obj.firstString + "'"} , but maybe there is some more conventional way for this requirement...
Thanks a lot!
I would just do this:
string1='${obj.firstString}'
string2='${obj.secondString}'
number1=${obj.firstNumber}
It's a template language, so the basic idea is to make your program look similar to its own output.

Example to find a value in a list using common expression language (CEL)

I was following google common expression language specification, can some one guide me if i could do something like this:
I need to write an expression to find if "345" is in the phone_numbers list using google CEL .
json : {"phone_numbers": ["123","234","345"] }
example : phone_numbers.exist_one("345"); // this does not works ....
https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions
I got the expression :
phone_numbers.exists_one(r, r=="345")
Since you're just testing for the existence of a single value in a list, I would recommend using the in operator:
'345' in phone_numbers
The exists_one macro is pretty useful if '345' can only appear exactly once in the list.

JMeter "if controller" with parameters?

I was reading the JMeter documentation and came across this info box about "If Controllers":
No variables are made available to the script when the condition is interpreted as Javascript. If you need access to such variables, then select "Interpret Condition as Variable Expression?" and use a __javaScript() function call. You can then use the objects "vars", "log", "ctx" etc. in the script.
I don't quite follow this. Does this mean if I want access to a "User Defined Parameter" then I can access it only by writing some JavaScript? The example that follows this box then refers to "${COUNT}"
Could someone clarify the usage of the If Controller, maybe with an example or two?
All these answers are wrong! You need to put the variable reference in quotes, like so:
"${my_variable}"=="foo"
You can simply use something like
${my_variable}=='1'
Sometimes JMeter documentation can be confusing :)
Edit 27 september 2017:
The answer here works but has a very bad performance impact when number of threads exceeds 40.
See below for correct and most performing answer:
https://stackoverflow.com/a/46976447/460802
See:
https://bz.apache.org/bugzilla/show_bug.cgi?id=61675
UNCHECK the CHECKBOX
"Interpret condition as variable expression"
I wasted a couple of hours without unchecking this checkbox. It worked with and without semicolon(;) at the end of the statement. Make sure that you have set the User-Defined Variables before calling the if controller.
All the following variations worked for me in Jakarta Jmeter 1.5
${__javaScript("${HOMEPAGE}"=="Y")}
${__javaScript("${HOMEPAGE}"=="Y")};
"${HOMEPAGE}"=="Y"
"${HOMEPAGE}"=="Y";
If Controller will internally use javascript to evaluate the condition but this can have a performance penalty.
A better option (default one starting from JMeter 4, see https://bz.apache.org/bugzilla/show_bug.cgi?id=61675) is to check "Interpret Condition as Variable Expression?", then in the condition field you have 2 options:
Option 1 : Use a variable that contains true or false. For example If you want to test if last sample was successful, you can use
${JMeterThread.last_sample_ok}
or any variable you want that contains true/false
${myVar}
Option 2 : Use a function (${__jexl3()} is advised) to evaluate an expression that must return true or false.
For example if COUNT is equal to 1:
${__jexl3("${COUNT}"== "1",)}
OR
${__jexl3(${COUNT}== 1,)}
Starting with 4.0, if you don't use the "Interpret Condition as Variable Expression?", a warning in RED will be displayed:
If you'd like to learn more about JMeter and performance testing this book can help you.
God bless the http://habrahabr.ru
Have tried until found these.
Using the quotes was my solution.
As Gerrie said you need to check your variable
${my_var} == 'value'
But be careful with the 'User Defined Variables'
Note that all the UDV elements in a
test plan - no matter where they are -
are processed at the start.
That basically means that you cannot define 'User Defined Variables' inside an 'If Controller'. Take a look to the 'BeanShell' instead.
Replace:
${my_variable}=='1'
with
"${my_variable}" == "1"
if it's string value pass as below and its performance effective
${__groovy("${key}"=="value")}
I have used ${code_g1}== 200 in condition and it worked for me.

Is there a shortcut to swap/reorder parameters in visual studio IDE?

I have a common issue when working with code in the IDE:
string.Concat("foo", "bar");
and I need to change it to:
string.Concat("bar", "foo");
Often I have several of these that need to be swapped at once. I would like to avoid all the typing. Is there a way to automate this? Either a shortcut or some sort of macro would be great if I knew where to start.
Edit: changed to string.Concat to show that you can't always modify the method signature. I am only looking to change the order of the params in the method call, and nothing else.
<Ctrl> + <Shift> + <t> will transpose two words, so it would work in your case. Unfortunately I don't see this working (without multiple presses) for functions with larger parameter lists...
I had a lot of code with this function:
SetInt(comboBox1.Value + 1, "paramName", ...
SetInt(comboBoxOther.Value, "paramName", ...
And I needed to swap only the first two parameters;
I ended up using some text editor with regular expression management (like Scite), and using this one saved me hours:
Find: SetInt(\([.a-z0-9]+[ + 1]*\), \("[a-z0-9]+"\)
Replace: SetInt(\2, \1

Resources