我正在将我们的前端从create-react-app转换到vite,我突然注意到,基于某种奇怪的原因,vite的development和preview构建并不能与Test咖啡馆协同工作。
我得到的确切错误是:
yarn testcafe .\src\tests\main\desktop\helppagina.test.ts
Running tests in:
- Chrome 104.0.5112.102 / Windows 10
My Fixture
× My Test
1) undefinedFailed to load the page at "http://localhost:3000/gms/app/help".
Increase the value of the "pageRequestTimeout" variable, enable the "retryTestPages" option, or use quarantine mode to perform additional attempts to execute this test.
You can find troubleshooting information for this issue at "https://go.devexpress.com/TestCafe_FAQ_ARequestHasFailed.aspx".
Error details:
Failed to find a DNS-record for the resource at "http://localhost:3000/gms/app/help".
Browser: Chrome 104.0.5112.102 / Windows 10
// 4 more snipped for length
5/5 failed (50s)
Warnings (1):
--
Was unable to take a screenshot due to an error.
Error: WebSocket is not open: readyState 3 (CLOSED)
at sendAfterClose (C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\ws\lib\websocket.js:979:17)
at WebSocket.send (C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\ws\lib\websocket.js:405:7)
at Chrome._enqueueCommand (C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\chrome-remote-interface\lib\chrome.js:286:18)
at C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\chrome-remote-interface\lib\chrome.js:88:22
at new Promise (<anonymous>)
at Chrome.send (C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\chrome-remote-interface\lib\chrome.js:87:20)
at Object.handler [as captureScreenshot] (C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\chrome-remote-interface\lib\api.js:32:23)
at BrowserClient.getScreenshotData (C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\testcafe\src\browser\provider\built-in\dedicated\chrome\cdp-client\index.ts:312:50)
at BrowserProviderPluginHost.takeScreenshot (C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\testcafe\src\browser\provider\built-in\dedicated\base.js:87:32)
at BrowserProvider.takeScreenshot (C:\Users\j.claassens\Documents\workspace\wlis\gms\mmi-end-to-end-test\node_modules\testcafe\src\browser\provider\index.ts:409:13)我的Vite dev服务器正在运行,因为http://localhost:3000/gms
http://localhost:<port_from_testcafe>/<some_random_id_from_testcafe>/
104.0.5112.102 (Official Build) (64-bit) (cohort: Stable)
http://localhost:<port_from_testcafe>/<some_random_id_from_testcafe>/
104.0.5112.102 (Official Build) (64-bit) (cohort: Stable)
firefox和edge上,而create-react-app.没有发生这种情况
我有更多关于这个gist的信息(两个项目的Package.json,文件/文件夹截图以及testcaferc和vite配置文件):https://gist.github.com/favna/38c0358a9827da176d4ccf02cfffe502
发布于 2022-08-24 15:13:34
解决方案是将server.host设置为vite.config.ts中的true,而不是以前的'localhost'值。
我不知道为什么考虑到TestCafe也会使用'localhost'来解决这个问题,但是不管是什么原因,解决这个问题的目标已经实现了。
https://stackoverflow.com/questions/73475104
复制相似问题