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 | [reply] |
|
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.
| [reply] |
|
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.
| [reply] |
|
From the CPAN docs for HTTP::Recorder:
"HTTP::Recorder won't record Javascript actions, or pages delivered via SSL."
| [reply] |
|
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.
| [reply] |
|
|
|
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!
| [reply] |
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. | [reply] |
Re: Using Perl to Test a Web App that uses Javascript
by PodMaster (Abbot) on Jun 09, 2004 at 05:47 UTC
|
| [reply] [d/l] |
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.
| [reply] |
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.
| [reply] |