2012-11-22 60 views
1

我已經設置了Jenkins來定期運行iphone UI自動測試。Perl發送不工作Jenkins?

運行第一個自動化測試腳本時,出於安全原因,OS X會提示輸入用戶名和密碼。

所以我做了一個perl腳本,它產生了來自Expect的命令併發送用戶名和密碼。

由於某種原因,用戶名被髮送,但沒有密碼。

密碼確實最終會發送,但是在我的命令超時之後。下面

代碼:

my $cmdString = "instruments -t $traceTemplatePath $AppFolder -e UIASCRIPT $escapedTest " . 
    "-e UIARESULTSPATH Logs"; 
if ($isFirst == 1) { 

    $isFirst = 0; 

    $password = `cat /Users/\$USER/.password`; 

    # Actually spawn the command from Expect. 
    my $exp = Expect->spawn($cmdString) 
     or die "Failed to spawn command in Expect: $! \n"; 
    #change delay if necessary 
    $exp->expect(30, [qr/Name .*/]); 
    $exp->send("\n"); 

    $exp->expect(undef, [qr/Password/]); 
    $exp->send("$password\n"); 
} 

我想要做的就是在我的命令的時間發送出去密碼,所以它的運行測試腳本。

+0

嘗試改變'undef'一些數量排在第二的最後一行。 –

+0

我已經嘗試過30,60和120而不是undef,但它仍然不發送密碼。 – stackErr

+1

'$ exp-> expect($ timeout,[qr/username:/ i,sub {my $ self = shift; $ self> send(「$ username \ n」); exp_continue;}],[qr /密碼:/ i,sub {my $ self = shift; $ self> send(「$ password \ n」); exp_continue;}],$ shell_prompt);'嘗試合併查詢並使用'exp_continue'。 –

回答

0

嘗試將查詢組合,並使用exp_continue爲:

$exp->expect($timeout, 
      [ qr/username: /i, sub { my $self = shift; 
             $self->send("$username\n"); 
             exp_continue; }], 
      [ qr/password: /i, sub { my $self = shift; 
             $self->send("$password\n"); 
             exp_continue; }], 
      $shell_prompt);