【发布时间】: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 您的解决方案似乎有效。如果您在下面发布您的答案,我会接受。