有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Selenium Grid:使用RemoteWebDriver的自定义浏览器位置

我正在使用Selenium grid在远程机器上运行一些测试。这就是我如何启动hub one远程机器的方法

java -jar /usr/local/lib/selenium-server-standalone-3.141.0.jar -role hub

这就是我在远程机器B上启动节点的方式

java -Dwebdriver.gecko.driver="/opt/foxdriver" -jar "$HOME/selenium-server-standalone-3.141.0.jar" -role webdriver -hub "http://192.168.100.99:4444/grid/register/" -port 9999

这是在远程计算机上启动浏览器的类:

package seleniumgrid;

import static java.lang.Thread.sleep;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class Seleniumgrid {
WebDriver driver;
String baseURL, nodeURL;

public static void main(String[] args)
        throws MalformedURLException, InterruptedException {
    Seleniumgrid grid = new Seleniumgrid();
    grid.doit();
}

void doit() throws MalformedURLException, InterruptedException {
    String nodeURL = "http://192.168.100.100:9999/wd/hub";
    DesiredCapabilities caps = DesiredCapabilities.firefox();
    caps.setBrowserName("firefox");
    caps.setPlatform(Platform.LINUX);

    driver = new RemoteWebDriver(new URL(nodeURL), caps);

    sleep(60000L);

    driver.quit();
}

上面的代码启动安装在远程节点(机器B)上的Firefox浏览器。不过,我想启动另一个版本的Firefox,它位于“/opt/Firefox/Firefox”中。我试过了

caps.setBrowserName("/opt/firefox/firefox");

但这只会引发以下异常:

INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
  "desiredCapabilities": {
    "browserName": "\u002fopt\u002fautobrowse\u002ffirefox\u002ffox\u002ffirefox",
    "version": "",
    "platform": "LINUX",
    "acceptInsecureCerts": true
  },
  "capabilities": {
    "firstMatch": [
      {
        "acceptInsecureCerts": true,
        "browserName": "\u002fopt\u002fautobrowse\u002ffirefox\u002ffox\u002ffirefox",
        "platformName": "linux"
      }
    ]
  }
}
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:22:52'
System info: host: 'machineB', ip: '192.168.100.100', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.172', java.version: '1.8.0_192'
Driver info: driver.version: unknown
Command duration or timeout: 202 milliseconds
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
        at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
        at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
        at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
        at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
        at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
        at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:125)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
        at seleniumgrid.Seleniumgrid.doit(Seleniumgrid.java:29)
        at seleniumgrid.Seleniumgrid.main(Seleniumgrid.java:18)
 Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
  "desiredCapabilities": {
    "browserName": "\u002fopt\u002fautobrowse\u002ffirefox\u002ffox\u002ffirefox",
    "version": "",
    "platform": "LINUX",
    "acceptInsecureCerts": true
  },
  "capabilities": {
    "firstMatch": [
      {
        "acceptInsecureCerts": true,
        "browserName": "\u002fopt\u002fautobrowse\u002ffirefox\u002ffox\u002ffirefox",
        "platformName": "linux"
      }
    ]
  }
}

有没有办法在/opt/firefox/firefox中使用浏览器,而不是安装在RemoteWebDriver中的浏览器


共 (0) 个答案