![收到此 Selenium 服务器错误:[1567550645.996][SEVERE]:bind() 失败:无法分配请求的地址 (99)](https://linux22.com/image/1602512/%E6%94%B6%E5%88%B0%E6%AD%A4%20Selenium%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%94%99%E8%AF%AF%EF%BC%9A%5B1567550645.996%5D%5BSEVERE%5D%EF%BC%9Abind()%20%E5%A4%B1%E8%B4%A5%EF%BC%9A%E6%97%A0%E6%B3%95%E5%88%86%E9%85%8D%E8%AF%B7%E6%B1%82%E7%9A%84%E5%9C%B0%E5%9D%80%20(99).png)
我正在尝试在 EC2 服务器上设置 Selenium Grid,以下是我迄今为止采取的步骤。
在端口 4044 上启动 hub
java -jar /ebst/wrangler/upla/bin/selenium-server-standalone-3.141.59.jar -role hub -port 4044
在 4045 上注册一个节点
java -Dwebdriver.chrome.driver="~/chromedriver" -jar ~/selenium-server-standalone-3.141.59.jar -role node -hub http://hubURL:4044/grid/register -port 4045
在我的 Java 代码中启动 Webdriver
import cucumber.api.java.Before; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import java.net.MalformedURLException; import java.net.URL; public class Test { WebDriver driver; @Before public void setup() throws MalformedURLException { String nodeURL = "http://hubURL:4044/wd/hub"; System.out.println("setting up"); DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome(); desiredCapabilities.setBrowserName("chrome"); desiredCapabilities.setPlatform(Platform.LINUX); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments( "--verbose", "--headless", "--disable-web-security", "--ignore-certificate-errors", "--allow-running-insecure-content", "--allow-insecure-localhost", "--no-sandbox", "--disable-gpu"); chromeOptions.merge(desiredCapabilities); driver = new RemoteWebDriver(new URL(nodeURL), chromeOptions); System.out.println("setting up done"); } }
在控制台上,我因超时而收到以下错误。
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 3.10.0-1062.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 16 milliseconds Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: 'ip-10-160-169-203.syd.non.c1.macquarie.com', ip: '10.160.169.203', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1062.el7.x86_64', java.version: '1.8.0_181' Driver info: driver.version: unknown Command duration or timeout: 523 milliseconds
当我导航回节点服务器时,显示的消息如下。
22:44:05.604 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService) Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 3459 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. [1567550645.675][SEVERE]: bind() failed: Cannot assign requested address (99) 22:44:05.988 INFO [ActiveSessionFactory.apply] - Capabilities are: { "browserName": "chrome", "goog:chromeOptions": { "args": [ "--verbose", "--headless", "--disable-web-security", "--ignore-certificate-errors", "--allow-running-insecure-content", "--allow-insecure-localhost", "--no-sandbox", "--port:4040", "--disable-gpu" ], "extensions": [ ] }, "platform": "LINUX", "version": "" }
我理解出现此错误的原因是,我们公司只有某些端口可用,而 ChromeDriver 每次都是在随机端口上启动的。为了指定此 ChromeDriver 每次启动的端口,我在 Java 代码中尝试了各种 ChromeOptions 和 RemoteWebDriver 的指定,但都无济于事。
这是在 EC2 上启动 Selenium 服务器的正确方法吗?
任何帮助都将不胜感激!
答案1
尝试以下命令:
java -Dwebdriver.chrome.driver="<path-of-chromedriver>" -jar ~/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar -port 4444
我认为 ChromeDriver 和 Selenium 应该在同一端口运行。