how to write 2 conditions in single while controller? - performance

i have used below code in while controller but not working in single iteration.
these 2 conditions used for text checking
${__javaScript("${textcheck1}".indexOf("Message") == -1,)}
&&
${__javaScript("${textcheck2}".indexOf("Message1") == -1,)}
plz help me on that.how to write both condition in single while controller?
i have tried multiple ways but not working ..

You need to put both conditions into single __javaScript() function like
${__javaScript(("${textcheck1}".indexOf("Message") == -1 && ("${textcheck1}".indexOf("Message1") == -1,)}
See Using the While Controller in JMeter article for more details.
Also as per __javaScript() function documentation:
javaScript is not the best scripting language for performances in JMeter. If your plan requires a high number of threads it is advised to use __jexl3 or __groovy functions.
so it worth considering migrating.

Related

Cypress assert A or B

I want to make an assertion in Cypress as follows:
cy.get(a).should('be.visible').or(()=>{
cy.get(b).should('be.visible');
});
In other words, I want to check if condition A or condition B is true. How to do this in Cypress?
One way is to use the jQuery multiple selector. It will require moving the visible assertion inside the the selector using :visible.
cy.get('a:visible, b:visible')
Be aware you sacrifice some of Cypress' built-in retry (as with all conditional testing).
For example, if b:visible now but a:visible in 1 second, it will give you b. Whereas cy.get(a).should('be.visible') will wait the second and return a.
Depending on details of the scenario, there are other ways.

How to perform a NOT query with postgres_ext

Is it possible to perform a NOT type query with chained methods using postgres_ext?
rules = Rule.where.overlap(:tags => ["foo"])
Basically want the inverse of the above. Thanks!
In regular active record you can use .where.not as described in this article: https://robots.thoughtbot.com/activerecords-wherenot however looking through the source code of postgres_ext I don't know if it is defined in that library. You may be able to construct your query in a way that uses the native active record methods.

iup.GetParam in LUA: data validation in the callback function

LUA novice, experimenting with GUI using iup.GetParam using LUA 5.1.
I have a simple use of iup.GetParam (which works fine with a simple callback function testing for OK & Cancel) and am trying to add some simple data validation for the parameters (e.g. testing a parameter for being alphanumeric), but am unsure of the correct approach.
I've searched the reference manual (and for code examples), but drawn a blank so far.
Using the string validation example, if I want to reject the
character entered by the user and display the old value of the
parameter, do I simply return 0 from the callback function, or, do
I also have to reset the value of the parameter to its previous
value before the return? Or is the right approach something
completely different?
In either case, do I have to refresh / update the GUI display with a
separate iup call, or does GetParam handle that for me?
Whatever combination I try, it doesn't appear to work (the parameter happily displays the non-alphanumerics). Debugging shows the validation test and return working as coded, so the advice I'm seeking is to get confirmation of the right approach. Sharing a simple working example would be great.
simply return 0
No, IUP will do everything for you, in this case
Download the "getparam.wlua" from the examples folder, then add to its callback this:
elseif (param_index == 1) then
return 0
You will notice that the integer value is now read-only.

CodeIgniter model not right with where condition

I have this code in my model:
$this->db->where('transaction_income_barcode.barcode_number', $barcode_number);
The value of $barcode_number is 000500007301000005304778
So I compare using PHP it is the correct value:
if($_POST['barcode_number'] == '000500007301000005304778')
but somehow via the model it is not working correctly.
Any ideas?
Forget all the chatter of var_dump() or complicated last_query(), simply follow the CI process of profiling your code and add:
$this->output->enable_profiler(TRUE);
In your controller after the active call. This will show you your FULL SQL QUERY (actually, all queries on that page).
Cleanest way to go about it, my suspicion is that your value is being converted to a int and it STRIPS out the leading 000's
Take care of that by doing a cast:
$this->db->where('transaction_income_barcode.barcode_number', (string)$barcode_number );
As a side note:
Don't use $_POST['barcode_number'] instead be safe with CI's $this->input->post('barcode_number');

Method Naming Convention Question (most languages)

If I have a method that hides a button, I would probably call it HideButton
If I have a method that shows a button, I would probably call it ShowButton
But what do you guys call a ShowIfThisHideIfThat style method?
Possible Choices:
TestForButtonVisibility (this kind of sounds like it will return true/false but not actually do the work)
TestButton
ShowHideButton (style I'm currently using)
Been at this a number of years and still don't have a style that I like for these types of methods. I'm working mostly in C# and a little Java, Ruby, and F#. What do you use for method names in this regard?
// example of the style of method
public void ShouldIShowOrHideButton()
{
Button.Visible = ((chkSomeSetting.Checked) && (DateTime.Now.Day < 8));
}
How about updateButtonVisibilty()?
Might be overengineering, but the reason you may have problems because it's doing two things. So making sure you only have a function doing a single thing, howabout a method to determine if the button should be shown or not (takes parameters, returns bool), then set the value of the button directly.
Button.Visibilty = DetermineIfButtonShouldBeShow(...);
My preference has been to keep toggle methods rather than separate methods for hide/show.
ToggleButtonVisibility()
This allows you to put your testing code in there and the expected result/output would be a properly visible/invisible button.
Edit: Toggle is a personal preference that stems from a partial background in working with binary gates, architecture, etc where a toggle may go through several separate gates before reaching an end state. The word itself could be changed to anything else such as Update, Determine, Finalize, or even Steve. It really boils down to what makes sense to you and what your standard is.
Edit: Now your question is edited to include the example
// example of the style of method
public void ShouldIShowOrHideButton()
{
Button.Visible = ((chkSomeSetting.Checked) && (DateTime.Now.Day < 8));
}
My answer is neither. I would do two things:
Move the Button.Visible part outside the function, so the function just computes the logic and returns bool.
Name the function according to its internal logic not according to whether it is for a button or not. So if your function checks for a wedding day it would be called IsWeddingDay, if it checks for a monthly meeting it would be IsMonthlyMeeting.
The code would be
Button.Visible = IsMonthlyMeeting()
and the logic can be subsequently used to control any other widgets if needed.
Old Answer:
You probably need to explain more what ShowIfThisHideIfThat does.
If it depends on one condition, like:
if (condition)
ShowBotton()
else
HideButton()
then I would use
Button.SetVisibility(condition)
as per Lazarenko's comment above, or if the language has properties:
Button.Visible = condition
If you have two conditions like what ShowIfThisHideIfThat seems to imply, equivalent to:
if (cond1)
ShowButton()
else if (cond2)
HideButton()
else
LeaveButtonAsItIs()
then the logic in my opinion is complicated and I wouldn't use one function. Sure, the code is equivalent to
Button.Visible = cond1 || (!cond2 && Button.Visible)
but you lose the understandability.
I would use one of these:
setXVisibility
refreshX or refreshXStatus
How about using SetButtonVisibility( )
The confusion seems to stem from a mixing of the business logic and the UI logic. The test isn't whether the button should be shown. Code is going to use the test to decide if the button should be shown. It probably depends on whether some feature should be available. Consider:
if (IsFeatureEnabled()) {
ShowButton();
} else {
HideButton();
}
This is the code where business logic (IsFeatureEnabled()) meets UI (ShowButton()/HideButton()).

Resources