无法加载 cypress 中本地托管的 Web 服务器

问题描述 投票:0回答:2

我正在尝试为我的项目设置 cypress 测试套件,但在运行测试套件时我不断遇到错误消息:

Sorry, we could not load:

http://dev.project.local/signup/test

我的赛普拉斯配置如下所示:

{
  "baseUrl": "http://dev.project.local",
  "chromeWebSecurity": false,
  "hosts": {
    "dev.project.local": "192.168.10.10"
},

我有一个 Web 服务器,托管在本地 vagrant 虚拟机上。我还在本地主机文件中添加了一个条目:

192.168.10.10   dev.project.local

这些是我从 cypress 收到的错误消息:

cy.visit() failed trying to load:


http://dev.project.local/signup/test

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > Error: Parse Error: Expected HTTP/

Common situations why this would fail:
  - you don't have internet access
  - you forgot to run / boot your web server
  - your web server isn't accessible
  - you have weird network configuration settings on your computer
cypress/integration/examples/window.spec.js:10:8
   8 |   it('cy.window() - get the global window object', () => {
   9 |     // https://on.cypress.io/window
> 10 |     cy.visit('/signup/test')
     |        ^
  11 |     cy.window().should('have.property', 'top')
  12 |   })
  13 | 
  • 您没有互联网接入

我愿意

  • 您忘记运行/启动您的网络服务器

正在运行

  • 您的网络服务器无法访问

我可以正常访问网络服务器

dev.project.local

  • 您的计算机上有奇怪的网络配置设置

也许,我不认为我这样做,但 cypress 可能不能很好地与子域或 vagrant 配合使用

这是来自控制台的错误代码:

at <unknown> (http://dev.project.local/__cypress/runner/cypress_runner.js:157829:24)
    at visitFailedByErr (http://dev.project.local/__cypress/runner/cypress_runner.js:157189:13)
    at <unknown> (http://dev.project.local/__cypress/runner/cypress_runner.js:157828:12)
From previous event:
    at go (http://dev.project.local/__cypress/runner/cypress_runner.js:157791:18)
    at <unknown> (http://dev.project.local/__cypress/runner/cypress_runner.js:157857:21)
From previous event:
    at visit (http://dev.project.local/__cypress/runner/cypress_runner.js:157855:39)
    at Context.visit (http://dev.project.local/__cypress/runner/cypress_runner.js:157864:15)
From Your Spec Code:
    at Context.eval (webpack:///cypress/integration/examples/window.spec.js:10:8)
From Node.js Internals:
    Error: Parse Error: Expected HTTP/
      at Socket.socketOnData (_http_client.js:469:23)
      at Socket.emit (events.js:315:21)
      at addChunk (_stream_readable.js:295:13)
      at readableAddChunk (_stream_readable.js:271:10)
      at Socket.Readable.push (_stream_readable.js:212:11)
      at TCP.onStreamRead (internal/stream_base_commons.js:186:24)

我的 cypress.json 中缺少什么吗?我在这里不知所措。

谢谢

vagrant cypress
2个回答
0
投票

也许您无法访问该 URL,因为它不在 Internet 上。您是否尝试过创建代理? (https://docs.cypress.io/guides/references/proxy-configuration.html#Set-a-proxy-on-Linux-or-macOS


0
投票

要解决此问题,我必须在启动本地服务器时将 host 参数传递给

vite

vite --host
© www.soinside.com 2019 - 2024. All rights reserved.