简体   繁体   English

How to run maven selenium project in docker (Maven + Selenium + java + TestNg + docker)

[英]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:项目设立:

  1. Selenium webdriver with Java Selenium webdriver 与 Java
  2. Maven as build tool Maven 作为构建工具
  3. TestNg framework TestNg 框架
  4. Running test case thru maven run config, which runs the test cases updated in testng.xml通过 maven 运行配置运行测试用例,它运行在 testng.xml 中更新的测试用例

What I understand from few helpful articles:我从几篇有用的文章中了解到:

  • need to create test case jar需要创建测试用例 jar
  • create image and run the image in docker.在 docker 中创建镜像并运行镜像。

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.

相关问题 Java maven selenium webdriver 在 docker 容器中不起作用 - Java maven selenium webdriver not working in docker container Java maven selenium 不在 Z05B6053C41A2130AFD6FC3B158BDA 容器中工作 - Java maven selenium not working in a docker container Selenium Java(maven项目):TestNG结果与ReportNG不同 - Selenium Java (maven project): TestNG results differs from ReportNG 在 docker 中运行整个 selenium 项目(Gradle + Selenium + java + junit + docker) - Run whole selenium project in docker (Gradle + Selenium + java + junit + docker) Maven + AspectJ + TestNG + Selenium - Maven + AspectJ + TestNG + Selenium 如何将我的Eclipse Maven Selenium Webdriver TestNG Java项目从一台PC转移到另一台PC? - How to transfer my Eclipse Maven Selenium Webdriver TestNG Java project from one PC to another? Testng和Maven,Java Selenium的魅力报告问题 - Allure reporting issue with testng and maven, java selenium 如何远程执行测试代码(maven/java/testNG/selenium)? - How to execute test code (maven/java/testNG/selenium) remotely? Maven项目(Cucumber + TestNG + Selenium-Java)测试无法使用mvn clean install在命令行上运行测试 - Maven Project(Cucumber+TestNG+Selenium-Java] Test Can't Run test on command line with mvn clean install 从命令行运行带有selenium(TestNG)的maven项目需要什么配置? - What configuration required to run maven project with selenium (TestNG) from command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM