我正在尝试使用'Test::WWW::Selenium::More‘和'Moose’,同时用Perl创建我自己的名为'MySelenium‘的类。
这是我运行程序时出现的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‘的类
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;任何帮助都将不胜感激。
发布于 2015-10-17 09:37:47
您没有正确设置您的驼鹿属性。尝试遵循以下模式:
has host => (
is => 'ro',
isa => 'Str',
default => 'localhost',
);我看到你已经在为browser_url这么做了。只需确保以这种方式设置所有属性即可。
发布于 2015-10-17 20:49:52
除了oalders' answer之外,如果想要向现有对象添加内容,还需要使用has +foo表示法。看起来host和port已经是属性了,您只需要更改它们的默认值。
has '+host' => ( default => 'localhost' );https://stackoverflow.com/questions/33179047
复制相似问题