2012-11-22 59 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);