2010-11-25 2 views
1

필자의 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; 
} 

답변

1

흠 ... 일 수 있지만, 단순한 접근 방식은 TAP에서 설명 방법 :: 파서 :: 결과 : 시험을 무시하는 것 (나는 그것이를 통해 수행해야 확신 하위 클래스이지만 아침에 너무 어리석은 방법으로 알아 내기). 다음 초안의 라인을 따라

뭔가 :

# Original: sub description { shift->{description} } 
*TAP::Parser::Result::Test::description = sub { 
    my $description = shift->{description}; 
    $description =~ s/type, id_password, .*$/type, id_password, XXX_PASSWORD_REMOVED_XXX/; 
    return $description; 
}; 
+0

흥미로운 ... 어쩌면 내가 나중에이 실험을 시도 할 것이다 – knb

관련 문제