Selenium Firefox 驱动程序强制 https

Ben*_*ier 3 ssl selenium webdriver selenium-webdriver docker

我有一个功能应用程序在端口上的 docker 中运行3000。当我将主机设置为http://localhost:3000. 我创建了一个容器来启动 selenium 测试,但失败并出现以下错误:

WebDriverError:Reachederrorpage:about:neterror?e=nssFailure2&u=https://app:3000/&c=UTF-8&f=regular&d=An error occurred during a connection to app:3000.

SSL received a record that exceeded the maximum permissible length.

Error code: <a id="errorCode" title="SSL_ERROR_RX_RECORD_TOO_LONG">SSL_ERROR_RX_RECORD_TOO_LONG</a>
Run Code Online (Sandbox Code Playgroud)

我的片段 docker-compose.yml

app:
    build:
        context: .
        dockerfile: Dockerfile.dev
    volumes:
        - ./:/usr/src/app/
    ports:
        - "3000:3000"
        - "3001:3001"
    networks:
        tests:

selenium-tester:
    build:
        context: .
        dockerfile: Dockerfile.selenium.tests
    volumes:
        - ./:/usr/src/app/
        - /dev/shm:/dev/shm
    depends_on:
        - app
    networks:
        tests:
Run Code Online (Sandbox Code Playgroud)

我替换了主机,http://app:3000但 Firefox 似乎想将此 http 重定向到 https(这不起作用)。最后我像这样构建我的驱动程序:

const ffoptions = new firefox.Options()
  .headless()
  .setPreference('browser.urlbar.autoFill', 'false'); // test to disable auto https redirect… not working obviously
const driver = Builder()
      .setFirefoxOptions(ffoptions)
      .forBrowser('firefox')
      .build();
Run Code Online (Sandbox Code Playgroud)

当手动联系selenium-tester 容器内的http://app:3000using 时curl,它按预期工作,我得到了我的主页。

我现在缺乏想法,甚至分解我的问题来写这个问题也没有给我带来新的问题

rya*_*anp 7

我遇到了完全相同的问题 - 无法在同一网络上的其他 Docker 容器中成功地从 Selenium 控制的浏览器(Chrome 或 Firefox)向应用程序发出 HTTP 请求。来自该容器的 cURL 虽然工作正常!通过 HTTP 连接,但似乎有什么东西试图强制使用 HTTPS。完全相同的情况直到容器“应用程序”的名称。

答案是……是容器的名字!

“app”是 HSTS 预加载列表中的顶级域——也就是说,浏览器将强制通过 HTTPS 访问。

修复方法是使用不在 HSTS 预加载列表中的容器名称。

HSTS - 更多阅读


归档时间:

查看次数:

683 次

最近记录:

6 年,4 月 前