I'm trying to automate the login to a website and submission of a form.
Is there a browser plugin (for firefox or Chrome) that allows you to record HTTP GET and POST requests in a form that allows them to be played back at a later point? I'm looking for something that will be possible to automate from a script e.g. via curl or wget.
I've tried using the Chrome developer tools to capture POST form data but I get errors when trying to replicate the request with wget which suggests I'm missing some cookies or other parameters. Ideally there would a nice automated way of doing this rather than doing lots of trial and error.
There are way too many methods for you to choose.
Use Firefox and selenium IDE. It can record your browser action
User selenium Web Driver. It can simulate different browser action by the script you write in Ruby or Java.
Use a macro plugin for Firefox to simulate absolute clicks and keypresses.
Use a OS level macro application and do the same as 3.
Write a script (such as PHP) to simulate the actual form post or cookie interations.
No.1 is common and easy to use. No.4 can be powerful but you need time to polish the automation.
No.3 is in the middle of No.4 and No.1. No.2 can be a tool for environment test and stress test also. No.5 is seeming the most flexible and resource saving.
For a simple interaction, you don't really need a tool like Selenium that will record and playback requests.
You only need the tools you've already mentioned:
curl
andwget
support cookies and POST data, but I've only tried curl for automation.There are several key steps that need to be done properly (this takes some experience):
curl
andwget
that will ensure that cookies and redirects are properly processed.Here's a sample of 3 curl calls that I wrote for an automation script that I wrote to download broadband usage from my ISP:
Note the careful use of
--cookie-jar
,--cookie
, and--location
. Thesleep
s,--user-agent
, and--referer
may not be necessary (the backend may not check) but they're simple enough that I include them to minimize the chance of errors.In this example, I was lucky that there were no dynamic POST fields, e.g. anti-CSRF nonce fields, that I would have had to extract and pass on to a subsequent request. That's because this automation is for authentication. For automating other types of web interactions, after the user's already logged in, you're likely to run into more of these dynamically-generated fields.
Firefox Firebug already has a feature which allows you to copy a web request as a curl request, so you see all the various elements of the request on the command line.
Turn on the Firebug and right click on a request in the Net panel and pick Copy as cURL. Then use it in the
curl
https://hacks.mozilla.org/2013/08/firebug-1-12-new-features/#copyAsCURL