Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Using Perl to Test a Web App that uses Javascript

by coolmichael (Deacon)
on Jun 08, 2004 at 18:03 UTC ( [id://362469]=perlquestion: print w/replies, xml ) Need Help??

coolmichael has asked for the wisdom of the Perl Monks concerning the following question:

I've been given the daunting task of creating a testing framework in Perl. All is good with the world, thanks to WWW::Mechanize by petdance. Everything would be cool, with Test::Harness and friends, except that the web app makes heavy use of javascript. All the forms are verified and submitted with javascript, and a lot of the page layout is done with javascript. I have not had much luck even getting the test scripts to login to the app.

About the application itself: It is written in a combination of VB/ASP/Javascript. I'm only testing the user interface by submitting forms and following links. The app is specific to IE4,5 and 6, but I don't think that should matter too much.

I had thought about trying to combine Javascript and WWW::Mechanize but I don't know where to begin. I would really like to know what sort of experiences other monks have had in a similar situation? How did you begin? Is it even possible? Is there a better tool available?

--
negativespace.net - all things inbetween.

Replies are listed 'Best First'.
Re: Using Perl to Test a Web App that uses Javascript
by perrin (Chancellor) on Jun 08, 2004 at 18:13 UTC
    This has been covered many times before. You don't need to try and run the JavaScript any more than you need to try and render the HTML. The server only sees the HTTP interaction, so all you need to do is mimic what your browser actually sends to the server.

    As it happens, you're in luck, because there is a recent article about how to capture this HTTP interaction with minimal effort:

    http://www.perl.com/pub/a/2004/06/04/recorder.html

      I'm not sure about that. The javascript does more than form processing, it also manipulates the data and sets a couple inputs before submitting the form. I have tried HTTP::Recorder and WWW::Mechanize, but HTTP::Proxy had some problems and didn't work.

      --
      negativespace.net - all things inbetween.

        It doesn't matter what the JavaScript does. All that matters is what eventually gets sent back to the server after the JavaScript finishes. That can be captured and tested with Mechanize, since it's just an HTTP request like any other.
      From the CPAN docs for HTTP::Recorder:

      "HTTP::Recorder won't record Javascript actions, or pages delivered via SSL."
        You're not listening to me. JavaScript is totally irrelevant. It runs on the client, then the client sends an HTTP request to the server. The only thing you have to do to test the server is mimic the end result of running the JavaScript, which will be captured perfectly be HTTP::Recorder.
Re: Using Perl to Test a Web App that uses Javascript
by McMahon (Chaplain) on Jun 08, 2004 at 18:19 UTC
    You're in a tough position.

    Look at Win32::GUITest first, which implements some VB/SendKeys commands better than VB.

    You might also be interested in SAMIE. I've corresponded with SAMIE's maintainer about the small amount of JS support SAMIE offers, he might have made more progress since then.

    Also, search CPAN for JavaScript modules, something there might help. (But I haven't found it yet.) Driving JS interfaces with automation seems to be non-trivial.

    Good luck, hope that helps, I'm very interested in what you come up with!
Re: Using Perl to Test a Web App that uses Javascript
by drewbie (Chaplain) on Jun 08, 2004 at 18:12 UTC
    To the best of my knowledge there is no way to do this currently, although many have asked for it. The primary problem is that Javascript doesn't support the DOM, which is necessary for what you want to do. You might be better off using one of the windows-specific QA tools like WinRunner, etc.

    That said, if you know the final form layout and list of elements you might be able to hack something w/ WWW::Mechanize by manually setting the various elements to the proper values. Check out the methods for setting form element values and submitting forms.

    Good luck! Let us know what you find. IIRC Andy will be giving a testing talk at YAPC::NA next week that might be helpful.

Re: Using Perl to Test a Web App that uses Javascript
by PodMaster (Abbot) on Jun 09, 2004 at 05:47 UTC
Re: Using Perl to Test a Web App that uses Javascript
by vek (Prior) on Jun 08, 2004 at 18:53 UTC

    You can only use modules like WWW::Mechanize or HTTP::Recorder for interacting direcly with the webserver. If that's all you need to test then you should be all set.

    If you actually need to test the javascript itself then you are in for a tough time unfortunately. Javascript runs inside your browser and I know of no way to emulate that in Perl.

    -- vek --
Re: Using Perl to Test a Web App that uses Javascript
by tomhukins (Curate) on Jun 08, 2004 at 21:16 UTC

    Before you write tests, determine your goals. Your tests must derive from and serve your goals, otherwise they lack purpose.

    If your goals include security against potential attacks, you should test for invalid and implausible parameters at the server, regardless of any client-side (JavaScript) constraints you have.

    Remember, client side validation may be disabled. Server side validation is always enabled.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://362469]
Approved by monktim
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found