J-Meter gives false results - automation

I'm trying to learn J-Meter.
When I'm running a sample script of logging into a site using both valid/invalid credentials,it doesn't stop thread execution when invalid login credential is used and also login is not recorded in database.
Does it actually login to the website or only creates virtual login to create a similar environment.Is there any way to achieve this using Samplers?

JMeter is/acts as a headless browser.
Whatever your browser with an UI does, JMeter can also do - except executing a javascript. So, If you had recorded your script correctly - JMeter can login to the actual application as well.
Jmeter is not like QTP/Selenium. It does not know if it is a valid credential/invalid credential. It passes/fails the request based on the HTTP codes. If the HTML response from the server comes with a 200 http code, It passed for JMeter. If the server responds with code 500, JMeter fails the request. But JMeter also provides a way to validate the response you get - Assertion. You can use Response Assertion to see if you are seeing the home page or not to confirm if the user has logged in successfully.
To stop the test on error, select the appropriate option here in thread Group properties.
JMeter is a very nice tool & have been using it for 2 years with no issues.
Good luck!

Does your script have Config Element -> HTTP Cookie Manager? It needs cookie for the login function.
If your script has many transactions with the same level with login transaction and the option you select in your Thread Group is Continue, all transactions will be executed no matter login transaction is passed or failed.
In case you want the other transactions will not be executed if login fails, let add a Regular Expression Extractor as child of the login transaction to retrieve the text Dashboard, put other transactions into a Logic Controller -> If Controller. Suppose the Regular Expression Extractor has name Dashboard and Default value is NotFound, then the Condition of If Controller will be "${Dashboard}"!="NotFound"

JMeter automatically treats 2xx and 3xx HTTP Response Codes successful so it won't be able to detect failed login unless you explicitly tell it to check presence or absence of some specific content in the response data.
So if you add a Response Assertion you will be able to conditionally fail sampler and choose what to do in case of failure via "Action to be taken after a Sampler error" on Thread Group level.
See How to Use JMeter Assertions in Three Easy Steps guide for more details on the assertions domain.
If you're unsure what JMeter Sampler is doing you can check request and response details via View Results Tree listener. If you cannot simulate login event in majority of cases it is due to missing HTTP Cookie Manager and/or failed correlation of dynamic mandatory parameter(s) like Viewstate, CSRF token, etc.

Related

Unable to fetch the token from another thread group in Jmeter

In HTTP Request, I gave login credentials then login got success, access_token generated.
Then by using JSON Extractor, I extracted the access_token and name as "auth_token".
Then in Beanshell Assertion, I added script "${__setProperty(auth_token, ${auth_token})};"
Then in HTTP Request Defaults, I added Parameter "Authorization" "${__property(auth_token)}" (in Test Plan level)
I cannot fetch that token in Thread_group-2, which is generated in Thread_group-1.
suggestions, please??
You need to ensure that the Thread Group which extracts the token is executed before the Thread Group which uses the token, either tick "Run Thread Groups consecutively" on Test Plan level:
or switch to setUp Thread Group which is being executed before all "main" Thread Groups
In general you should not be passing values between Thread Groups as thread group represents a logical group of business users and authentication/authorization is an integral part of the business flow so my expectation is that you need to have authentication and other actions in the single Thread Group. If you want to perform authentication only once - put it under Once Only Controller
Using Beanshell is kind of a performance anti-pattern, consider moving to JSR223 Test Elements instead.
I also have doubts regarding correctness of your token usage, I think you should rather use HTTP Header Manager instead and configure it to pass Authorization header with the value of Bearer followed by whitespace followed by your token

Getting generic page error in response, using JMeter in .NET site

When using .Net application,
and checking error logs,
getting below error: Object reference not set to an instance of an object.
Most probably you're sending the wrong request due to missing or improperly implemented correlation
So if you have recorded a request using HTTP(S) Test Script Recorder most probably there is at least one parameter there which is supposed to be dynamic, to wit
extracted from the previous response using a suitable JMeter Post-Processor
stored into a JMeter Variable
and the dynamic variable to be sent along with the request instead of recorded hard-coded value
In .NET web applications the most commonly used parameter is ViewState, however other may also be required like EventValidation
so given you properly handle these dynamic parameters you should start getting "good" responses, see ASP.NET Login Testing with JMeter for example handling of the dynamic parameters.
Also don't forget to add HTTP Cookie Manager to your test plan.

Same response data for all iterations even though cookie is cleared

My Test structure in Jmeter
Thread group (2 users)
Http request
Listener
For each iteration same form_key values are getting in response which should not be.
How to get unique form_key in response for each iteration
Jmeter Test result screenshot
I cannot reproduce your issue using one of the online Magento demo instances, in particular this one: http://demo-acm-2.bird.eu/customer/account/login/
As you can see, each time form_key is different for each user for each iteration.
If you're using HTTP Cookie Manager - make sure to tick "Clear cookies each iteration" box
Also make sure to properly setup the HTTP Request sampler, to wit put http or https into "Protocol", server name or IP to the relevant field, path, etc.

Automated Debugging of failed API test cases

Our application has 35 web servers and around 100 different APIs being executed on it.
These APIs internally calls each other and execute independently as well.
We have automated test cases of around 30 APIs but some of our tests fail because the other APIs fail on which the API under test depends.
So how can we know through our automated test cases the reason for each test failure?
Example Scenario:
We have a test case to validate the API to fetch the User's Bank account balance.
Now we hit this API through rest Assured and tries to assert the expected output. This request goes first to the ledger server which further internally hits auth server to validate the request authenticity, then hits, then hits a counter server to log fetchBalance request, then hits several other servers to get the correct balance of the user and then responds to our request.
But the problem is that this may break at any instance and if it breaks, the ledger server returns always same error string- "Something failed underhood". Now debugging becomes a challenge. We have to go to each server and have to search for the logs to know the actual cause.
I want to write a solution which can trace complete lifecycle of this request and can report where it actually failed.
For this problem, you should be aware of the most common failure reasons. And then you can implement the strategy bases on the failure reasons.
Example: If you have send one request to the server that API may have some security validations and some processing steps and integration with different components.
If you can identify some failure points and can implement checkpoints against that.
Request failed at Security validation. You have possible error codes for that then write logic according to that
You have a failure at the processing step there could be a possible reason
If there is a failure at the integration point then there must be some error codes also. You can implement logic around them
Validate the state of data before each interaction with server. For example
assert expression1 : expression2
Where expression2 will be executed if expression1 fails. (This is a Groovy example, but you can modify this as needed.)
An example expression2 message could be something like: "Failure occured when trying to send 'so-and-so' request!".

Handling dynamic http requests instead of hardcoded http requests in Jmeter

I'm creating a 50 users load test on a JSF web application.
I record a scenario using JMeter proxy for one user who logs in, does some db operations and logs out. After recording the scenario, the recorded test contains http requests and data that particularly belongs to the user used while scenario recording.
At the time of running the test for 50 unique virtual users, the recorded test sends http requests and data which was in the recorded scenario. But in our application, the http requests and data vary depending upon the user. So how do I handle such situations in JMeter when it comes to methods being called depending upon the existence or non-existence of data for a user after logging in?
To be precise how would I make changes in my Test plan to manage dynamic urls and dynamic data for each virtual user?
Latest versions of JMeter allow you to write the whole parameters (raw data) from scratch, so you could use variables in this field.
To achieve dynamic URLs use a Regular Expression Extractor (Post-Processor) on a prior request that define what request will be sent and use the variable in HTTP Request's path field.
If you know what request each type of users will send you could use If Controllers and test a thread variable, created by a previous Regular Expression Extractor, and inside each controller add the specific request.
If the subsequent request for each user is defined by the server, using redirection, just check "Follow Redirection" field.
See JMeter Wiki for more examples on how to do this.