What is the proper way to benchmarking a simple PHP-MySQL website with automated test cases - page-load-time

I am a novice in the area of benchmarking and so would like to request for your guidance.
Problem: I have a test website developed in PHP and MySQL hosted in the localhost.
I need to perform the following set of activities:-
Login as a registered user
Download a PDF file
I wish to know how to load test the above activities in order? I need to check if at a particular instant, 'n' number of users are logged in and they download a pdf file, what would be the worst response time and related stats.
Steps I already did (Please correct me if I did something wrong here.):-
Used the apache benchmarking tool (ab) to load test the login authentication script page passing the username and password as parameters
(i.e., ab -n 1000 -c 100 -A username:password url_of_script.php)
I tested both for apache and nginx webservers (got comparatively better results in nginx)
But, I want to test if after login, the user performs some other activities, how can we use the ab (or some other) tool to assess the load.
Waiting for your responses. Thanks.

Create a PHP script using curl.
Use your Browser to login and and downlaod the PDF.
Before you do that, right click and select Inspect or Inspect Element. Go to the Network tab. Then start the login and download PDF process.
In the Network Tab look only at the request headers of each HTML page request. Filter out all the other requests (e.g. JS CSS images, media and etc.). You can use these headers as a guideline when setting up curl to do each request.
In FireFox you can edit the headers and resend. Go in to the edit mode and copy the request header.
In your curl requests use exactly the the same request the Browser used.
Curl reports all the stats on the request and response.

Related

NI-FI - Issue authenticating to a page to download a file

I'm currently trying to get a .zip file from a webpage using nifi to do it. I am able to generate a direct download link of the file but the application needs to log in into the page before opening the direct link. I've tried using InvokeHTTP, ListWebDAV and FetchWebDAV processors and I was not able to do this properly.
I even tried to add the login and the password as attributes using the same ID used by the page(logon, temp_password).
Also tried going for a Python code but I was not able to get any good results with it.
Every time I tried any of these methods I received a small file on the InvokeHTTP with the download link saying that authorization is required and it downloads a file that is the source code of the login page.
Tried to look in almost everyplace on the internet without much success :/
I'm now trying to get a processor to actually log into the page and keep it that way so the invoke processor can download the zip file using the direct link.
If somebody have another idea on how I can resolve this I will be very grateful.
I can provide more info if needed, at the moment I am using the Ni-Fi 1.1.2
Thanks in advance;
Depending on the authentication mechanism in place by the page, you'll likely need to chain two InvokeHTTP processors together. Assuming the first page has a form field you fill out with the username and password, you'll make one InvokeHTTP which uses the POST method to submit the form with the provided credentials and receives a response that contains some kind of token (session ID, etc.). You will extract this value (either from a response header or the page content), and provide it to the second InvokeHTTP as a request header. Using your browser's Developer Tools feature as daggett suggested to observe the authentication process will allow you to determine exactly where these values are provided.

Test autocomplete in jmeter

I have a search form which would open a list when 2 characters are typed. I would like to measure that time it takes to open and load the list in jmeter. How can I do it?
If you look into your "Network" tab of your favourite browser developer tools you will see that each time you type a letter or digit in the search field the browser sends a HTTP request to the backend server and it responds with search suggestions:
So all you need to do is to simulate these requests using JMeter and measure the response time.
You can even record these requests using HTTP(S) Test Script Recorder, Badboy, JMeter Chrome Extension, whatever
There are two things, I would like to quote:
JMeter is not a browser
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).
From JMeter Wiki
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.
If the page uses Javascript to build up a URL or submit a form, you
can use the Proxy Recording facility to create the necessary sampler.
If this is not possible, then manual inspection of the code may be
needed to determine what the Javascript is doing.
Solution #1
Whenever you type each character, check any service call to the server. This can be captured using browser developer tools > Network tab.
E.g.
If you type iPhone, there will be six service calls to the server. By measuring each call individually, you will be able to understand, how your application behaves under the load.
Again this is a service call, not the UI rendering.
https://example.com?q=i
https://example.com?q=iP
https://example.com?q=iPh
https://example.com?q=iPho
https://example.com?q=iPhon
https://example.com?q=iPhone
Solution #2
By leveraging Selenium WebDriver in your JMeter Test plan, you can measure the end-to-end response time.
Please refer this Blazemeter article and this blog for more details.
Visit JMeter Plugins website and search for Selenium to read more details about Selenium WebDriver.

?_escaped_fragment_= - headless browser

what do I have to do to add a ?_escaped_fragment_= support to my server? I want google to be able to crawl through my ajax site. My hashes are already in #! form
But I have no idea how to tell my server that when I enter mywebsite.com/?_escaped_fragment_=section to my browser so the url mywebsite.com/section and it would be equal to mywebsite.com/#!
thanks
Simple answer - my method (soon to be used for a site with ca. 50,000 AJAX-generated URLs) is to have a node.js server using a headless environment (try zombie, phantomjs, or any other) to load the site, making sure it's able to execute javascript and read the DOM - then at runtime, if it's google requesting the fragment, fire a request to the node.js server, which loads the site, executes the javascript, waits for the response, and delivers back the HTML, which is output to the browser.
If that sounds like a lot of work - I'm about 90% finished on the code that does it all for you, where you'd simply drop one line of (PHP) code at the top of your site/app and it does the rest for you, using a remote node.js server.
The code will be open source so if you want to set it up yourself on a node server, you can - or if it's a PITA to set it up yourself, I'll probably have a live server up and running which your app/website would fire ?_escaped_fragment_ requests to, and get the html snapshot back. It also implements caching so that these are only requested once every X days.
Watch this space - just got a few kinks to work out, and it'll be on my site (josscrowcroft.com) and I'll put it in a github repo too.

How to download a secured webpage

I wish to programmatically download a webpage which requires a log in to view. Is there any sane way of doing this? By looking at HTTP headers and such, I can see the username / password being passed as POST data, but requesting a page with this info attached isn't good enough. I think cookies are involved too, and it looks like they contain some kind of encrypted authorisation data.
Is there any way of faking this? Language isn't too important here, but something like Perl that can be run on Linux with relative ease would be nice. Or maybe a command line browser could be scripted?
Yes, you can do this via the curl command-line tool or the CURL library. You need to figure out what's supposed to be in the cookies, and then pass them with curl's -b option or the equivalent CURL API.
You can also perform HTTP Basic authentication via CURL.
If the page is really sophisticated, you'll have to do HTML parsing or even JS interpretation to extract the cookie data beforehand. That's still doable, but not with CURL alone.
As a general note, anything a web browser can do can be scripted. Turing-completeness and all that. "Unscriptable" captive portals like BlueSocket sells are a load of bunk; they're basically just obfuscated web pages. They'll slow you down but can never, ever stop you - they have to give you the keys in order to work!
Php's CURL would do it. Also check here if this solution is right for you.

Reverse Engineer A Web Form

I have a web site which I download 2-3 MB of raw data from that then feeds into an ETL process to load it into my data mart. Unfortunately the data provider is the US Dept. of Ag (USDA) and they do not allow downloading via FTP. They require that I use a web form to select the elements I want, click through 2-3 screens and eventually click to download the file. I'd like to automate this download process. I am not a web developer but somehow it seems that I should be able to use some tool to tell me exactly what put/get/magic goes from the final request to the server. If I had a tool that said, "pass these parameters to this url and wait for a response" I could then hack something together in Perl to automate this process.
I realize that if I deconstructed all 5 of their pages and read through the JavaScript includes and tapped my heals together 3 times I could get this info from what I have access to. But I want a faster and more direct path that does not require me to manually parse all their JS.
Restatement of the final question: Is there a tool or method that will show clearly what the final request request sent from a web form was and how it was structured?
A tamperer's best friends (these are firefox extensions, you could also use something like Wireshark)
HTTPFox
Tamper Data
Best of luck
Use Fiddler2 as a proxy to see what is being passed back and forth. I've done this with success in other similar circumstances
Home page is here: http://www.fiddler2.com/fiddler2/
As with the other responses, except my tool of choice is Charles
What about using a web testing toolkit, like Watir and Ruby ?
Easy to fill in the forms.. just use the output..
Use WatiN and combine it with WatiN TestRecorder (Google for it)
It can "simulate" a user sitting in front of the browser punching in values which you can supply from your own C# code...

Resources