gpt4 book ai didi

windows - 为什么 Perl 应用程序 'prove' 并行启动我的脚本但不并行执行这些脚本中的测试用例?

转载 作者:可可西里 更新时间:2023-11-01 09:34:19 25 4
gpt4 key购买 nike

我有几个 .t文件夹中的文件。每个测试脚本都会启动自己的 Selenium 实例,因此会打开自己的浏览器。然后它们将它们的指令传递给单独模块中的页面对象。唉,页面对象是大多数测试断言发生的地方。

我使用 prove -j2 testfolder 并行运行它们.当我这样做时,我看到两个浏览器打开,响应 Selenium 调用,但测试结果和浏览器操作表明第二个脚本仅在第一个脚本第一次调用 Test::More 之前运行。 ,然后它会挂起,直到第一个脚本完成。

页面对象模型是一个转移注意力的问题。我试过只裸露 pass()在每个 .t 的顶部调用文件并确认在整个第一个脚本完成之前不会尝试第二个脚本中的测试用例。

每个testX.t文件最终看起来像这样:

use strict;
use warnings;
use Test::More tests => 40;
use Selenium::Remote::Driver;
use MyPage::Object; # test execution module

my $sel = new Driver( 'browser_name' => $browser,'
'remote_server_addr' => $host,
'port' => "80", );

pass("Debug test case - let's see when this passes");

my $user = new MyPage::Object( text => "test string", sel => $sel);
$user->verify_text;
.
.

这是Object.pm看起来像:

use strict;
use warnings;
use Selenium::Remote::Driver;
use Selenium::Remote::WebElement qw(get_text);

package Object;

sub new {
my $class = shift;
my $self = bless { @_ }, $class;
return $self;
}

sub verify_text {
my ($self, $text_to_verify) = @_;
my $webElement = $self->{sel}->find_element("//*$xpath") or warn $!;
my $returnedtext = get_text($webElement) or warn $!;
Test::More::ok($returnedtext =~ /\Q$text_to_verify/, "text matches");
}

1;

这是输出。当第一个测试运行时,我看到了这个:

===(       4;12   4/40  0/? )===========================================

随着第一个脚本的测试用例得到验证,第一对数字和第二对中左边的数字上升。此后,当第二个脚本启动时,输出变为:

testfolder\test2.t .. 4/35

左边的数字随着测试用例的执行而增加。

并行运行它们不应该导致它们中的每个断言同时运行吗?这是不寻常的还是并行作业在 prove 中应该如何工作? ?

我在 64 位 Windows 7 ActiveState Perl v5.16.1 中从命令行运行它。 CPAN 显示 Prove 是最新的 (3.28)。

最佳答案

我想出了一个解决方法,尽管这并不是解决根本问题的真正方法。我使用了 this solutions at the Sauce Labs blog 的组合和 Freddy Vega's solution here想出这个:

#!usr/bin/perl
use strict;
use warnings;
use File::Find::Rule;
use Thread::Pool::Simple;

my $count = 0;

my @files = File::Find::Rule->file()
->name( '*.t' )
->in( 'C:\path\to\tests\' );

sub worker() {
my $file = shift;
system("prove $file");
print "Executing Test: " . $file . "\n";
}

my $pool = Thread::Pool::Simple->new(
min => 5,
max => 25,
do => [\&worker],
);

foreach my $test (@files) {
$pool->add($test);
print "Added $test to pool..\n";
$count++;
}
$pool->join();

exit(0);

关于windows - 为什么 Perl 应用程序 'prove' 并行启动我的脚本但不并行执行这些脚本中的测试用例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18897186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com