필자의 Perl 프로그램은 Test :: WWW :: Selenium을 사용하여 웹 페이지에서 작업을 실행하는 동안 TAP 테스트 케이스 출력을 HTML 보고서에 작성하고 TAP :: Harness에 의해 업데이트되었습니다.perl : 눈에 띄지 않게 IO :: Handle이 TAP :: Formatter :: HTML로 열어 본다.
내 Selenium 클라이언트는 암호로 보호 된 일부 웹 페이지에 로그인해야하며 불가피합니다. 따라서 암호는 TAP 출력에 나타납니다.
ok 1 - open, /homepage-with-loginform.html, true
ok 2 - type, id_username, JoeSixp
ok 3 - type, id_password, secrIt
...
HTML 출력에서 암호를 제거하려면, 나는 아래의 기능을 마련했지만, 그것은 작동하지 않습니다. 애니 애니가 도와 줄 수 있습니까?
은 내가이 질문을 "나는 펄을 사용하여 파일을 절단 어떻게"간단한이 아니라고 생각
my $fmt = TAP::Formatter::HTML->new;
my $harness = TAP::Harness->new({ formatter => $fmt, merge => 1 });
$harness->test_args([ "--browser=$browser", "--config=$h{config}" ]);
my $agg = $harness->runtests(@tests);
#remove passwords from HTML report
remove_password(\%h, $fmt); # %h is an options hash
...
sub remove_password {
# remove password from HTML report
my ($h, $fmt) = @_;
my $passwd = $h->{password} || "xxx-xxx";
my $outhtml = ${ $fmt->html() };
#from the TAP::Harness perldoc
#html() - This is a reference to the scalar containing the html generated on the last test run.
#Useful if you have "verbosity" set to silent, and have not provided a custom "output_fh" to write the report to.
note("replacing password with xxx-xxx in html file");
$fmt->html(\$outhtml); # does not work
$outhtml =~ s/$passwd/xxxxxx/msg; # works
{
local $/ = undef;
my $fh = $fmt->output_fh(); #An IO::Handle filehandle for printing the HTML report to.
if ($fh->opened){
#
# ??? HOW DO I unobtrusively truncate the file here?
#
print $fh $outhtml; # writes back censored HTML output
}
}
}
으로 포맷터 객체를 만들었습니다.
파일이 이미 일부 라이브러리 코드에 의해 열렸으며 코드가 unix 및 windows에서 작동해야합니다. 프로그램은 $ fh로 계속 작업해야합니다. TAP :: Formatter :: HTML 모듈을 혼동시킬 수 있고 제대로 작동하지 않을 수 있으므로 직접 열고 닫는 것이 좋습니다.
업데이트
#this gets the job done but it is kind of brutal
my $outf = $h->{outfile};
if ($fh->opened){
$fh->close();
open $fh, ">", $outf or die "cannnot open '$outf' for truncating and writing:$!";
print $fh $outhtml;
close $fh;
}
흥미로운 ... 어쩌면 내가 나중에이 실험을 시도 할 것이다 – knb