【发布时间】:2017-09-28 22:54:50
【问题描述】:
tl;博士;
我需要增加这个超时时间:
命令 |命令 `test` 在 [32.585s] 后以错误结束
命令 | BackstopExcpetion:测试 #1 未定义:GotoTimeoutError:goto() 超时
考虑以下服务器代码:
const http = require('http');
const hostname = '0.0.0.0';
const port = 3000;
http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end(`<!DOCTYPE html>
<title>Test Page</title>
<script>console.log("Hello world!")</script>
<h1>Hello world!</h1>
`);
}).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
和带有 4 * 3 = 12 次测试的 BackstopJS 配置:
{
"id": "backstop_default",
"viewports": [
{ "label": "phone_portrait", "width": 320, "height": 480 },
{ "label": "phone_landscape", "width": 480, "height": 320 },
{ "label": "tablet_portrait", "width": 768, "height": 1024 },
{ "label": "tablet_landscape", "width": 1024, "height": 768 }
],
"scenarios": [
{ "label": "Test #1", "url": "http://localhost:3000/", "selectors": ["body"] },
{ "label": "Test #2", "url": "http://localhost:3000/", "selectors": ["body"] },
{ "label": "Test #3", "url": "http://localhost:3000/", "selectors": ["body"] }
],
"paths": {
"bitmaps_reference": "backstop_data/bitmaps_reference",
"bitmaps_test": "backstop_data/bitmaps_test",
"engine_scripts": "backstop_data/engine_scripts",
"html_report": "backstop_data/html_report",
"ci_report": "backstop_data/ci_report"
},
"report": ["browser"],
"engine": "chrome",
"engineFlags": []
}
当我启动backstop test 时,一切正常:
D:\Temp\Supertemp\server-delay>backstop test
BackstopJS v3.0.22
Loading config: D:\Temp\Supertemp\server-delay\backstop.json
COMMAND | Executing core for `test`
createBitmaps | Selcted 3 of 3 scenarios.
Starting Chromy: port:9222 --disable-gpu,--force-device-scale-factor=1,--window-size=320,480
Starting Chromy: port:9223 --disable-gpu,--force-device-scale-factor=1,--window-size=480,320
Starting Chromy: port:9224 --disable-gpu,--force-device-scale-factor=1,--window-size=768,1024
Starting Chromy: port:9225 --disable-gpu,--force-device-scale-factor=1,--window-size=1024,768
Starting Chromy: port:9226 --disable-gpu,--force-device-scale-factor=1,--window-size=320,480
Starting Chromy: port:9227 --disable-gpu,--force-device-scale-factor=1,--window-size=480,320
Starting Chromy: port:9228 --disable-gpu,--force-device-scale-factor=1,--window-size=768,1024
Starting Chromy: port:9229 --disable-gpu,--force-device-scale-factor=1,--window-size=1024,768
Starting Chromy: port:9230 --disable-gpu,--force-device-scale-factor=1,--window-size=320,480
Starting Chromy: port:9231 --disable-gpu,--force-device-scale-factor=1,--window-size=480,320
9224 LOG > Hello world!
9227 LOG > Hello world!
9226 LOG > Hello world!
9222 LOG > Hello world!
9223 LOG > Hello world!
9225 LOG > Hello world!
9228 LOG > Hello world!
9231 LOG > Hello world!
9229 LOG > Hello world!
9230 LOG > Hello world!
Starting Chromy: port:9232 --disable-gpu,--force-device-scale-factor=1,--window-size=768,1024
Starting Chromy: port:9233 --disable-gpu,--force-device-scale-factor=1,--window-size=1024,768
9232 LOG > Hello world!
9233 LOG > Hello world!
COMMAND | Executing core for `report`
compare | OK: Test #1 backstop_default_Test_1_0_body_0_phone_portrait.png
compare | OK: Test #1 backstop_default_Test_1_0_body_1_phone_landscape.png
compare | OK: Test #1 backstop_default_Test_1_0_body_2_tablet_portrait.png
compare | OK: Test #1 backstop_default_Test_1_0_body_3_tablet_landscape.png
compare | OK: Test #2 backstop_default_Test_2_0_body_0_phone_portrait.png
compare | OK: Test #2 backstop_default_Test_2_0_body_1_phone_landscape.png
compare | OK: Test #2 backstop_default_Test_2_0_body_2_tablet_portrait.png
compare | OK: Test #2 backstop_default_Test_2_0_body_3_tablet_landscape.png
compare | OK: Test #3 backstop_default_Test_3_0_body_0_phone_portrait.png
compare | OK: Test #3 backstop_default_Test_3_0_body_1_phone_landscape.png
compare | OK: Test #3 backstop_default_Test_3_0_body_2_tablet_portrait.png
compare | OK: Test #3 backstop_default_Test_3_0_body_3_tablet_landscape.png
report | Test completed...
report | 12 Passed
report | 0 Failed
report | Writing browser report
report | Browser reported copied
report | Copied configuration to: D:\Temp\Supertemp\server-delay\backstop_data\html_report\config.js
COMMAND | Executing core for `openReport`
openReport | Opening report.
COMMAND | Command `openReport` sucessfully executed in [0.114s]
COMMAND | Command `report` sucessfully executed in [0.182s]
COMMAND | Command `test` sucessfully executed in [8.495s]
但是现在让我们在发送页面前让服务器延迟 40 秒:
const http = require('http');
const hostname = '0.0.0.0';
const port = 3000;
http.createServer((req, res) => {
setTimeout(() => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end(`<!DOCTYPE html>
<title>Test Page</title>
<script>console.log("Hello world!")</script>
<h1>Hello world!</h1>
`);
}, 40000);
}).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
然后运行backstop test:
D:\Temp\Supertemp\server-delay>backstop test
BackstopJS v3.0.22
Loading config: D:\Temp\Supertemp\server-delay\backstop.json
COMMAND | Executing core for `test`
createBitmaps | Selcted 3 of 3 scenarios.
Starting Chromy: port:9222 --disable-gpu,--force-device-scale-factor=1,--window-size=320,480
Starting Chromy: port:9223 --disable-gpu,--force-device-scale-factor=1,--window-size=480,320
Starting Chromy: port:9224 --disable-gpu,--force-device-scale-factor=1,--window-size=768,1024
Starting Chromy: port:9225 --disable-gpu,--force-device-scale-factor=1,--window-size=1024,768
Starting Chromy: port:9226 --disable-gpu,--force-device-scale-factor=1,--window-size=320,480
Starting Chromy: port:9227 --disable-gpu,--force-device-scale-factor=1,--window-size=480,320
Starting Chromy: port:9228 --disable-gpu,--force-device-scale-factor=1,--window-size=768,1024
Starting Chromy: port:9229 --disable-gpu,--force-device-scale-factor=1,--window-size=1024,768
Starting Chromy: port:9230 --disable-gpu,--force-device-scale-factor=1,--window-size=320,480
Starting Chromy: port:9231 --disable-gpu,--force-device-scale-factor=1,--window-size=480,320
COMMAND | Command `test` ended with an error after [32.585s]
COMMAND | BackstopExcpetion: Test #1 on undefined: GotoTimeoutError: goto() timeout
9230 LOG > Hello world!
9228 LOG > Hello world!
9222 LOG > Hello world!
9224 LOG > Hello world!
9227 LOG > Hello world!
9231 LOG > Hello world!
9223 LOG > Hello world!
9225 LOG > Hello world!
9229 LOG > Hello world!
9226 LOG > Hello world!
如你所见,有一个错误
命令 |命令 `test` 在 [32.585s] 后以错误结束
命令 | BackstopExcpetion:测试 #1 未定义:GotoTimeoutError:goto() 超时
但之后我们可以看到console.log 在页面上执行。逆止器开始无限等待某事......无论如何,这不是问题。
我对扩大 30 秒超时的选项很感兴趣,因为在某些情况下,开发服务器需要更多时间来提供内容。我该如何配置它?
【问题讨论】:
-
您找到解决方案了吗?我也有同样的问题。
-
@seth,不幸的是没有。我以另一种方式解决了这个问题:如果测试命令和应用程序的开发版本在不同的计算机上启动,则会发生超时。因此,我在同一台计算机上对 prod 版本进行了测试,30 秒就足够了。我认为,您可以尝试限制后续测试的数量(以提供更多的网络品牌宽度)或编译为 prod 版本。顺便说一句,如果您使用的是 backstop,能否请您看看我关于它的其他问题?
-
@seth,看看答案!
标签: node.js google-chrome testing regression-testing backstop.js