从JAR文件中运行Docker容器中的硒测试

发布于 2025-01-27 21:44:47 字数 1403 浏览 2 评论 0原文

我目前有一个带有3个服务的Docker-Compose文件:

  • Selenium-Hub
  • 节点A
  • 包含我的Selenium Junit测试的容器。

我想在容器的dockerfile中使用命令(含有这些测试)来硒测试(w/ junit)。我考虑过使用selenium-server.jar,但我似乎无法弄清楚exec命令应该是什么(在dockerfile中)。

有人可以帮我吗?

我的docker-compose.yml:

version: "3"
services:
  chrome:
    image: selenium/node-chrome:4.1.4-20220427
    shm_size: 2gb
    container_name: chrome
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
  selenium-hub:
    image: selenium/hub:4.1.4-20220427
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"
  application:
    build: .
    container_name: application
    ports:
      - "4447:4447"
    depends_on:
      - chrome

和我的dockerfile:

#
# Build stage
#
FROM maven:3.6.0-jdk-11-slim AS build
COPY src .
COPY pom.xml .
RUN mvn -f pom.xml jar:test-jar

#
# Package stage
#
FROM openjdk:11-jre-slim
COPY --from=build target/playground-project-selenium-1.0-SNAPSHOT-tests.jar /usr/local/lib/demo.jar
ADD selenium-server.jar .
ENTRYPOINT exec java -jar selenium-server.jar --ext /usr/local/lib/demo.jar:selenium/node-chrome standalone --port 4447
EXPOSE 4447

I currently have a docker-compose file with 3 services:

  • selenium-hub
  • chrome-node
  • a container containing my selenium JUnit tests.

I want to selenium-test (w/ JUnit) my JAR file (containing these tests) with a command in the container's Dockerfile. I thought about using the selenium-server.jar but I can't seem to figure out what the exec command should be (in the Dockerfile).

Anyone can help me out?

My docker-compose.yml:

version: "3"
services:
  chrome:
    image: selenium/node-chrome:4.1.4-20220427
    shm_size: 2gb
    container_name: chrome
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
  selenium-hub:
    image: selenium/hub:4.1.4-20220427
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"
  application:
    build: .
    container_name: application
    ports:
      - "4447:4447"
    depends_on:
      - chrome

And my Dockerfile:

#
# Build stage
#
FROM maven:3.6.0-jdk-11-slim AS build
COPY src .
COPY pom.xml .
RUN mvn -f pom.xml jar:test-jar

#
# Package stage
#
FROM openjdk:11-jre-slim
COPY --from=build target/playground-project-selenium-1.0-SNAPSHOT-tests.jar /usr/local/lib/demo.jar
ADD selenium-server.jar .
ENTRYPOINT exec java -jar selenium-server.jar --ext /usr/local/lib/demo.jar:selenium/node-chrome standalone --port 4447
EXPOSE 4447

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情归归情 2025-02-03 21:44:47

经过经过经过反复试验的会议,我设法回答了自己的问题。我创建了一个包含所有测试,资源和依赖项的所谓脂肪Jar(使用Maven组装插件),并且我将Junit 4与org.junit.runner.junitcore.junitcore类一起运行测试套件。

现在,我的Selenium UI测试正在使用Selenium Hub和Chrome驱动程序在单独的容器中完全运行在Docker容器中。

After some sessions of trial-and-error, I've managed to answer my own question. I created a so-called Fat-JAR (using the maven assembly plugin) containing all tests, resources and dependencies and I used JUnit 4 with the org.junit.runner.JUnitCore class to run a test suite.

Now, my selenium UI tests are fully running in a Docker container using selenium hub and chrome driver in separate containers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文