gpt4 book ai didi

java - docker-compose selenium-grid、maven、java。用于设置功能的空 VM 池

转载 作者:太空宇宙 更新时间:2023-11-04 09:21:16 25 4
gpt4 key购买 nike

我正在尝试在 docker 容器中运行 selenium java 项目:

我的 docker-compose.yml:

version: '3'
services:
hub:
image: selenium/hub:3.141.59-vanadium
container_name: hub
ports:
- "4444:4444"

firefox:
image: selenium/node-firefox:3.141.59-vanadium
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
- HUB_HOST=hub
- HUB_PORT=4444

mongo:
image: 'mongo:4.0.4'
ports:
- '27017:27017'
volumes:
- 'mongo:/data/db'

app:
image: app:latest
ports:
- "5050:5050"
depends_on:
- mongo
- firefox

volumes:
mongo:

我的 java 应用程序的 Dockerfile:

#
# Build stage
#
FROM maven:3.6.0-jdk-11-slim AS build
COPY src /home/app/src
COPY pom.xml /home/app

# build jar with dependencies
RUN mvn -f /home/app/pom.xml clean compile assembly:single

#
# Package stage
#
FROM openjdk:11-jre-slim
COPY --from=build /home/app/target/app-1.0-SNAPSHOT-jar-with-dependencies.jar /usr/local/lib/app.jar
EXPOSE 5001
ENTRYPOINT ["java","-jar","/usr/local/lib/app.jar", "docker"]

来自 pom.xml 的插件:

    <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>learn.selenium.Main</mainClass>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>learn.selenium.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>learn.selenium.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>

从代码连接到selenium:

Capabilities firefoxCapabilities = new FirefoxOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://hub:4444/wd/hub"), firefoxCapabilities);

当我尝试仅使用 selenium 运行 docker compose 时,看起来效果很好。但是当我将 java 应用程序添加到容器时,出现以下错误:

hub        | org.openqa.grid.common.exception.GridException: Empty pool of VM for setup Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:firefoxOptions: {args : {}}}
hub | at org.openqa.grid.internal.ProxySet.verifyAbilityToHandleDesiredCapabilities(ProxySet.java:146)
...
app_1 | org.openqa.selenium.WebDriverException: Error forwarding the new session Empty pool of VM for setup Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:firefoxOptions: {args: [], prefs: {}}}
app_1 | Command duration or timeout: 453 milliseconds
app_1 | at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

这是网格控制台: http://localhost:4444/grid/console

你能告诉我我做错了什么吗?

最佳答案

好吧,在我尝试连接集线器时,集线器似乎尚未准备好。因此,为了进行测试,我添加了 Thread.sleep(1000) 并且它起作用了。我认为正确的方法是对集线器执行 ping 操作,并在状态更改为就绪后继续进行 Web 驱动程序初始化。对我来说这很奇怪,因为我添加了

 depends_on:
- mongo
- firefox

所以我希望我的 java 项目在与 selenium 相关的容器启动并准备就绪后运行。

关于java - docker-compose selenium-grid、maven、java。用于设置功能的空 VM 池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58301134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com