Reputation: 41
I am learning JMeter. In my assignment I need to load a test URL but the test URL actually redirects to a different URL. When I try to check the 'View Result Tree' in HTML format I dont see anything loaded but 'Sampler Result' is 200 OK.
I get following Response data
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
</head>
<script type="text/javascript">
var externalURL = "cat04-partner-external.napgsys.com".toLowerCase();
internalUrl = "cat04-partner.napgsys.com".toLowerCase();
$(document).ready(function () {
if(window.location.href.indexOf(externalURL) > -1) {
window.location.href = window.location.href +"sso/login/#/login2";
}
else{
window.location.href = window.location.href +"sso/login/#/login";
}
});
</script>
<!--<META http-equiv="refresh" content="0;URL=/sso">-->
</html>
I tried 'Redirect Automatically' and 'Follow Redirects' but nothing helps. How to make sure it redirects to the correct URL and I can verify in the HTML whether the correct test URL gets loaded.
Upvotes: 2
Views: 5109
Reputation: 13960
The options you tried ('Redirect Automatically' and 'Follow Redirects') are for the applications that redirect on the server side, but your application redirects on client side, using JavaScript code, while JMeter's HTTP sampler operates on HTTP level and does not run any JavaScript code:
Does JMeter process dynamic pages (e.g. Javascript and applets)?
No. JMeter does not process Javascript or applets embedded in HTML pages.
JMeter can download the relevant resources (some embedded resources are downloaded automatically if the correct options are set), but it does not process the HTML and execute any Javascript functions.
So you have 3 options:
Option 1: Pretend redirect happened:
This advantage of this method is that it is easy to implement, is completely sufficient for performance testing, and allows you to control how many users / iterations go to each redirect link (e.g. you could add "Random" controller to get users to randomly go to either login
or login2
, or Throughput controller to redirect certain percentage of users to login
and the rest to login2
).
The disadvantage which could be perceived by some is that if you want to also test you JS code, you won't. But JMeter in general is not for client-side testing, so that is not really a disadvantage of this method, but a disadvantage of using JMeter for functional testing.
Here's an example of such plan:
After first request, we are checking that response page contains login redirection (this is one way to check it, there are many other ways of course). If it does, the request is presumed to be successful.
Then Random controller ensures that each time we choose either login
or login2
. Randomly. Of course instead of Random controller, you could use any other controller, based on the needs.
Option 2: Use Selenium WebDriver Sampler
Basically you will create selenium tests, and run them in JMeter:
Web Driver Sampler automates the execution and collection of Performance metrics on the Browser (client-side). A large part of performance testing, up to this point, has been on the server side of things. However, with the advancement of technology, HTML5, JS and CSS improvements, more and more logic and behaviour have been pushed down to the client. This adds to the overall perceived performance of website/webapp, but this metric is not available in JMeter. Things that add to the overall browser execution time may include:
- Client-side Javascript execution - eg. AJAX, JS templates
- CSS transforms - eg. 3D matrix transforms, animations
- 3rd party plugins - eg. Facebook like, Double click ads, site analytics, etc
The advantage is outlined above. The disadvantage is that Selenium samplers are not as scalable as HTTP samplers, and cannot stress server as efficient as HTTP samplers. They also need a lot more maintenance as any UI-based tests.
Option 3: Combine both methods
Have most threads running HTTP samplers, and few measuring end-user experience with Selenium samplers. This provides best coverage, but of course requires a larger investment in creating and maintaining them.
Upvotes: 4