perl selenium:Test::Exception、正确用法和良好的代码示例?
在selenium IDE中,perl驱动程序/格式化程序安装的代码模板包括perl selenium:Test::Exception、正确用法和良好的代码示例?,perl,testing,selenium,Perl,Testing,Selenium,在selenium IDE中,perl驱动程序/格式化程序安装的代码模板包括 use Test::Exception; 默认情况下为代码行 关于这个模块,我有几个问题:wrt Test::WWW::Selenium 在my.t文件中是否应该使用Test::Exception? 直到现在,我还没有使用它的任何方法,我的测试运行得很好(我通常做快乐路径测试) 现在我想到了一个潜在的用途。我注意到,如果selenium对象在页面上找不到某些内容或定位器出错等,它有时会死亡。在许多情况下,我希望我的测
use Test::Exception;
默认情况下为代码行
关于这个模块,我有几个问题:wrt Test::WWW::Selenium
在my.t文件中是否应该使用Test::Exception?
直到现在,我还没有使用它的任何方法,我的测试运行得很好(我通常做快乐路径测试)
现在我想到了一个潜在的用途。我注意到,如果selenium对象在页面上找不到某些内容或定位器出错等,它有时会死亡。在许多情况下,我希望我的测试继续进行,即selenium不应死亡,并继续在页面上执行操作
这是Test::Exception方法的正确用法吗?
我应该尝试将它与try::Tiny结合起来吗
这是我刚刚写的一个小助手方法。
该U和方法属于Test::Exception
sub verify_text_qr {
my ( $sel, $text ) = @_;
#$sel - the selenium object
#$text ||= 'I think that'; # some text I am looking for on the page
lives_and( sub {
my $found = $sel->get_text("//p[contains(text(), '$text')]");
like( $found, qr /$text/)
},
"found '$text' on page" );
}
编辑-(问题仍未回答-我只是对方法进行了一点改进,使其更加健壮):
你不应该和它结合,因为它是为你捕捉的。简单演示:
use Test::More;
use Test::Exception;
lives_and { is not_throwing(), "42" } 'passing test';
lives_and { is throwing(), "42" } 'failing test';
done_testing;
sub not_throwing { 42 }
sub throwing { die "failed" }
因此,我将使用与您的第一个代码片段类似的方式。你也可以考虑使用,这是稍微轻一点的方法。 你不应该结合,因为它是为你而捕捉的。简单演示:
use Test::More;
use Test::Exception;
lives_and { is not_throwing(), "42" } 'passing test';
lives_and { is throwing(), "42" } 'failing test';
done_testing;
sub not_throwing { 42 }
sub throwing { die "failed" }
因此,我将使用与您的第一个代码片段类似的方式。你也可以考虑使用,这是稍微轻一些的方法。@达希姆-我注意到麋鹿最近从t::e到t::F. Here也是一些@达西姆-我注意到麋鹿最近从t::e到t::F. Here也是一些。