JMeter - How can I use multiple conditions in IF Controller? - if-statement

Here is my code:
In If Controller -> Condition (Default Javascript) I am providing following
"${responsecode}" == "404" || "${responsecode}" == "500" && "${responseMessage}" == "Not Found"

Yes you can, assuming your current condition SMTP Sampler will be executed:
If ${responsecode} variable is 404
OR
If ${responsecode} variable is 500 AND ${responseMessage} variable is Not Found
I doubt that you will get Not Found message given Response Code 500, most likely you will get an Internal Server Error there so maybe you should amend your condition to look like:
"${responsecode}" == "500" || ("${responsecode}" == "404" && "${responseMessage}" == "Not Found")
In case when If Controller doesn't behave as expected first of all check jmeter.log file for any JavaScript-related errors, it will give you some clue regarding what's wrong with your setup. You can also use __javaScript() function and View Results Tree listener combination to visualize the result of your If Controller condition:
See How to Use JMeter's 'IF' Controller article for more details on conditionally running samplers via If Controller.

Related

I m inserting my data uthrough page item using request process it gives an error fetch more then one row please give me a solution

var a = $v('P1995_LUMBER');
if ((a = '1')) {
apex.submit({
request: "CREATE",
set: {
LUMBER: "P1995_LUMBER",
LST_NME: "P1995_LST_NME",
FST_NME: "P1995_FST_NME",
},
});
} else if (a != '1') {
apex.submit({
request: "Update",
set: {
LUMBER: "P1995_LUMBER",
LST_NME: "P1995_LST_NME",
FST_NME: "P1995_FST_NME",
},
});
} else {
alert("bang bang");
}
Couple of things:
JavaScript's equality check is either == or === (more details here). (a = '1') assign '1' to the variable.
It seems like you're not using the apex.submit process correctly. Typically, you would set the item's value
e.g.:
apex.page.submit({
request: "SAVE",
set: {
"P1_DEPTNO": 10,
"P1_EMPNO": 5433
}
} );
Although, by looking at your JavaScript code, I would say you don't even need to use JavaScript.
Whenever you submit a page, all items on it are automatically sent to the server-side. You can then reference them using bind variables. You could then simply have two process, one for the Create and one for the Update, each having the corresponding insert/update statement using the different items on your page.
Usually what you will see is a page with two buttons for Create/Edit. They will have a server-side condition so that only the correct one is displayed.
Try creating a Form type page (form with report) using the wizard, and you'll see how everything is done.
Without seeing the page and the code you're using it's hard to tell what your issue really is, more details would be required.
That code does not have any sql in it so it is impossible to diagnose why you are encountering a TOO_MANY_ROWS exception. Run the page in debug mode and check the debug data - it should show you what statement is throwing the exception. If you need more help, post a proper reproducible case, not a single snipped of code without any context.

How can I write a code in apex that fires an alert when client selects a specific choices from 2 items

I have two items, P4_oper_type and P4_plan they are both drop down lists
all I want to do is when the client chooses "Partial Surrender" from P4_oper_type and "A" from P4_plan
an alert appears on the page, any other choice that client makes other than the specified conditions nothing happens.
I tried to write this code :
function cond(){
var item1 = apex.item("P4_oper_type").getValue();
var item2= apex.item("P4_plan").getValue();
if (item1.value == "Partial Surrender") && (item2.value == "A") {
window.alert('omar')
};
else null;
};
There is the place where I wrote my code, I don't know if this is the right place or there is something wrong with this code:
These are the two items to be selected by client with the condition :
Your Javascript is invalid in a number of ways (you will be seeing errors in the browser tools console) and is defining a function, not executing anything. You may also have other issues in the set-up of your dynamic action that we can't see from your screen shots.
When using dynamic actions you should try to use as little Javascript as possible. In this case you just need a Javascript expression to define the client-side condition:
$v("P8_OPER_TYPE") == "Partial Surrender" && $v("P8_PLAN") == "A"
$v("x") is a shorter way of writing apex.item().getValue("x")
Your dynamic action should look like this:
Then for the action you don't need Javascript, just an Alert action:
If for some reason you really needed to write a Javascript function and call it from the dynamic action, you would define the function in the page "Javascript Function and Global Variable Declaration" section like this:
function cond() {
var item1 = $v("P8_OPER_TYPE");
var item2 = $v("P8_PLAN");
if (item1 == "Partial Surrender" && item2 == "A") {
alert('omar')
}
};
And call it from the dynamic action like this:
cond();

ember validation with if condition not working as expected

I am using dockyard/ember-validation to validate controller properties, but I haven;t been able to get it working as I expected it to. So I have basically toggle effect on checkboxes, and I have defined 2 validation rules and only one of them should be executed/validated when user toggles between the checkboxes.
My validation rules are defined as :
validations: {
"instructions": {
format: {
if: 'inlineSource',
'with': /^(?!\s*$).+/
}
},
"externalSourceValue": {
format: {
if: 'externalSource',
'with': /^(?!\s*$).+/
}
}
}
Here either inlineSource is true or externalSource is true, but both will never be simultaneously true. I would expect only one validation rule to be exercised, but it seems both are getting run disregarding the if condition there.
Here is the jsbin to the issue: http://jsbin.com/ODAmukOM/1/
Follow these steps :
1) click on External Website
2) set the input field value to empty
3) click to Content I Specify
4) the validation sets the controller to invalid state
Thanks,
Dee
you are adding 2 format validations,
instructions is valid if inlineSource && /^(?!\s*$).+/
really your logic needs to be more like this
"instructions": {
format: {
if: function(object, validator) {
console.log('inlineSource',object);
if(!object.get('inlineSource')){
return (object.get('instruction') || '').match(/^(?!\s*$).+/);
}
return true;
}
}
}
unfortunately validation is only run when you change properties, so you change instruction validation is run and it's invalid, you then switch (flipping inlineSource), but validation won't happen again. At this point you'll need to manually run validations to get that validation checked again. good luck

JMeter Response Assertion: incorporating property into pattern test

I'd like to setup a JMeter test plan to suggest whether a web site (URL) is Drupal-based (based completely on the HTTP response from the site) and compare it with existing data that I have on the environment. (I realize that using an HTTP approach, as opposed to say examining the site's file system, is "iffy" but I'm curious how useful the approach is)
The JMeter command line might look like this:
JMeter -t "DrupalAssertions.jmx" -Jurl=http://my.dot.com -Jdrupal=true
where I provide the URL to test and an additional property "drupal" indicating my best guess on whether the site is Drupal-based.
In my test plan, I add an HTTP Request to return the HTML content of the page for the URL. I'm then able to successfully add a Response Assertion that tests a pattern (say (?i)(drupal) for a sadly lacking pattern) to see if it's contained in the response.
That much works fine, or as expected, but what I'd like to do is to compare the value of the "drupal" property against the result of that pattern test in that same Response Assertion. I know I'm missing something simple here, but I'm not seeing how to do that.
I want to try to use an expression like this:
(?i)(drupal) == ${__P(drupal)}
in a pattern, but that doesn't work. The name of the Compare Assertion looks promising, but I don't see how to incorporate the property into a comparison.
Update: The approach suggested by PMD UBIK-INGENIERIE does work. I used a Regular Expression Extractor like this:
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Extract Drupal in Response" enabled="true">
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
<stringProp name="RegexExtractor.refname">drupalInResponse</stringProp>
<stringProp name="RegexExtractor.regex">(.*drupal.*)</stringProp>
<stringProp name="RegexExtractor.template">$0$</stringProp>
<stringProp name="RegexExtractor.default">__false__</stringProp>
<stringProp name="RegexExtractor.match_number">1</stringProp>
</RegexExtractor>
followed by this BeanShell Assertion:
// Variable "drupalInResponse" is "__false__" by default
if ( !(vars.get("drupalInResponse").equals("__false__") ) ) {
vars.put("drupalInResponse","true");
}
else {
vars.put("drupalInResponse","false");
}
print("\n\nThe value of property 'drupal' is: " + props.get("drupal") + "\n");
print("\n\nThe value of variable 'drupalInResponse' is: " + vars.get("drupalInResponse") + "\n");
if (vars.get("drupalInResponse").equals( props.get("drupal") ) ) {
print("Site Drupalness is consistent with your beliefs");
}
else {
print("You're wrong about the site's Drupalness");
Failure = true;
FailureMessage = "Incorrect Drupal assumption";
}
In the Regular Expression Extractor, I'd set a default value that I felt wouldn't be matched by my pattern of interest, then did an ugly verbose Java comparison with the "drupal" property in the BeanShell Assertion.
Wish somehow that the assertion could be made in a single component rather than it having two parts, but you can't argue with "working" :)
You can use a regexp extractir with your first pattern
Then use a Beanshell assertion which will use your variable and compare it to drupal property.

accessing session data

I am setting a custom session in the catalog/controller/checkout/cart.php controller. All it does, it checks if a value is set or not.
if (isset($this->request->post['no_tax']) && $this->request->post['no_tax'] == '1')
{
$this->session->data['no_tax'] = true;
}
elseif (isset($this->request->post['no_tax']) && $this->request->post['no_tax'] === '0')
{
unset($this->session->data['no_tax']);
}
I can then access this in the catalog/model/shipping/totalbased.php model file,
isset($this->session->data['no_tax'])
The problem is, I need to send additioanl information in the order to the admin, which is done in the catalog/model/checkout/order.php
I've done a check in there:
if(isset($this->session->data['no_tax']) )
{
//do something
}
$mail->send();
The do something, simply adds a PDF. The problem is, the PDF isn't attached.
In the error.txt, I get: 2012-05-14 14:42:11 - PHP Notice: Undefined index: no_tax in /var/www/vhosts/site.com/httpdocs/catalog/order.php
Can I access the session this way?
Thanks
The code looks fine from what I can see, and yes you can access the data like you've shown. The error you've had looks like you have tried to access the session data directly at some point without checking it's set, causing the notice