【发布时间】:2022-01-16 14:07:43
【问题描述】:
我正在设置一个测试套件来访问一些内部(最终是外部 [生产] 以替换 pingdom),但是现在当我在 eclipse 中运行它时,所有其他“作为 Java 应用程序运行”的调用都会挂起,留下一些僵尸进程,并且什么也不输出(我猜从挂起部分很明显)。但是如果我杀死它(仍然在 Eclipse 中),然后重新启动,它会立即输出页面并且不会留下僵尸进程。所以为了形象化,它是这样工作的:
- 以 java 应用程序运行,并打印出我期望的结果
- 在 java 应用程序挂起时运行并且几乎什么都不做(除了产生僵尸进程)
- 以 java 应用程序运行,并打印出我期望的结果
- 在 java 应用程序挂起时运行并且几乎什么都不做(除了产生僵尸进程)
- ...
Jerry$ ps -ef | grep -i headless | wc
16 511 15011
Jerry$ ps -ef | grep -i headless | wc
21 678 19990
Jerry$ ps -ef | grep -i headless | wc
21 678 19990
Jerry$ ps -ef | grep -i headless | wc
26 845 24977
我已经尝试了几次,所以您可以看到它从 16 开始,经过几次运行后,现在是 26 个仍在后台运行的僵尸(孤立?)进程。
现在,代码:
public class SeleniumTest {
public static void main(String[] args) {
// Globally set the driver location
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
// Locally pass in the options
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--no-sandbox");
// Create the driver, download, and test
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("http://192.168.2.15:8080/testApp/m/getBeans2");
System.out.println(driver.getPageSource());
System.out.println(driver.getCurrentUrl());
// This block was introduced around the 21 mark as I was testing if I had to
// quit first between subsequent calls, so calling it twice didn't lead to the
// initial 16 zombie processes, just the call to the QA server above
System.out.println("-------------------- LOCALHOST --------------------");
driver.get("http://localhost:8080/testApp/m/getBeans2");
System.out.println(driver.getPageSource());
System.out.println(driver.getCurrentUrl());
driver.quit();
}
}
现在我正在使用 Open JDK 11、Chrome 驱动程序 95.0.4638.69 和这个版本的 selenium:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.0</version>
</dependency>
那么...为什么我会得到 Zombies/孤立进程 - 这是我必须在运行之间清理的东西吗?
【问题讨论】:
-
本题目前多题合一。它应该只关注一个问题。
-
@Prophet 重点将是主要问题,即标题;如果您认为这会让其他人回答,我可以删除后续问题,但没有人尝试过
标签: java selenium selenium-webdriver