带有opera和edge浏览器的远程webdriver

时间:2017-11-24 16:30:23

标签: java selenium microsoft-edge opera remotewebdriver

无法通过集线器连接到opera和edge webdriver。 我的程序:

  • 在cmd中启动集线器:

       java -jar C:\path\to\selenium-server-standalone-3.7.1.jar -role hub 
    
  • 在cmd中启动节点:

            java -Dwebdriver.opera.driver=C:\path\to\operadriver.exe -
            Dwebdriver.edge.driver=C:\path\to\MicrosoftWebDriver.exe -jar 
            C:\path\to\selenium-server-standalone-
            3.7.1.jar -role node -hub http://mylocalhost:4444/grid/register 
            -browser "browserName=opera,maxInstances=5,platform=Windows" -
            browser "browserName=edge,maxInstances=5,platform=Windows"
    

为Opera运行此测试:

               WebDriver driver;
               String nodeURL;
               nodeURL = "http://mylocalhost:5555/wd/hub";
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("opera");
        capabilities.setPlatform(Platform.WINDOWS);
        driver = new RemoteWebDriver(new URL(nodeURL), capabilities);
        driver.get("https://www.google.ru/");

对于Edge:

               WebDriver driver;
               String nodeURL;
               nodeURL = "http://mylocalhost:5555/wd/hub";
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("opera");
        capabilities.setPlatform(Platform.WINDOWS);
        driver = new RemoteWebDriver(new URL(nodeURL), capabilities);
        driver.get("https://www.google.ru/");

这是Opera的例外:

    org.openqa.selenium.WebDriverException: unknown error: cannot find Opera binary

Edge的例外:

org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService

我知道此代码适用于Chrome和Firefox。任何人都知道如何将这个应用于Opera ana Edge?

1 个答案:

答案 0 :(得分:0)

对于Open Opera,您需要设置二进制文件:

DesiredCapabilities capabilities = new DesiredCapabilities.opera();
capabilities.setCapability("opera.binary", "/path/to/your/opera");
capabilities.setCapability("opera.log.level", "CONFIG");
WebDriver driver = new OperaDriver(capabilities);

For Edge - 希望它可以帮到你:

System.setProperty("webdriver.edge.driver", "C:/Program Files (x86)/Microsoft Web Driver/MicrosoftWebDriver.exe");  Your Edge driver path
    DesiredCapabilities capability = DesiredCapabilities.edge();
    capability.setBrowserName("MicrosoftEdge");
    capability.setPlatform(Platform.WIN10);
    WebDriver driver = new EdgeDriver(capability);
    driver.get("http://www.google.com");