add Xpath lookup method in test lib

This commit is contained in:
Maxime Besson 2022-10-01 19:13:14 +02:00
parent 5f129f90d4
commit 012b41b2b1
1 changed files with 12 additions and 0 deletions

View File

@ -57,6 +57,7 @@ use strict;
use Data::Dumper;
use File::Find;
use JSON;
use XML::LibXML;
use LWP::UserAgent;
use Time::Fake;
use URI::Escape;
@ -595,6 +596,17 @@ sub expectCspChildOK {
count(1);
}
sub getHtmlElement {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my ( $res, $xpath ) = @_;
# Use recover to ignore parsing errors
my $doc =
XML::LibXML->new->load_html( string => $res->[2]->[0], recover => 2 );
return $doc->findnodes($xpath);
}
=head4 getCookies($res)
Returns an hash ref with names => values of cookies set by server.