[英]Passing Parameter to Test::Class Setup method
I need to invoke a browser in selenium dynamically. 我需要动态调用硒中的浏览器。
To achieve this I need to send the browser name as parameter to the set-up or start-up methods in Test::Class
. 为此,我需要将浏览器名称作为参数发送到
Test::Class
的设置或启动方法。 How do I achieve this? 我该如何实现?
I take it you want to get a browser, then reuse it for some tests, then destroy it later? 我认为您想获得一个浏览器,然后将其重用于某些测试,然后销毁它? So just use a global to hold the browser you create.
因此,只需使用全局变量来保存您创建的浏览器。 For example:
例如:
my $browser = '';
sub b_connect : Test(startup) {
$browser = WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*iexplore",
browser_url => "http://www.google.com",
);
};
sub b_disconnect : Test(shutdown) {
$browser->close()
};
Just use the $browser var in you tests. 只需在测试中使用$ browser var。
sub startup : Test( startup ) {
my ($self) = @_;
my $arg = shift;
$self->{browser_type} = $arg->{browser};
-------------------------------#some other code for myself
$self->{browser} =
Test::WWW::Selenium->new(
host => $self->{host},
port => $self->{port},
browser => $self->{browser_type},
browser_url => $self->{test_url},
);
In my test script I need it to call using the following 在我的测试脚本中,我需要使用以下命令进行调用
my $t1 = Test::Class::Selenium::TestCases->new(browser=>$browser,);
Test::Class->runtests($t1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.