views:

443

answers:

5

In the bad old days of interactive console applications, Don Libes created a tool called Expect, which enabled you to write Tcl scripts that interacted with these applications, much as a user would. Expect had two tremendous benefits:

  • It was possible to script interactions that otherwise would have had to be repeated by hand, tediously. A classic example was dialup Internet access hell (from the days before PPP).

  • It was possible to write scripts to test one's own interactive applications, programmatically, as part of a regression suite.

Today most interactive applications are on the web, not on the console. Hence my question: is there any tool that provides the ability to interact with web pages and web forms programmatically, much as Expect provides the ability to interact with console applications programmatically?

(The closest thing I am aware of is Chickenfoot.)

+8  A: 

You might be looking for Selenium

Logan Capaldo
+5  A: 

I've used Selenium RC in conjunction with Python to drive web page interactions programmatically. This has allowed me to write pretty extensive user tests in which forms and inputs are driven and their results are measured.

Check out the Selenium IDE on Firefox (as mentioned above). It allows you to record tests in the browser and play them back, either using the IDE itself, or the Remote Control app.

bedwyr
+5  A: 

Perl Mechanize works pretty well for this exact issue.

HTTPS and some authentication issues are tricky at times. I will be posting couple questions about those in the future.

Ville M
I browsed the link---is there any, dare I ask, "user friendly" documentation?
Norman Ramsey
Mechanize is great, but you have to realize it's not so much analogous to Expect as it is to the terminal. Err that was an awful analogy. Let's try this: Mechanize doesn't automate a browser, Mechanize is a (programmable) browser. If you understand that it can be very powerful, err I'm out of space.
Logan Capaldo
Yeah, that's a good point, that's probably why it gets little tricky where the page is very complex since it may look one way on firefox etc, but mechanize sees the page "mechanize" way. But anyways, it's often a breeze to program with as well.
Ville M
my $agent = WWW::Mechanize->new(); $agent->get('http://www.livejournal.com/login.bml'); $agent->form_number('3'); $agent->field('user',$form->{user}); $agent->field('password',$form->{password}); $agent->submit();
Ville M
+1  A: 

In addition to Selenium, if you're doing the Ruby/Rails thing, there's Webrat.

Jim Puls
I want to interact with arbitrary sites. It sounds like Webrat is only for sites implemented in Ruby where I have access to the source code. Correct?
Norman Ramsey
+5  A: 

I did a ton of Expect work in a former life and always thought Don Libes' Expect book was one of the best-written and most enlightening technical books I'd ever seen.

Hands down I would say that Perl's WWW::Mechanize library is what you want. I note above that you were having trouble finding documentation. There is good documentation for it! Look up the module's distribution on search.cpan.org and see what all is packaged with it. There's a FAQ, Cookbook with examples, etc. Plus I've always been able to get help on the web. If you can't get it here, try at use.perl.org or perlmonks.org. WWW::Mechanize's author, Andy Lester, is present on Stack Overflow. (He's also an all around friendly and helpful guy.)

I believe WWW::Mechanize also has a program that is analogous to Expect's autoexpect program: you set up a proxy process running this program as a server, point your browser to it as a proxy, perform the actions you want to automate, and then the proxy program gives you a WWW::Mechanize program for you to use as a base for your project. (If it works like autoexpect, you will certainly want to make modifications from there.)

As mentioned above, WWW::Mechanize is a browser (to be more exact, it is a web client or http client) that happens to be programmable. The last time I looked, there was even work in progress to make it support JavaScript.

skiphoppy