How to create a selenium test suite using PERL

729 views
Skip to first unread message

kaykay

unread,
Feb 11, 2011, 11:35:47 AM2/11/11
to Selenium Users
Hi All,

I am new to this group. I have created separate PERL scripts using
Selenium IDE. Record a script and export the script using Selenium IDE
(Export test case as PERL) and saved it as script1.pl. The list goes
to script10.pl

I am able to playback all the ten perl scripts individually using
Selenium RC without any problem. But, my task is to have all ten perl
scripts in one file and should be called using Selenium RC by a single
perl file. I am able to do this by HTML file using the above code.
C:\Program Files (x86)\Java\jre6\bin>java -jar selenium-server.jar -
htmlSuite "*firefox" "http://www.google.com" "C:\Program Files
(x86)\Java\jre6\bin\Selenium\testsuite.html" "C:\Program Files
(x86)\Java\jre6\bin\Selenium\results.html".

But unfrotunately for PERL I do not know how to do this. I saw this
code snippet in the internet for PERL . Follwed the same instructions
but it did not work.

REM Run all test scripts in the Tests directory.

set SE_BROWSER=firefox
set SE_SITE=tst11.dev
set SE_BUILD=0037_00

perl -MTest::Harness -e "@ARGV= map glob, @ARGV if $^O =~ /^MSWin/;
runtests @ARGV;" Tests/*.pl

Thanks in advance for helping me.

Regards,
K

Bob McConnell

unread,
Feb 11, 2011, 3:15:06 PM2/11/11
to seleniu...@googlegroups.com
From: kaykay

"Did not work" covers a lot of possibilities and makes it difficult to
figure out what your particular problem is. What results or error
messages do you get from that command line?

That code snippet assumes you wrote your Perl tests with Test::More to
conform to the TAP API. Did you read the entire wiki article at
<http://wiki.openqa.org/display/SRC/Selenium+RC+and+Perl> and use it as
a template for your tests?

Bob McConnell

Freddy Vega

unread,
Feb 11, 2011, 7:50:37 PM2/11/11
to Selenium Users
This is essentially what the command
perl -MTest::Harness -e "@ARGV= map glob, @ARGV if $^O =~ /
^MSWin/; runtests @ARGV;" Tests/*.pl

is doing. Is going into the directory that holds the scripts and
executing them one by one using Test::Harness (a perl module).

You can achieve the same thing by creating a driver script that calls
all of your perl scripts in order. This driver script could be a
windows .bat file, linux shell script or even a perl script that
simply contains 10 system calls to your individual scripts.

For example:
Assuming that your scripts reside in the directory C:\Automation
\Scripts\, this is how i would do it in perl.

my $result_dir = "C:\\Automation\\Results\\"

opendir (my $dh, $result_dir) or die "can't open dir: $!";
while (readdir $dh){
if ($_ =~ /pl$/){
system ( $_ );
}
}

The above:
1. Opens the directory
2. Reads the directory
3. If the file ends in PL it gets executed by the system call

Hope this helps.

kaykay

unread,
Feb 15, 2011, 12:48:07 PM2/15/11
to Selenium Users
Hi All,

thanks for your reply.

@Freddy: I tried using your method Selenium RC server is unable to get
the connection and hence the test is not running. I mean the perl file
which I am trying to connect to RC Server is not working

This is my file

my $result_dir = "C:\\Users\\Keerthi\\Desktop\\Try";

opendir (my $dh, $result_dir) or die "can't open dir: $!";
while (readdir $dh){
if ($_ =~ /pl$/){
system ( $_ );
}
}

I have ten perl scripts in C:\\Users\\Keerthi\\Desktop\\Try and tried
executing all of them as a test suite. Its not working.

Would be helpful if someone has shed some light on this

Thanks once again.

Regards,
Keerthi

Freddy Vega

unread,
Mar 11, 2011, 12:13:57 AM3/11/11
to Selenium Users

Sorry for the late reply. My apologies also for assuming that it
would be obvious that my
Example was just that a sample and although it does work, it may not
work in all systems.

Do you have perl in your path?

Anand

unread,
Mar 11, 2011, 4:58:44 PM3/11/11
to Selenium Users
kaykay, am not sure why it din't work...but you may be missing last "\
\" in the directory path from the Freddy's example ?

On Mar 10, 10:13 pm, Freddy Vega <freddy.vega...@gmail.com> wrote:
> Sorry for the late reply.  My apologies also for assuming that it
> would be obvious that my
> Example was just that a sample and although it does work, it may not
> work in all systems.
>
> Do you haveperlin your path?
>
> On Feb 15, 12:48 pm, kaykay <keerthi....@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi All,
>
> > thanks for your reply.
>
> > @Freddy: I tried using your method Selenium RC server is unable to get
> > the connection and hence thetestis not running. I mean theperlfile
> > which I am trying to connect to RC Server is not working
>
> > This is my file
>
> > my $result_dir = "C:\\Users\\Keerthi\\Desktop\\Try";
>
> > opendir (my $dh, $result_dir) or die "can't open dir: $!";
> > while (readdir $dh){
> >         if ($_ =~ /pl$/){
> >              system ( $_ );
> >         }
>
> > }
>
> > I have tenperlscripts in C:\\Users\\Keerthi\\Desktop\\Try and tried
> > executing all of them as atestsuite. Its not working.
>
> > Would be helpful if someone has shed some light on this
>
> > Thanks once again.
>
> > Regards,
> > Keerthi
>
> > On Feb 12, 12:50 am, Freddy Vega <freddy.vega...@gmail.com> wrote:
>
> > > This is essentially what the command
> > >  perl-MTest::Harness -e "@ARGV= map glob, @ARGV   if  $^O =~ /
> > > ^MSWin/; runtests @ARGV;" Tests/*.pl
>
> > > is doing. Is going into the directory that holds the scripts and
> > > executing them one by one usingTest::Harness (aperlmodule).
>
> > > You can achieve the same thing by creating a driver script that calls
> > > all of yourperlscripts in order. This driver script could be a
> > > windows .bat file, linux shell script or even aperlscript that
> > > simply contains 10 system calls to your individual scripts.
>
> > > For example:
> > > Assuming that your scripts reside in the directory C:\Automation
> > > \Scripts\, this is how i would do it inperl.
>
> > > my $result_dir = "C:\\Automation\\Results\\"
>
> > > opendir (my $dh, $result_dir) or die "can't open dir: $!";
> > > while (readdir $dh){
> > >         if ($_ =~ /pl$/){
> > >              system ( $_ );
> > >         }
>
> > > }
>
> > > The above:
> > > 1. Opens the directory
> > > 2. Reads the directory
> > > 3. If the file ends in PL it gets executed by the system call
>
> > > Hope this helps.
>
> > > On Feb 11, 11:35 am, kaykay <keerthi....@gmail.com> wrote:
>
> > > > Hi All,
>
> > > > I am new to this group. I have created separatePERLscripts using
> > > > Selenium IDE. Record a script and export the script using Selenium IDE
> > > > (Exporttestcase asPERL) and saved it as script1.pl. The list goes
> > > > to script10.pl
>
> > > > I am able to playback all the tenperlscripts individually using
> > > > Selenium RC without any problem. But, my task is to have all tenperl
> > > > scripts in one file and should be called using Selenium RC by a single
> > > >perlfile. I am able to do this by HTML file using the above code.
> > > > C:\Program Files (x86)\Java\jre6\bin>java -jar selenium-server.jar -
> > > > htmlSuite "*firefox" "http://www.google.com" "C:\Program Files
> > > > (x86)\Java\jre6\bin\Selenium\testsuite.html" "C:\Program Files
> > > > (x86)\Java\jre6\bin\Selenium\results.html".
>
> > > >  But unfrotunately forPERLI do not know how to do this. I saw this
> > > > code snippet in the internet forPERL. Follwed the same instructions
> > > > but it did not work.
>
> > > > REM Run alltestscripts in the Tests directory.
>
> > > > set SE_BROWSER=firefox
> > > > set SE_SITE=tst11.dev
> > > > set SE_BUILD=0037_00
>
> > > >perl-MTest::Harness -e "@ARGV= map glob, @ARGV   if  $^O =~ /^MSWin/;
Reply all
Reply to author
Forward
0 new messages