automated-tests - Protractor-Flake 在重试后在所有实例中运行相同的脚本,而不是仅使用一个实例
问题描述
我有一个带有 Protractor、Protractor-Flake 的项目(重新运行失败的测试,3 次),在两个实例中用于并行化的 Multicapabilities。但是当第一次执行完成时,失败的规范在两个不同的实例中同时执行,是否有可能只有一个实例在重试尝试时运行,或者至少如果两个规范失败则在每个实例中执行每个规范. (在第一次执行时,Test1 和 Test 2 在不同的会话中同时运行)这是我的 config.json。
multiCapabilities: [{
browserName: 'chrome',
shardTestFiles: true,
maxSessions: 1,
chromeOptions: {
w3c: false
},
specs: ['../tests/Test1.spec.js']
}, {
browserName: 'chrome',
shardTestFiles: true,
maxSessions: 1,
chromeOptions: {
w3c: false
},
specs: ['../tests/Test2.spec.js']
}],
这就是第二次尝试的样子:
Using multi to parse output
Re-running tests: test attempt 2
Re-running the following test files:
Test2.spec.js
[18:40:29] W/launcher - You have specified both capabilities and multiCapabilities. This will result in capabilities being ignored
[18:40:29] I/launcher - Running 2 instances of WebDriver
[18:40:19] I/testLogger - [chrome #01] PID: 36072
[chrome #01] Specs: Test2.spec.js
[chrome #01]
[chrome #01] [18:39:36] I/direct - Using ChromeDriver directly...
[chrome #01] Started
[chrome #01] Jasmine started
[chrome #01] 3 specs, 1 failure
[chrome #01] Finished in 41.496 seconds
[chrome #01]
[18:40:19] I/testLogger -
[18:40:19] I/launcher - 1 instance(s) of WebDriver still running
.[18:40:28] I/testLogger -
------------------------------------
[18:40:28] I/testLogger - [chrome #11] PID: 7760
[chrome #11] Specs: Test2.spec.js
[chrome #11]
[chrome #11] [18:39:36] I/direct - Using ChromeDriver directly...
[chrome #11] Started
[chrome #11] Jasmine started
[chrome #11] 3 specs, 0 failures
[chrome #11] Finished in 49.188 seconds
[chrome #11]
[chrome #11] Executed 3 of 3 specs SUCCESS in 49 secs.
解决方案
您必须查看protractor-flake
内部工作原理以了解为什么会发生这种情况。没有过多的细节,基本上正在发生的事情是每个正在运行的量角器实例都会使用失败的测试列表重新启动。因为你有两个能力,他们都用这个列表重新启动。您可以在此处查看导致这种情况发生的代码。
也就是说,拥有两个完全相同的功能并没有多大意义。您已将 shardInstances 设置为 true,但只运行一项测试。我相信您知道, shardInstances 用于并行执行。将功能更改为类似这样,它将解决您的问题。它最初仍会启动两个规范,每个规范都有自己的浏览器实例,然后重试只会运行失败的规范。
multiCapabilities: [{
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 2,
chromeOptions: {
w3c: false
},
specs: [
'../tests/Test1.spec.js',
'../tests/Test2.spec.js'
]
}]