簡體   English   中英

Selenium Grid:使用RemoteWebDriver自定義瀏覽器位置

[英]Selenium Grid: Use custom browser location with RemoteWebDriver

我正在使用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安裝的瀏覽器?

選項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:為webdriver.firefox.bin屬性指定正確版本的firefox.exe的路徑

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

NODE1:

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

NODE2:

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和移動測試自動化驅動程序之間的區別

希望這可以幫助。

您的目標是擁有一個多版本的selenium網格。 每個節點都設計為使用單個瀏覽器可執行路徑,可以是OS的默認路徑,也可以手動指定為Java參數。

您可以在遠程計算機中啟動多個節點並將它們連接到同一個集線器。 每個節點可以運行不同的瀏覽器可執 我還建議為每個節點使用docker容器,以避免瀏覽器在幕后進行的任何緩存問題,或者至少為每種執行類型使用自定義瀏覽器配置文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM