收到此 Selenium 服务器错误:[1567550645.996][SEVERE]:bind() 失败:无法分配请求的地址 (99)

收到此 Selenium 服务器错误:[1567550645.996][SEVERE]:bind() 失败:无法分配请求的地址 (99)

我正在尝试在 EC2 服务器上设置 Selenium Grid,以下是我迄今为止采取的步骤。

  1. 在端口 4044 上启动 hub

    java -jar /ebst/wrangler/upla/bin/selenium-server-standalone-3.141.59.jar -role hub -port 4044
    
  2. 在 4045 上注册一个节点

    java -Dwebdriver.chrome.driver="~/chromedriver" -jar ~/selenium-server-standalone-3.141.59.jar -role node -hub http://hubURL:4044/grid/register -port 4045
    
  3. 在我的 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 应该在同一端口运行。

相关内容