if(<webelement>.getText() == "Flash_Message_text")
System.out.println(<message to be printed>);
else
System.out.println(<webelement>.getText());
waitFor(3000);
Once I perform an action and it is successful, then a flash message is displayed. As per the above code, I am identifying the flash message and using its text to verify if the action completed successfully or not.
However, it is never executing the "if" part of the code, and it is always printing from the "else" part.
Is there anything I am missing, or is there any other way I can handle this?
Try .equals() instead of == for String Comparison!
Related
What I'm trying to do is hit a service twice in a row with a post of the same data. The idea here is to confirm that I can't have duplicate data, so I should get a 422 and a specific message in the response.
The test looked something like this:
When javaClient.createFoo(parameters)
And javaClient.createFoo(parameters)
Then status 422
And match $.message == "This is a duplicate."
It doesn't have a problem matching the status of the second call, but when I try to match the message (or any part of the response) it compares to the response from the first call.
I've tried making the second call a When, tried checking the status of the first call in between, but there must be something else that I'm missing.
Any ideas? Is there something special I need to do to clear the response?
Unless the method step is called, Karate does not do anything. The use of javaClient.createFoo() (whatever that is) suggests that there are some fundamental problems in your use and understanding of Karate.
I suggest keep it simple and just repeat the method post with the same payload and it should work as you expect.
Also please read this: https://stackoverflow.com/a/54126724/143475
I'd like to perform a while loop using jmeter. Within the loop I'm using xpath extract to pull information from the server response, and storing it in a variable. I'd like to quit the loop if that variable has any data in it (if the request has been successful) - otherwise I'd like to fail if it doesn't respond correctly in x number of attempts. Is this something that JMeter can do?
I found a solution for this
If you know the response that you are trying to extract from Xpath extractor,
With the help of response assertions and while loop its possible..
here is my answer
First of all add a beanshell sampler to the test plan before while loop.
In the beanshell sampler add the following 2 lines
vars.put("counter","1");
vars.put("txtFound","FALSE")
Next Add a While controller with the following condition
${__javaScript("${txtFound}" == "FALSE" && parseInt(${counter})<=3,)}
Above expression evaluates to true if both conditions are true.here 3 represents the number of attempts.
Now in the while loop add your request .
To the same request add a response assertion and add the pattern(the text you are trying to extract using Xpath)
to the same request add a beanshell post processor and copy the following code to it
int counter = Integer.parseInt(vars.get("counter"));
if(counter==3)
vars.put("txtFound","TRUE");
counter++;
vars.put("counter",Integer.toString(counter));
in above code 3 represents number of attempts.
The code will increment number of attempts by one for each iteration and if it reaches max attempts it sets txtFound to TRUE to stop the test.
Add an if condition below the request as shown below
In if loop add a bean shell sampler and set the txtFound value to TRUE as shown below
When response assertion fails if condition will not be executed and if the response assertion passes if condition is set to true and the elements in If will be executed
The test stops if it finds the correct response ant time or it will stop if it reaches max number of attempts
In my case i kept 3 as response assertion so if it finds 3 it will stop or if it reaches max number of 3 attempts
Please follow this link for more information on
while controller
I run some load tests (all endpoints) and we do have a known issue in our code: if multiple POST requests are sent in the same time we do get a duplicate error based on a timestamp field in our database.
All I want to do is to count timeouts (based on the message received "Service is not available. Request timeout") in a variable and accept this as a normal behavior (don't fail the tests).
For now I've added a Response Assertion for this (in order to keep the tests running) but I cannot tell if or how many timeout actually happen.
How can I count this?
Thank you
I would recommend doing this as follows:
Add JSR223 Listener to your Test Plan
Put the following code into "Script" area:
if (prev.getResponseDataAsString().contains('Service is not available. Request timeout')) {
prev.setSampleLabel('False negative')
}
That's it, if sampler will contain Service is not available. Request timeout in the response body - JMeter will change its title to False negative.
You can even mark it as passed by adding prev.setSuccessful(false) line to your script. See Apache Groovy - Why and How You Should Use It article fore more information on what else you can do with Groovy in JMeter tests
If you just need to find out the count based on the response message then you can save the performance results in a csv file using simple data writer (configure for csv only) and then filter csv based on the response message to get the required count. Or you can use Display only "errors" option to get all the errors and then filter out based on the expected error message.
If you need to find out at the runtime then you can use aggregate report listener and use "Errors" checkbox to get the count of failure but this will include other failures also.
But, if you need to get the count at the run time to use it later then it is a different case. I am assuming that it is not the case.
Thanks,
I have an RPG program which prints data with the command DSPLY.
When I call the program,
I can see the printings which appears for a couple of milliseconds,
but it closes right away.
Is there a way in native RPG to make the program wait for input other than using a display file?
Yes, you need to add a response parameter to your DSPLY operation:
/free
dou (response = 'Q');
// dsply 'Q = Quit' '*EXT' response;
// Better to let the RPG runtime determine
// whether to use *EXT (for interactive jobs)
// or QSYSOPR (for batch jobs).
dsply 'Q = Quit' '' response;
if (response <> 'Q');
// your code here
dsply yourvar;
endif;
enddo;
*inlr = *on;
/end-free
Please note - I'm currently unable to test this, I'm just typing the code here straight out of my head.
*Edited to incorporate Barbara's excellent point.
Benny is on the right track, but he left off the response parm.
All you need is:
dsply wMessage *EXT wResponse;
The program will wait till a response is entered. Technically, since any reponse requires enter to be pressed. The user could respond with just enter.
A CL procedure using the Send User Message (SNDUSRMSG) with a default value supplied [Default Reply Value (DFT)] can enable an Inquiry allowing for a pause and just Enter to be pressed to continue. IIRC, even without a default specified, the character string value *N is returned for lack of any input by the user, for which of course a return value of less than two-characters would return only the asterisk; though depending on other setup, that may not be the effect with just Enter, and may instead be seen only with either F11=Delete of the inquiry by the user [or F13=Clear]. Or doing the same code, using whatever message-feature API effects similar; deciding on where to send the message when running as batch vs interactive, might be required by the code using the API vs coding to use SNDUSRMSG for which that feature is built-in.
Note: This usage is of course influenced by the Inquiry Message Reply Handling (INQMSGRPY) setup of the job; e.g. the job could be set auto-reply with the default, such that the inquiry never presents, but that is probably a good thing for consistency/expectation.
I am using simple_captcha in my rails 3 application. I have a form for requesting quote, But in my controller
if simple_captcha_valid?
always returns false.
The log says it gets null key value
SimpleCaptcha::SimpleCaptchaData Load (1.0ms) SELECT `simple_captcha_data`.* FROM `simple_captcha_data` WHERE `simple_captcha_data`.`key` IS NULL LIMIT 1
Please help..
A little late to the party here, but I ran into the same issue and opened a pull request on the repo to make captcha validation idempotent. Seems the captcha entry is deleted the first time you validate it, which is both surprising and obscured by the code (a predicate method calling a bang method internally). Make sure you're not validating your model more than once and you should be OK.