Im newbie to jmeter and Im stuck in a situation. Altough scenario is simple but like i said Im newbie to Jmeter.
I have to request a webpage.
In response I will receive an HTML file which will contain a java script code.
I have confirm some string present in that javascript code
I know I can do this with the help of seleium webdriver and I already done it so far but I need to run this test multiple times.
and as far as JMeter goes it discard any scrip present in response. So please help me out
JMeter will not run Javascript. That doesn't mean that it will ignore it.
Add a Response Assertion to your HTTP Request Sampler (right click on it, Add -> Assertions -> Response Assertion). This will let you add Strings and Assert that that String exists in the Response (NB: unlike, for instance, C++, an assertion here won't stop your test, it will only make that Sampler an error).
To use the Response Assertion, switch the Radio Button to Contains and click Add at the bottom center. In the new box that shows up in the center, add the "some string present in that javascript code."
First of all in your HTTP request sampler, you should select an option, 'Retrieve all embedded resources', after this jmeter will retrieve all resources like css,js,graphics etc.
Also you might want to take a look at http://jmeter-plugins.org/
This library contains some really cool plugins for jmeter testing.
You should look for some kind of Post Processors and add that to your test script. These can be used to extract some particular resources from retrieved data.
Also, one unrelated advice because you are new, Do not add Many/Any Listeners to your jmeter test plan.
From JMeter Project Main Page
JMeter is not a browser
JMeter is not a browser. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever viewed at a time).
JMeter acts on protocol level, of your JavaScript is doing something local - you can duplicate the logic using JSR223 Test Elements
If JavaScript is used to send a request - you can mimic the request using JMeter, JMeter doesn't execute JavaScript but it is able to record and replay JavaScript-driven requests with HTTP(S) Test Script Recorder and HTTP Request samplers
If you're trying to load test an application which is AJAX-based and you need to simulate the requests from real browser (i.e. asynchronous, several requests at a time triggered by opening the page, etc) - you will need to do some extra work as JMeter doesn't provide any test elements to jump over defined virtual users defined on Thread Group level. There are several techniques on testing AJAX applications with JMeter, see How to Load Test AJAX/XHR Enabled Sites With JMeter guide for more details
Related
I am facing an issue in simulating below scenario in JMeter script. Appreciate if anyone of you can help with a solution.
I am trying to create JMeter script for a form submission flow which is a .NET application. One of the HTTP Request Samplers is getting redirected to a different HTTP request. JMeter script replay is able to redirect to correct HTTP request; however, it doesn’t provide required HTTP response.
It fails with the message – “Please enable JavaScript to view the page content. Your support ID is: 7865380748200702010”
While recording the script, it gives proper response with .net variables such as View State, View State Generator, Event Validation etc.
Please help me if you have got this earlier.
Most probably you're not sending the right requests because your script is missing or doesn't have properly implemented correlation of the dynamic parameters
In the vast majority of cases you won't be able to replay the recorded test scenario, in your case due to incorrect hard-coded recorded values of these View State, View State Generator, Event Validation, etc.
While browser is sending these variables automatically for JMeter you need to extract them from the previous response using a suitable PostProcessor (I would recommend CSS Selector Extractor), convert them into JMeter Variables and replace hard-coded values with the variables. You can see ASP.NET Login Testing with JMeter article for example correlation of these .NET web applications dynamic parameters.
With regards to JavaScript in general, as per Apache JMeter project main page
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
so if a part of your page is being loaded by JavaScript (i.e. using AJAX technology) JMeter again won't execute this request automatically, you will need to properly simulate it
I'm not new in load testing. My job is to create a load testing with jmeter. I did not bother with tread number, clients, memory consumption ,etc. For jmeter load testing i used 3 client , each of them run 1000 threads (30% CPU was used), results were expected all the time. No problems were detected on SUT or clients.
I'm put before new challenge. Now i have to execute web performance testing on browsers.I don't know if i create a correct picture about performance testing.
I want to measure, first byte, load time on web page, java script, Ajax, etc,...
Web automation tests are written in selenium. Selenium is not mentioned for web load testing.
Lets say to simulate 1.000 users clicking ob browser, this means a lot of VM, collecting results from browsers(DOM counters), SUT is managed by PS script to take data from perf. counters. I see a problem a lot of VM means also financial budget which i do not have.
I'm in doubt if the upper approach is correct or should change my approach.
One of these tools is Visual Studio Ultimate edition. But i still need a lot of VM to simulate 1,000 users - browsers.
On the internet i read a documents, descriptions, top tools.
How do you do changeling web page performance testing on you company.
Any help about web page performance will be appreciated.
Thanks,
Dani
Well-behaved JMeter script must look exactly like real browser does from the server's perspective, just make sure you properly handle the next few bits:
Embedded resources via "Advanced" tab of the HTTP Request Defaults
Cache via HTTP Cache Manager
Cookies via HTTP Cookie Manager
Headers via HTTP Header Manager
AJAX requests via Parallel Controller
See How to make JMeter behave more like a real browser article for more details.
Assuming all above you should be able to mimic the load on HTTP protocol level. If you need to measure rendering or JS execution speed additionally you can add another Thread Group with 1 (or several threads) and use WebDriver Sampler which provides JMeter integration with Selenium. Additionally you can collect some extended stats using i.e. Navigation Timing API via WDS.browser.executeScript() method allowing execution of arbitrary JavaScript code.
After experimenting with scripts on facebook.com, I noticed that for a couple of minutes it didn't allow me to connect to facebook.com. This happened more than one time so I suspect that Facebook doesn't like to mess with their code using userscripts.
The Stack Overflow question Can a website know if I am running a userscript? answers the multiple ways a website can detect scripts.
Now I want to know how I can fool a website to not detect any scripts I may be running.
Is there a way to know what my userscript HTML changes trigger on the website?
For Firefox and Chrome there is no magic bullet to prevent detection, it is a process and an art...
The 3 principle ways that a site would detect a script are:
Out of sequence or too-frequent AJAX requests.
Changes to the page's code (HTML, global JS, or even CSS).
Unnatural mouse or keyboard action.
See "Can a website know if I am running a userscript?" for more information.
Some countermeasures:
For AJAX requests that your script makes:
Use Wireshark, or similar, to analyze the traffic of normal AJAX calls. Make sure that you send the same type of calls, in the same order.
Make sure that your requests show the same headers and data as the page's.
Do not send AJAX requests faster than the page does normally or faster than a user could reasonably trigger.
Consider adding random delays to your script's requests, so that they are not uniformly timed.
Beware of constantly changing fields in the page's requests. Be sure that you know how to generate the correct value; don't just cut and paste.
For changes that you make to the page's code:
The page can handle these either entirely locally, with it's own javascript, or it can also send back status or code fragments to the server.
Block and replace the page's javascript. Tools like NoScript, RequestPolicy, firewalls and proxies can be used to block the JS.
Then use Greasemonkey to add your edited version of the page's JS. Greasemonkey will run even if all of a page's JS is disabled.
If the page phones status home, and that status changes in response to your script's changes, Intercept and replace those messages. (This is not needed if you used the previous method.) You will need a custom firewall, proxy, or router to do this.
For events that you trigger (mouse clicks, filling out fields, etc.):
If the page checks for this, give it what it looks for. For example, instead of a click event, you may need a mouseover, mousedown, mouseup, mouseout sequence.
If that is not enough, then the countermeasures are the same as for changes made to the page's code (replace JS, intercept status messages).
Important!
In the rare event that you are battling a site that tries to thwart userscripts, it is like a war. The webmaster can adapt to what you are doing, and the environment can constantly change. So scripting for such a site is an ongoing process.
Scripts are executed on user's side - your side. Therefore site's server code cannot know if you run anything or not.
There's two things to note however:
Site can deliver some script to be run on your computer that will inspect its environment and will report back if necessary. Those are most often targeted to detect some specific script that site owner don't want to have in its environment.
Site author can inspect your requests and analyze if they don't match patterns that would match regular communication from site supplied forms or AJAX. Missing keys or keys not matching hardcoded order in query, headers that identify automation clients or missing browser headers and things like that. Hitting throttling limits if you do requests automatically much faster than human user should fits this category too.
Otherwise if you generate exactly the same responses and don't leave traces in globally accessible environment, it is impossible for site to tell if you're using userscript with either server or client side checks.
I want to have a "control panel" on a website, and when a button is pressed, I want it to run a command on the server (my computer). The panel is to run different python scripts I wrote (one script for each button), and I want to run the panel on my Mac, my iPod touch, and my wii. The best way I see for this is a website, since they all have browsers. Is there a javascript or something to run a command on my computer whenever the button is pressed?
EDIT: I heard AJAX might work for server-based things like this, but I have no idea how to do that. Is there like a 'system' block or something I can use?
Here are three options:
Have each button submit a form with the name of the script in a hidden field. The server will receive the form parameters and can then branch off to run the appropriate script.
Have each button hooked to it's own unique URL and use javascript on the button click to just set window.location to that new URL. Your server will receive that URL and can decide which script to run based on the URL. You could even just use a link on the web page with no javascript.
Use Ajax to issue a unique URL to your server. This is essentially the same (from the server's point of view) as the previous two options. The main difference is that the web browser doesn't change what URL it's pointing to. The ajax call just directs the server to do something and return some data which the host web page can then do whatever it wants with.
On the client side (the browser), you can do it with the simplest approach. Just an html form. javascript would make it nicer for validation and to do ajax calls so the page doesnt have to refresh. But your main focus is handling it on the server. You could receive the form request in the language of your choice. If you are already running python, you could write a super fast cgi python script. Look at the cgi module for python. You would need to put this into the apache server on osx if thats where you will host it.
Unfortunately, your question about exactly how to write it is beyond the scope of a simple answer. But google for how to write and html form, or look at maybe jquery to build a quick form that can make ajax calls easily.
Then search for how to use the python cgi module and receive POST requests.
Javascript is basically for doing work in the browser (usually to render something nice for the end user to look at). What you want (as others have said already) is a way to connect an HTML form action to an action on the webserver "back end". And this is exactly (as RobG has pointed out) what CGI is for. An alternative to CGI which is quite popular with Apache users is mod_python - the difference is basically whether the "back end" operation runs as a standalone process (CGI) or inside a webserver process (mod_python), but for most basic applications your server side scripts don't need to care. And if you're in a shared hosting environment you may not have a choice - ask your sysadmin (or read your hosting service docs) to learn how best to run CGI scripts in this case.
Caveats:
You will probably need fairly elevated webserver admin access & expertise in order to get everything set up the way you want. You will at least need to be able (both in the sense of permissions and technical understanding) to view your webserver logs, edit your webserver configs and bounce (restart) your http service.
Whatever "back end" operations you want done will be done with the permissions/privileges of the webserver, which may not be the same as the permissions/privileges of the user account which you normally use to perform these operations. There are various ways around this (using custom daemons and/or sudo operations), but you really need to have a clear understanding with the webserver sysadmin (if the webserver is exposed to the Big Bad Internet) about how this is going to work before you deploy anything, otherwise you run the very real risk (especially if you are a noob) of making it possible for hackers to exploit your "command gateway" to hack the webserver.
Of course if you're just doing all this for fun on your personal laptop (there is an OSX tag on the question, after all), then you are the webserver sysadmin, and you're free to hack away and happily shoot yourself in the foot repeatedly while learning everything you need to know along the way, which is fine as long as you're not on a network. In this case, you may find this tutorial to be useful.
This is a followup question to the one here
Here's briefly what I am trying to do. The File server creates a text file to indicate an end of the process. On a webpage on the Web Server, I loop every x seconds and make an ajax request to find out if the test file exists (ajax request to http://fileserver/files/UserFile.txt)
I've tried the following approaches so far:
Trigger a web method from the client side that creates a HttpContext object to verify if the text file exists. But this is too strenous on the server and I started getting all kinds of exceptions in the Event Viewer.
YQL works great but unfortunately it's too slow. The user waits atleast twice the amount of time.
I am looking for a solution that doesn't involve the server side. Somehow, I'd like to use JQuery to verify the existence of a text file on the fileserver.
Any thoughts?
You should be able to use JSONP and JQuery.ajax() to do cross-domain request work. Play with the jsonp and jsonpCallback attributes. Alternatively, you can use JQuery.getJSON().
Serving a single file from the filesystem is the most simple operation a web server can do. If that is already too much, then all other solutions will be worse. Find out why the server takes so long to serve a simple file and fix that.
Note: I'm assuming that the file is small since you say "test file". If it's a big file, the server will actually send it to the client which will need a lot of resources.
What you can try is to add an ASP page to the web site which runs code on the server that checks whether the file is there and just returns a tiny piece of HTML which you can add to the page with jQuery.load().
I may be miles off base here but... could you not create ONE asynchronous (!) Ajax client request with a HUMONGOUS timeout. Fire it, and wait. You would be invoking some server script that checks every so often, in a loop on the server (using sleep in between), whether the file exists. And not replying to the Ajax request until the file finally shows. The server script then replies and exits.
EDIT: Depending on the server-side scripting framework used, you may even get some OS support. You may be able to sleep on a status change in the directory...