1
use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;
my $sel = Test::WWW::Selenium->new(
    host        => "localhost",
    port        => 4444,
    browser     => "*firefox",
    browser_url => "http://10.201.3.192:8000/"
);
$sel->open_ok("/abc-dd/");
$sel->window_maximize();
$sel->$sel->$sel->$sel->_ok();
$sel->close_ok();

上面的代码适用于单个 URL。我需要对另一个 URL 执行相同的操作。以下代码仅完成了第一部分的执行。

use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;
my $sel = Test::WWW::Selenium->new(
    host        => "localhost",
    port        => 4444,
    browser     => "*firefox",
    browser_url => "http://10.201.3.192:8000/"
);
$sel->open_ok("/abc-dd/");
$sel->window_maximize();
$sel->$sel->$sel->$sel->_ok();
$sel->close_ok();
$sel->open_ok("http://10.201.3.195:8000/abc-dd/");
$sel->window_maximize();
$sel->$sel->$sel->$sel->_ok();
$sel->close_ok();

我必须对单个 Perl 文件中的两个 URL 执行操作:

http://10.201.3.192:8000/abc-dd/
http://10.201.3.195:8000/abc-dd/

如何附加第二个 URL?

4

2 回答 2

1

你可以创建一个url数组并循环遍历它

my @urls = qw (http://10.201.3.192:8000 
               http://10.201.3.195:8000); # create list of urls

for my $url (@urls) {

    my $sel = Test::WWW::Selenium->new( host => "localhost", 
                                    port => 4444, 
                                    browser => "*firefox", 
                                    browser_url => $url );

    $sel->open_ok("/abc-dd/");
    $sel->
    $sel->
    ...
}
于 2012-06-15T08:45:26.537 回答
1

将您的逻辑打包到函数中以供重用:

use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;

sub test_url {
    my $sel = Test::WWW::Selenium->new( host => "localhost", 
                                        port => 4444, 
                                        browser => "*firefox", 
                                        browser_url => "http://10.201.3.192:8000/" );

    $sel->open_ok("/abc-dd/");
    $sel->window_maximize();
    $sel->
    $sel->
    $sel->
    $sel->_ok();
    $sel->close_ok();
}

test_url("/abc-dd/");
test_url("http://10.201.3.195:8000/abc-dd/");
于 2012-06-15T10:28:25.987 回答