我使用的是来自waitForElementVisible(<selector>, <timeout>, false)的夜视API文档命令,它的行为与我所期望的不太一样。为了获得预期的行为,我如何修改这段代码?
预期的行为:
.waitForElementVisible('foobar', 10, false)实际行为:
.waitForElementVisible('foobar', 10, false)下面是要复制的示例代码
module.exports = {
tags: ['smoke'],
before: browser =>
browser
.maximizeWindow('current').url('https://google.com'),
after: browser => browser.end(),
'smoke test': browser =>
browser
.waitForElementVisible('foobar', 10, false)
.waitForElementVisible('img')
.assert.visible('img'),
};下面是运行该命令的控制台输出:
Starting selenium server in parallel mode... started - PID: 75459
Started child process for: 01_smoke
01_smoke \n
01_smoke [01 Smoke] Test Suite
=========================
01_smoke
01_smoke Results for: smoke test
01_smoke ✖ Timed out while waiting for element <foobar> to be present for 10 milliseconds. - expected "visible" but got: "not found"
01_smoke at Object.smokeTest [as smoke test] (/path/to/tests/01_smoke.js:12:8)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
01_smoke ✔ Element <img> was visible after 33 milliseconds.
01_smoke ✔ Testing if element <img> is visible.
01_smoke
01_smoke Retrying (1/3): smoke test
01_smoke ✖ Timed out while waiting for element <foobar> to be present for 10 milliseconds. - expected "visible" but got: "not found"
01_smoke at Object.smokeTest [as smoke test] (/path/to/tests/01_smoke.js:12:8)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
01_smoke ✔ Element <img> was visible after 21 milliseconds.
01_smoke ✔ Testing if element <img> is visible.
01_smoke
01_smoke Retrying (2/3): smoke test
01_smoke ✖ Timed out while waiting for element <foobar> to be present for 10 milliseconds. - expected "visible" but got: "not found"
01_smoke at Object.smokeTest [as smoke test] (/path/to/tests/01_smoke.js:12:8)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
01_smoke ✔ Element <img> was visible after 20 milliseconds.
01_smoke ✔ Testing if element <img> is visible.
01_smoke Retrying (3/3): smoke test
01_smoke ✖ Timed out while waiting for element <foobar> to be present for 10 milliseconds. - expected "visible" but got: "not found"
01_smoke at Object.smokeTest [as smoke test] (/path/to/tests/01_smoke.js:12:8)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
01_smoke ✔ Element <img> was visible after 20 milliseconds.
01_smoke ✔ Testing if element <img> is visible.
01_smoke FAILED: 1 assertions failed and 2 passed (53ms)
>> 01_smoke finished.
_________________________________________________
TEST FAILURE: 1 assertions failed, 2 passed. (6.259s)
✖ 01_smoke
- smoke test (53ms)
Timed out while waiting for element <foobar> to be present for 10 milliseconds. - expected "visible" but got: "not found"
at Object.smokeTest [as smoke test] (/path/to/tests/01_smoke.js:12:8)
at _combinedTickCallback (internal/process/next_tick.js:131:7)发布于 2019-02-21 10:47:32
是的,应该是这样的!我认为您误解了abortOnFailure标志对waitForVisible命令的工作方式。false标志只给出方法要由测试运行程序作为非中断步骤计算的字符。但这并不意味着它不把这一步算作失败的一步。
注意:类似的事情发生在断言/核实的情况下( verify是一个不中断的断言,类似于waitForElementVisible的abortOnFailure: false参数)。
不过,我能看出人们在哪里会有这样的印象。如果您阅读API调用的描述,它会说:
如果元素未能在指定的时间内出现并可见,则测试将失败。您可以通过将abortOnFailure设置为false来更改此操作。
这让您想到,即使waitForVisible命令失败,测试可能最终还是会通过。但是. API调用的参数部分提供了帮助,删除了这个错误的假设:
默认情况下,如果找不到元素,则测试将失败。如果您希望测试继续进行,即使断言失败,将其设置为false。要全局设置此属性,可以在全局值中定义属性abortOnAssertionFailure。
最后,.在文档可能会失败的地方,代码永远不会说谎:
process.on('exit', function (code) {
var exitCode = code;
if (exitCode === 0 && globalResults && (globalResults.errors > 0 || globalResults.failed > 0)) {
exitCode = 1;
}
process.exit(exitCode);
});上面是一个代码片段夜莺的测试运行程序(nightwatch/lib/runner/run.js)。自己看看它认为什么是有效的exit code 1条件。
干杯!
https://stackoverflow.com/questions/54793757
复制相似问题