【问题标题】:Perl send not working on Jenkins?Perl 发送在 Jenkins 上不起作用?
【发布时间】:2012-11-23 09:44:54
【问题描述】:

我已将 Jenkins 设置为定期运行 iphone UI 自动化测试。

运行自动化的第一个测试脚本时,出于安全原因,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");
}

我想做的是在我的命令超时之前发送密码,以便它运行测试脚本。

【问题讨论】:

  • 尝试将undef 更改为倒数第二行中的某个数字。
  • 我已经尝试了 30、60 和 120 而不是 undef,但它仍然不发送密码。
  • $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); 尝试组合查询并使用exp_continue
  • @ChankeyPathak 看起来 exp_continue 应该可以工作,会尝试并让您知道
  • @ChankeyPathak 您的解决方案似乎有效。如果您在下面发布您的答案,我会接受。

标签: perl terminal jenkins


【解决方案1】:

尝试组合查询并将 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 2013-09-05
    • 2012-08-08
    相关资源
    最近更新 更多