[英]How to run maven selenium project in docker (Maven + Selenium + java + TestNg + docker)
I need to run the selenium test cases into docker.我需要将 selenium 测试用例运行到 docker 中。 I referred multiple articles are tried the same.
我提到的多篇文章都试过了。 I could run the test case in docker which has only selenium set up.
我可以在 docker 中运行测试用例,它只设置了 selenium。 But my project is maven build which I want to run in docker.
但我的项目是 maven 构建,我想在 docker 中运行。
Project set up:项目设立:
What I understand from few helpful articles:我从几篇有用的文章中了解到:
But I am unable to get the make this setup working.但我无法让这个设置正常工作。
I don't have experience using TestNg, but I run Selenium testing through maven in docker with the below configuration:我没有使用 TestNg 的经验,但我通过 maven 运行 Selenium 测试,配置如下:
docker-compose.yml (this will allow you to connect to a separate selenium docker container) docker-compose.yml(这将允许您连接到单独的 selenium docker 容器)
image: selenium/standalone-firefox
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
expose:
- 4444
maven_container:
build: . # uses Dockerfile
links:
- remote-webdriver
volumes:
- <your local volume>:<container volume>
stdin_open: true
tty: true
entrypoint: /bin/sh
In your pom.xml in the "maven_container" be sure to include the selenium dependency (see below).在“maven_container”中的 pom.xml 中,确保包含 selenium 依赖项(见下文)。
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
Finally, the docker image for the "maven_container".最后,“maven_container”的 docker 映像。 Notice we need to copy our local pom.xml over the generic pom.xml generated if we want to run mvn build, etc. before mounting volumes in docker-compose.
请注意,如果我们想在 ZBAEDB53E845AE71F13945FCC00572AE9 中安装卷之前运行 mvn build 等,我们需要将本地 pom.xml 复制到生成的通用 pom.xml 上。
FROM zenika/alpine-maven
RUN apk update \
&& apk add ca-certificates wget \
&& update-ca-certificates
RUN apk add vim
RUN mvn archetype:generate -B \
-DarchetypeGroupId=net.alchim31.maven -DarchetypeArtifactId=<intended artifact ID> -DarchetypeVersion=1.7 \
-DgroupId=com.myproject -DartifactId=MyProject -Dversion=0.1-SNAPSHOT -Dpackage=com.scalascrape
WORKDIR /usr/src/app/MyProject
RUN rm pom.xml
COPY pom.xml .
Notice.注意。 you will have to wait on the selenium server to boot before you connect to it.
在连接到它之前,您必须等待 selenium 服务器启动。 This is an important consideration if you want to run your tests with the
docker-compose up
command.如果您想使用
docker-compose up
命令运行测试,这是一个重要的考虑因素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.