Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl HTML Submit Form Data - Testing

Posted on 2011-03-10
8
Medium Priority
?
478 Views
Last Modified: 2012-05-11
Situation: I have multiple websites with multiple forms each. I would like to create a script that will submit the form data to the server script so I don't have to open a browser and fill out the form to test. I know how to do this part...

My question is...

Is there an easy way to load the form fields and data into the script?

I was going to create a config file (tab delimited or something) with the form fields and data that I could parse and use to submit. Then I thought well I could save the page (after filling the form out) and parse the fields and values from it. This way I don't have to type everything... just the values into the form (once).

Is there any better ways to do this?
Are there possibly any cpan modules or anything that makes this type of testing easier??


Just looking for advice and more knowledge!

Thanks in advance!
0
Comment
Question by:kindaprog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Accepted Solution

by:
notjames earned 576 total points
ID: 35105095
Not sure about CPAN modules. I'm sure there's something out there in the wild.

So I'm assuming you know the fields you want to fill out per form? This is pretty easy. You don't really need a complicated Perl script unless you want to find some way to automate determining the form fields and the values for those form fields and then submitting.

I recommend creating a shell script that calls wget with the params to each form for each site. You infer that the values will probably never change. So, creating a file that has the URI's with the accompanying fields and values would be easy to create and simply read in a looped fashion calling wget per line. IE

URI FILE...let's call it form_uris.txt

'http://myhost1.com/application1.cgi?field1=value1&field2=value2'
'http://myhost2.com/application2.cgi?field1=value1&field2=value2'
'http://myhost3.com/application3.cgi?field1=value1&field2=value2'

Your shell Script:
#!/bin/sh

INFILE='/path/to/form_uris.txt'
OUTFILE='/path/to/output.txt'

while read line
do
    wget $line >> $OUTFILE
    echo >> $OUTFILE # separate output with a \n
done < $INFILE

....

Anyway, this is just one of millions of ways to do this.
0
 
LVL 20

Assisted Solution

by:Mark Brady
Mark Brady earned 572 total points
ID: 35107554
I do this when I'm testing forms especially large ones.

Create a javscript function to fill your form out for you and on the pages <body> tag run that function.
<body onload="fillMyForm()">

Then in the head section

function fillMyForm()
{
document.getElementById('firstname').value = 'John'; // etc...etc...
}
0
 
LVL 1

Assisted Solution

by:notjames
notjames earned 576 total points
ID: 35113116
@elvin66: The only problem with your solution, though not a bad solution, is that I believe the OP was inferring the use of a back-end solution, while your solution requires a client-side solution.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Assisted Solution

by:Mark Brady
Mark Brady earned 572 total points
ID: 35113136
Fair comment. You can do the exact same thing using php. Create the form in a php variable and put values into the "value=" fields. When they echo the table it will be filled in.
0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 852 total points
ID: 35122586
Is the lack of need for basic authentication the only difference between this question and your other practically identical one a few weeks ago?

What do you need to do once the script does the submission?  Do you need to save the returned html in one or more files, as notjames is doing, or do you want the script to process the returned html, or do you simply need to know if the submission was successful?

Since you posted this question in the Perl area and specified Perl as the language of choice in the subject, I'll direct you to a Peerl solution.

The module I'd use for the submission is LWP::Simple
http://search.cpan.org/~gaas/libwww-perl-6.01/lib/LWP/Simple.pm

For now I'll make the same assumption as notjames did about the content of your config file.

#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;

my $config_file = '/path/to/config.txt';

open my $fh, '<', $config_file or die "failed to open <$config_file> $!";

while ( my $url = <$fh> ) {
    
    chomp $url;
    
    # if you want to save the returned page, use getstore() instead of head()
    my $rc = head($url);
    
    if ( is_success($rc) ) {
        print "successful: $url\n";
    }
    else {
        print "failed: $url";
    }
}
close $fh;

Open in new window

0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 852 total points
ID: 35122622
I forgot that the head() function doesn't return the status code, like most of the other functions.  So, if you use the head function, you'll need to adjust it a little.

my ($content_type, $document_length, $modified_time, $expires, $server)  = head($url);

And the test for success/failure would also need to be adjusted accordingly.
0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 852 total points
ID: 35122631
Or instead of assigning the vars, you could do this:

while ( my $url = <$fh> ) {
    
    chomp $url;

    if ( head($url) ) {
        print "successful: $url\n";
    }
    else {
        print "failed: $url";
    }
}

Open in new window

0
 

Author Comment

by:kindaprog
ID: 36424883
I apologize. I thought I had already closed this question. I ended up using a Firefox add-on (iMacros).

I'm going to split the points evenly between all responses.

Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question