JMeter mathematical function - jmeter

I have one random variable and one variable which I read from page. How can I subtract or multiply that two variables and where or in which component in JMeter.

Check out the functions page for Jmeter. It has tons of cool math tools that you can plug anywhere in your script.
You'll most likely end up doing a jexl command, which would look something like this: ${__jexl2(${var1}-${var2})}

The above did not work for me. How ever i was able to resolve my problem with :
${__jexl(vars.get("YOUR_VARIABLE")+1)}

Related

Quick question about Environment Variables use in SH scripts

I have found a script to set the background image and do some more stuff, but that's not important.
Look at this line, it's supposed to set a route, nothing complicated.
#!/bin/sh
bgloc="${XDG_DATA_HOME:-$HOME/.local/share/}bg"
I didn't understand what was it doing, because of the env variable and the :- that comes after it. Now, after some trial and error, I've figured it out. It sets the variable bgloc with the value of that env variable and, if that variable is not set —which is the case—, then, it use the route that comes after the :- .
So, the question is: why does that happen? I mean, I've searched it on the internet, and I haven't found anything. Is it supposed to work like this? In that case, where can I find information about that? I'd like to learn more about it, but I don't find any information on the internet. Some help would be great. Thanks.
A lot can be done with values within ${} in bash.
To find out more about these features I would recommend to read TLDP manual on this topic.

Error calling similar() in Sikuli

l = find("Start_menu.png").similar(0.5).anyColor()
click(l)
The above is an excerpt from my code. "Start_menu.png" refers to an image of the Windows Start Menu. I got the following error when I executed this:
File "C:\Users\VPRAVE~1.TSI\AppData\Local\Temp\sikuli-tmp8636618870597770744.py", line 1, in
l = find("1368426219510.png").similar(0.5).anyColor().anySize()
AttributeError: 'org.sikuli.script.Match' object has no attribute 'similar'
Could some one help me out with this? And could some one tell me how to use anyColor() and anySize()?
find attempts to find something when it's called. So what your code says, in prose, is "find something that looks like 'Start_menu', then make the thing you found 0.5 similar, then make that any color"
This is wrong--you can't set the similarity threshold after the fact. Instead, call it as seen in the Sikuli docs.
Instead, say
l = find(Pattern("Start_menu.png").similar(0.5))
Here's the same code arranged vertically:
pattern = Pattern("Start_menu.png")
pattern.similar(0.5)
l = find(pattern)
The other problem is your reference to the anyColor() function, which doesn't exist. I see the code you're trying to run is from "Sikuli: Using GUI Screenshots for Search and Automation" (linked from the Sikuli docs), but this function (and the syntax used in that paper) don't exist in any extant version of Sikuli. You can see an open feature request for it on the Sikuli launchpad page.
This doesn't help you now, though. I don't know of another visual automation package that can do anyColor. If you wanted to use that feature for something, I suggest asking a new question where you describe the problem you're trying to solve, and someone may be able to suggest a work-around for that specific case.

Generalizing Cucumber/Capybara Tests

I wrote a feature to test the default configuration of my web app using Cucumber and Capybara. Part of the feature looked like this:
And the page has a photo labeled "Device"
And the page has a checkbox labeled "Device"
And I check "Device"
And I submit the form
Then the resulting page has no photo labeled "Device"
It worked great. I want users who have installed and configured the web app on their own servers to be able to run the test to help confirm that their configuration is correct. And "Device" is a string in the default config file that the user can change. It's an element in an array and they can add to or remove from the array when configuring their instance of the app.
Is this a sensible use of the tools or am I abusing Cucumber and/or Capybara? If it's sensible, how would I do it? If it's a bad idea, what tools might I use for this instead, if anything?
Here's how I got it to work. I'm just not sure this is the best way to do it.
For this to work, the feature would have to look more like this:
And the page has at least 3 photos, let us call the last one "third_photo"
In the corresponding step definition, I use an XPath to pull out the corresponding label string for the first photo and assign it to a Hash object stored in a class variable.
And /^I the page has at least (\d*) photos, let us call the last one "([^\"]*)"$/ do |n, name|
if ! defined?(#note)
#note = Hash.new;
end
#note[name] = find(:xpath, '//ol[#id="menu"]/li[' +n+ ']/a').text;
end
Subsequent step definitions can now access the value, whatever it was.
So, another feature might be:
Then I uncheck "third_item"
And the corresponding step definition might be:
Then /I uncheck "([^\"]*)"/ do |item|
uncheck(#note[item])
end
But I don't feel good about it. If nothing else, I imagine there might be a name collision with another instance variable defined outside the step definitions.
It feels like I'm either Doing It Wrong or else I'm Using The Wrong Tool. What is the right way to do this?
Don't know what you are fishing after, but it feels like your tests and implementation are quite tightly coupled. Maybe that's the feeling you are having, that it seems like you are describing your app in tests.
I don't have a good answer to your questions, merely because I don't "understand" it. I would however urge you to try to decouple your tests from your implementation and see if there's any abstraction there waiting to be found.
There's a blog post about using instance variables in step definitions at http://www.cloudspace.com/blog/2010/06/23/using-instance-variables-with-cucumber-steps/.
Commenters talk about the coupling this entails and at least one possible way around it.
In particular, davetron5000 says:
What we do is to not use instance variables at all, but instead
provide a has that shared state can go in. This hash is cleared after
each test run. Not ideal, but it's a bit cleaner than random instance
variables all over the place (and also ensures a reasonably clean
state before each test)

XPath Query in JMeter

I'm currently working with JMeter in order to stress test one of our systems before release. Through this, I need to simulate users clicking links on the webpage presented to them. I've decided to extract theese links with an XPath Post-Processor.
Here's my problem:
I have an a XPath expression that looks something like this:
//div[#data-attrib="foo"]//a//#href
However I need to extract a specific child for each thread (user). I want to do something like this:
//div[#data-attrib="foo"]//a[position()=n]//#href
(n being the current index)
My question:
Is there a way to make this query work, so that I'm able to extract a new index of the expression for each thread?
Also, as I mentioned, I'm using JMeter. JMeter creates a variable for each of the resulting nodes, of an XPath query. However it names them as "VarName_n", and doesn't store them as a traditional array. Does anyone know how I can dynamicaly pick one of theese variables, if possible? This would also solve my problem.
Thanks in advance :)
EDIT:
Nested variables are apparently not supported, so in order to dynamically refer to variables that are named "VarName_1", VarName_2" and so forth, this can be used:
${__BeanShell(vars.get("VarName_${n}"))}
Where "n" is an integer. So if n == 1, this will get the value of the variable named "VarName_1".
If the "n" integer changes during a single thread, the ForEach controller is designed specifically for this purpose.
For the first question -- use:
(//div[#data-attrib="foo"]//a)[position()=$n]/#href
where $n must be substituted with a specific integer.
Here we also assume that //div[#data-attrib="foo"] selects a single div element.
Do note that the XPath pseudo-operator // typically result in very slow evaluation (a complete sub-tree is searched) and also in other confusing problems ( this is why the brackets are needed in the above expression).
It is recommended to avoid using // whenever the structure of the document is known and a complete, concrete path can be specified.
As for the second question, it is not clear. Please, provide an example.

capturing what keys were used to launch vbscript

I have an application that has 'macro' capabilities. When I map some keys on the keyboard to perform the 'macro', I can also have it launch vbscript instead.
What i'd like to try and do is within my vbscript figure out what keys were used in order to launch the script. Is it posible to do this? Could there be a way in vbscript to figure out what keys were last touched on the keyboard and then I could apply my logic.
The purpose of doing this is to keep the code in a single .vb file instead of several seperate .vb script files(one for each keyboard mapping, possible 3-4). Obviously we are looking to just maintain 1 file instead of multiple files with essentially the same code in each one.
I am leaning towards the idea that this is not possible, but i figured this would be a worthy question for the masses of StackOverflow. Thanks for the help everyone!
What you are asking for is not possible.
Can you change your VBScript to accept parameters and then call it with a different parameter based on which hotkey was selected?
I agree with aphoria, the only way to make something like this possible is if your keyboard mapping software allows you to assign a script/command with parameters/arguments. For example if you used
c:\Temp\something.vbs
then you would change this to
%WINDIR%\system32\wscript.exe c:\temp\something.vbs "Ctrl-Alt-R"
Then in your vbscript code you could collect the argument using the wscript.Arguments object collection to do actions based on what argument/parameter was passed. See the following two links for more info:
http://msdn.microsoft.com/en-us/library/z2b05k8s(VS.85).aspx
http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0915.mspx
The one possible approach you may use is to install keylogger and read its log in your VBScript.
For example save script start time in the very beginning of the script
StartTime = Timer()
and then read one log record of your keylogger before this time.

Resources