0

我正在使用 Selenium 网格在远程机器上运行一些测试。这就是我启动集线器一台远程机器A的方式

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 浏览器。但是,我想启动位于“/opt/firefox/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

4

2 回答 2

0

选项 A:提供版本二进制文件的路径

FirefoxBinary binary = new FirefoxBinary(new File("path_to_bin"));
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(binary, profile);

选项 B

System.setProperty("webdriver.gecko.driver","path of geckodriver.exe");
 WebDriver driver = new FirefoxDriver();

选项 C:将正确版本的 firefox.exe 的路径分配给 webdriver.firefox.bin 属性

System.setProperty("webdriver.firefox.bin", "c:\\path\\to\\firefox.exe");

还让我分享我的单个(本地机器)的 GRID 配置: HUB

java -jar selenium-server-standalone-3.11.0.jar -role hub -hubConfig hub.json & pause

节点1:

java -jar -Dwebdriver.gecko.driver=geckodriver.exe -Dwebdriver.chrome.driver=chromedriver.exe selenium-server-standalone-3.11.0.jar -role node -nodeConfig node1.json & pause

节点2:

java -jar -Dwebdriver.gecko.driver=geckodriver.exe -Dwebdriver.chrome.driver=chromedriver.exe selenium-server-standalone-3.11.0.jar -role node -nodeConfig node2.json & pause

如果您需要 .json 配置,请告诉我(我也可以提供)。

抛开范围- Web 和移动测试自动化驱动程序之间的区别和区别

希望这可以帮助。

于 2019-05-12T10:48:53.987 回答
0

您的目标是拥有一个多版本的 selenium 网格。每个节点都设计为使用单个浏览器可执行路径,可以是操作系统的默认路径,也可以是手动指定为 Java 参数。

您可以在远程计算机中启动多个节点并将它们连接到同一个集线器。每个节点可以运行不同的浏览器可执行文件。我还建议为每个节点使用 docker 容器,以避免浏览器在后台执行的任何缓存问题,或者至少为每种执行类型使用自定义浏览器配置文件。

于 2019-05-23T21:32:55.833 回答