Perl-Selenium also provides the standard methods of Test::More such as ok(), like(), is(), etc , also as object methods, e.g. $sel->like()
.
($sel is the selenium perl object)
Should these object methods be used at all? Which one is preferred?
I am puzzled because like() and $sel->like seem to behave differently in places. Here I assume text is indeed found on the page.
like( $found, qr /$text/, "found '$text' on page" ) ; # WORKS FINE
# DOES NOT WOR开发者_如何学运维K, ERROR: "doesn't look much like a regex to me."
$sel->like( $found, qr/$text/ , "found '$text' on page")
So it seems the pure like() method is preferable to $sel->like()?
It looks like Test::WWW::Selenium does not itself provide like
method, but rather many methods like title_like
or text_like
.
That gives us either
like( $found, qr /$text/, "found '$text' on page" );
or
$sel->text_like('id', qr/$text/, "found '$text' on page");
Edit: There is like
method available in Test::WWW::Selenium, but when dumped, it looks like this:
sub {
my $tb = 'Test::More'->builder;
return $tb->like(@_);
}
it means that by calling as $sel->like(...)
you are adding one extra parameter ($sel
) to the method call. The method is remnant of Test::Builder
inheritance and it likely not supposed to be used directly.
精彩评论