测试:: WWW :: Selenium ::更多与驼鹿

时间:2015-10-16 20:28:38

标签: perl moose

我试图使用'测试:: WWW :: Selenium ::更多'和'穆斯'在创建我自己的名为“MySelenium'在Perl。

这是运行程序时的Moose错误:

You must pass an even number of attribute options at /Library/Perl/5.18   /darwin-thread-multi-2level/Moose/Exporter.pm line 422
Moose::has('host', 'localhost') called at MySelenium.pm line 5
require MySelenium.pm at x.pl line 5
main::BEGIN at MySelenium.pm line 0
eval {...} at MySelenium.pm line 0
Compilation failed in require at ./x.pl line 5, <DATA> line 438.
BEGIN failed--compilation aborted at ./x.pl line 5, <DATA> line 438.

以下是该计划:

#!/usr/bin/perl -w
use strict;

use MySelenium;
use Test::Most;

my $x = MySelenium->new;

$x->open_ok('/');

done_testing;

这是我的班级名为“MySelenium&#39;

package MySelenium;
use Moose;
extends 'Test::WWW::Selenium::More';

has host        => 'localhost';
has port        => 4444;
has browser     => 'firefox';
has browser_url => (is => 'rw', isa => 'Str',
default => 'http://www.google.com');

    sub login_ok {
    my ($self, $username, $password) = @_;
    $self->open_ok('/login');
    $self->is_text_present_ok('Please login thanks');
    $self->type_ok('username' => $username);
    $self->type_ok('password' => $password);
    $self->follow_link_ok('login');
}

no Moose;

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

您未正确设置Moose属性。请尝试遵循以下模式:

has host => (
    is      => 'ro',
    isa     => 'Str',
    default => 'localhost',
);

我发现你已经为browser_url做了这个。只需确保以这种方式设置所有属性。

答案 1 :(得分:1)

除了oalders' answer之外,如果要向现有对象添加内容,则需要使用has +foo表示法。看起来hostport已经是属性,您只想更改其默认值。

has '+host' => ( default => 'localhost' );

see the Moose doc on has and has +