【问题标题】:Specify the port ChromeDriver runs指定 ChromeDriver 运行的端口
【发布时间】:2020-01-06 23:12:07
【问题描述】:

H 社区,我正在尝试在 EC2 服务器上设置 Selenium Grid,以下是我目前采取的步骤。

1.在端口 4044 上启动集线器

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:未知错误:找不到 Chrome 二进制文件

(驱动程序信息:chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 3.10.0-1062.el7.x86_64 x86_64)(警告:服务器没有提供任何堆栈跟踪信息)

命令持续时间或超时:16 毫秒

构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018-11-14T08:25:53' 系统信息:主机:'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.version:未知命令持续时间或超时:523 毫秒

当我导航回节点服务器时,这是显示的消息。

22:44:05.604 INFO [ActiveSessionFactory.lambda$apply$11] - 匹配工厂 org.openqa.selenium.grid.session.remote.ServicedSession$Factory(提供者:org.openqa.selenium.chrome.ChromeDriverService)

在端口 3459 上启动 ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29})

只允许本地连接。

请保护 ChromeDriver 和相关测试框架使用的端口,防止恶意代码访问。

[1567550645.675][SEVERE]:bind() 失败:无法分配请求的地址 (99)

22:44:05.988 信息 [ActiveSessionFactory.apply] - 功能是:{ “浏览器名称”:“铬”, “谷歌:chromeOptions”:{ “参数”:[ “--详细”, “——无头”, “--禁用网络安全”, “--忽略证书错误”, “--allow-running-insecure-content”, "--allow-insecure-localhost", “--无沙盒”, “--端口:4040”, “--禁用-GPU” ], “扩展”:[ ] }, “平台”:“Linux”, “版本”: ”” }

我了解该错误的发生是因为在我们公司内部,只有某些端口可用,并且 ChromeDriver 每次都在随机端口上启动。为了每次都指定这个 ChromeDriver 启动的端口,我在 Java 代码中尝试了我的 ChromeOptions 和 RemoteWebDriver 的各种规范,但没有成功。

其他人也遇到过这个问题吗?如果是这样,你能给我建议怎么做吗?或者更广泛地说,这是在 EC2 上启动 selenium 服务器的正确方法吗? 任何帮助将不胜感激!

【问题讨论】:

标签: java selenium selenium-webdriver amazon-ec2 selenium-grid


【解决方案1】:

尝试将-Dwebdriver.chrome.whitelistedIps= 传递给chromedriver

喜欢

java -Dwebdriver.chrome.driver="~/chromedriver" -Dwebdriver.chrome.whitelistedIps= -jar ~/selenium-server-standalone-3.141.59.jar -role node -hub http://hubURL:4044/grid/register -port 4045

【讨论】:

    【解决方案2】:

    尝试使用它来启动 chromedriver:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--whitelisted-ips");
    ChromeDriver driver = new ChromeDriver(options);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    相关资源
    最近更新 更多