0

我想要三个连接的 docker 容器(在构建服务器上运行它):

  1. 我的应用程序(名称:app)
  2. 浏览器(在本例中为 chrome;名称:selenium)
  3. 我的 End2End/UI 测试(名称测试员)

但是测试没有运行。来自测试器容器的当前错误消息是“由于未知错误,请求失败,状态为 500:net::ERR_SSL_PROTOCOL_ERROR”

文件结构:

dir
  test
    specs
      basic.js
  app.js
  docker-compose.yml
  Dockerfile
  package.json
  wdio.conf.js

这里是我的文件:“docker-compose.yml”:

version: '3'

services:
  tester:
    build:
      context: .
      target: e2e-tests
    command: npx wdio wdio.conf.js
    links:
      - selenium

  selenium:
    image: selenium/standalone-chrome
    expose:
      - "4444"
    links:
      - app

  app:
    build:
      context: .
      target: prod
    expose:
      - "3000"
    command: npm start

“Dockerfile”:

FROM node:12 as base
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install


FROM base as prod
COPY app.js ./
EXPOSE 3000


FROM base as e2e-tests
COPY wdio.conf.js ./
COPY test test

“wdio.conf.js”:

exports.config = {
  hostname: 'selenium',
    path: '/wd/hub',
    specs: [
        './test/specs/**/*.js'
    ],
    exclude: [],
    maxInstances: 10,
    capabilities: [{
        maxInstances: 5,
        browserName: 'chrome',
        acceptInsecureCerts: true
    }],
    logLevel: 'info',
    bail: 0,
    baseUrl: 'http://localhost',
    waitforTimeout: 10000,
    connectionRetryTimeout: 120000,
    connectionRetryCount: 3,
    framework: 'jasmine',
    reporters: ['spec'],
    jasmineNodeOpts: {
        defaultTimeoutInterval: 60000,
        expectationResultHandler: function(passed, assertion) {}
    },
}

“测试/规范/basic.js”:

describe('test app', () => {
    it('should have the right title', () => {
        browser.url('http://app:3000')
        expect(browser).toHaveTextContaining('Hello');
    })
})

“app.js”:

const express = require('express');
const app = express();

app.get('/', (req, res) => res.send('<html><head><title>Hello</title></head><body>Hello World!</body></html>'));

const server = app.listen(3000, () => {
  const { port } = server.address();
  console.log(`Test app listening on port ${port}`);
});

“包.json”:

{
  "name": "wdiodocker",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {
    "@wdio/cli": "^6.5.2",
    "@wdio/jasmine-framework": "^6.5.0",
    "@wdio/local-runner": "^6.5.2",
    "@wdio/spec-reporter": "^6.4.7",
    "@wdio/sync": "^6.5.0",
    "wdio-docker-service": "^3.0.0"
  }
}

“日志中的更大片段”:

tester_1    | 2020-09-28T07:55:11.844Z INFO @wdio/cli:launcher: Run onPrepare hook
tester_1    | 2020-09-28T07:55:11.848Z INFO @wdio/cli:launcher: Run onWorkerStart hook
tester_1    | 2020-09-28T07:55:11.850Z INFO @wdio/local-runner: Start worker 0-0 with arg: wdio.conf.js
selenium_1  | 07:55:12.017 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
selenium_1  | 2020-09-28 07:55:12.150:INFO::main: Logging initialized @1038ms to org.seleniumhq.jetty9.util.log.StdErrLog
tester_1    | [0-0] 2020-09-28T07:55:12.634Z INFO @wdio/local-runner: Run worker command: run
tester_1    | [0-0] 2020-09-28T07:55:12.658Z INFO webdriverio: Initiate new session using the ./protocol-stub protocol
selenium_1  | 07:55:12.862 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
tester_1    | [0-0] RUNNING in chrome - /test/specs/basic.js
tester_1    | [0-0] 2020-09-28T07:55:13.056Z INFO webdriverio: Initiate new session using the webdriver protocol
tester_1    | [0-0] 2020-09-28T07:55:13.060Z INFO webdriver: [POST] http://selenium:4444/wd/hub/session
tester_1    | [0-0] 2020-09-28T07:55:13.061Z INFO webdriver: DATA {
tester_1    |   capabilities: {
tester_1    |     alwaysMatch: { browserName: 'chrome', acceptInsecureCerts: true },
tester_1    |     firstMatch: [ {} ]
tester_1    |   },
tester_1    |   desiredCapabilities: { browserName: 'chrome', acceptInsecureCerts: true }
tester_1    | }
selenium_1  | 07:55:13.122 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
selenium_1  | 07:55:13.331 INFO [ActiveSessionFactory.apply] - Capabilities are: {
selenium_1  |   "acceptInsecureCerts": true,
selenium_1  |   "browserName": "chrome"
selenium_1  | }
selenium_1  | 07:55:13.335 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
selenium_1  | Starting ChromeDriver 85.0.4183.83 (94abc2237ae0c9a4cb5f035431c8adfb94324633-refs/branch-heads/4183@{#1658}) on port 24508
selenium_1  | Only local connections are allowed.
selenium_1  | Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
selenium_1  | ChromeDriver was started successfully.
selenium_1  | [1601279713.386][SEVERE]: bind() failed: Cannot assign requested address (99)
selenium_1  | 07:55:14.377 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C
selenium_1  | 07:55:14.428 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 82d59567606b7f101da8650600e7dd00 (org.openqa.selenium.chrome.ChromeDriverService)
tester_1    | [0-0] 2020-09-28T07:55:14.607Z INFO webdriver: COMMAND navigateTo("http://app:3000/")
tester_1    | [0-0] 2020-09-28T07:55:14.610Z INFO webdriver: [POST] http://selenium:4444/wd/hub/session/82d59567606b7f101da8650600e7dd00/url
tester_1    | [0-0] 2020-09-28T07:55:14.611Z INFO webdriver: DATA { url: 'http://app:3000/' }
tester_1    | [0-0] 2020-09-28T07:55:15.188Z WARN webdriver: Request failed with status 500 due to unknown error: net::ERR_SSL_PROTOCOL_ERROR
tester_1    |   (Session info: chrome=85.0.4183.83)
tester_1    | [0-0] 2020-09-28T07:55:15.189Z INFO webdriver: Retrying 1/3
tester_1    | [0-0] 2020-09-28T07:55:15.190Z INFO webdriver: [POST] http://selenium:4444/wd/hub/session/82d59567606b7f101da8650600e7dd00/url
tester_1    | [0-0] 2020-09-28T07:55:15.191Z INFO webdriver: DATA { url: 'http://app:3000/' }
tester_1    | [0-0] 2020-09-28T07:55:15.592Z WARN webdriver: Request failed with status 500 due to unknown error: net::ERR_SSL_PROTOCOL_ERROR
tester_1    |   (Session info: chrome=85.0.4183.83)
tester_1    | [0-0] 2020-09-28T07:55:15.592Z INFO webdriver: Retrying 2/3
tester_1    | [0-0] 2020-09-28T07:55:15.594Z INFO webdriver: [POST] http://selenium:4444/wd/hub/session/82d59567606b7f101da8650600e7dd00/url
tester_1    | [0-0] 2020-09-28T07:55:15.595Z INFO webdriver: DATA { url: 'http://app:3000/' }
tester_1    | [0-0] 2020-09-28T07:55:15.942Z WARN webdriver: Request failed with status 500 due to unknown error: net::ERR_SSL_PROTOCOL_ERROR
tester_1    |   (Session info: chrome=85.0.4183.83)
tester_1    | [0-0] 2020-09-28T07:55:15.943Z INFO webdriver: Retrying 3/3
tester_1    | [0-0] 2020-09-28T07:55:15.944Z INFO webdriver: [POST] http://selenium:4444/wd/hub/session/82d59567606b7f101da8650600e7dd00/url
tester_1    | [0-0] 2020-09-28T07:55:15.945Z INFO webdriver: DATA { url: 'http://app:3000/' }
tester_1    | [0-0] 2020-09-28T07:55:16.104Z ERROR webdriver: Request failed with status 500 due to unknown error: unknown error: net::ERR_SSL_PROTOCOL_ERROR
tester_1    |   (Session info: chrome=85.0.4183.83)
tester_1    | [0-0] Error in "test app should have the right title"
tester_1    | unknown error: unknown error: net::ERR_SSL_PROTOCOL_ERROR
tester_1    |   (Session info: chrome=85.0.4183.83)
tester_1    | [0-0] 2020-09-28T07:55:16.118Z INFO webdriver: COMMAND deleteSession()
tester_1    | [0-0] 2020-09-28T07:55:16.119Z INFO webdriver: [DELETE] http://selenium:4444/wd/hub/session/82d59567606b7f101da8650600e7dd00
selenium_1  | 07:55:16.196 INFO [ActiveSessions$1.onStop] - Removing session 82d59567606b7f101da8650600e7dd00 (org.openqa.selenium.chrome.ChromeDriverService)
tester_1    | [0-0] FAILED in chrome - /test/specs/basic.js
tester_1    | 2020-09-28T07:55:16.299Z INFO @wdio/cli:launcher: Run onComplete hook
tester_1    |
tester_1    |  "spec" Reporter:
tester_1    | ------------------------------------------------------------------
tester_1    | [chrome 85.0.4183.83 linux #0-0] Spec: /usr/src/app/test/specs/basic.js
tester_1    | [chrome 85.0.4183.83 linux #0-0] Running: chrome (v85.0.4183.83) on linux
tester_1    | [chrome 85.0.4183.83 linux #0-0] Session ID: 82d59567606b7f101da8650600e7dd00
tester_1    | [chrome 85.0.4183.83 linux #0-0]
tester_1    | [chrome 85.0.4183.83 linux #0-0] test app
tester_1    | [chrome 85.0.4183.83 linux #0-0]    ✖ should have the right title
tester_1    | [chrome 85.0.4183.83 linux #0-0]
tester_1    | [chrome 85.0.4183.83 linux #0-0] 1 failing (1.6s)
tester_1    | [chrome 85.0.4183.83 linux #0-0]
tester_1    | [chrome 85.0.4183.83 linux #0-0] 1) test app should have the right title
tester_1    | [chrome 85.0.4183.83 linux #0-0] unknown error: unknown error: net::ERR_SSL_PROTOCOL_ERROR
tester_1    |   (Session info: chrome=85.0.4183.83)
tester_1    | [chrome 85.0.4183.83 linux #0-0]     at <Jasmine>
tester_1    | [chrome 85.0.4183.83 linux #0-0]     at processTicksAndRejections (internal/process/task_queues.js:97:5)
tester_1    | [chrome 85.0.4183.83 linux #0-0]     at UserContext.<anonymous> (/usr/src/app/test/specs/basic.js:3:17)

一些提示:

  • 当我从测试仪或硒容器中调用 curl http://app:3000 时,我按预期收到了 HTML。
  • 当我在测试中导航到谷歌时,我收到了谷歌代码
  • 感谢您的时间!
4

0 回答 0