ChromeDriverService
をchromeOptions
またはDesiredCapabilities
とマージして、xvfbでブラウザを実行したいとします。xvfbを使用してヘッドレスのChromeのドライバサービスを希望する機能とマージするにはどうすればよいですか?
以下はコードChromeDriverService
の一部です。以前はセレニウムグリッドなしで使用しました。
String NodeChromeIncognito = "http://localhost:5558/wd/hub"
ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("driver_linux/chromedriver"))
.usingAnyFreePort()
.withEnvironment(ImmutableMap.of("DISPLAY", ":1")).build();
chromeDriverService.start();
// commented because using RemoteWebDriver
// driver = new ChromeDriver(chromeDriverService);
以下私はChromeDriverService
と合併するRemoteWebDriverの部品コードです。
DesiredCapabilities cap = null;
String NodeChromeIncognito = "http://localhost:5558/wd/hub";
String NodeChrome = "http://localhost:5557/wd/hub";
String NodeFirefox = "http://localhost:5556/wd/hub";
if (browserName.equals("chrome")) {
cap = DesiredCapabilities.chrome();
cap.setBrowserName("chrome");
driver = new RemoteWebDriver(new URL(NodeChrome), cap);
} else if (browserName.equals("firefox")) {
System.setProperty("webdriver.gecko.driver", "driver_linux/geckodriver");
cap = DesiredCapabilities.firefox();
cap.setCapability("marionette", true);
driver = new RemoteWebDriver(new URL(NodeFirefox), cap);
}else if (browserName.equals("chromeIncognito")) {
ChromeOptions option = new ChromeOptions();
option.addArguments("--incognito");
cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, option);
cap.setPlatform(Platform.WIN10);
cap.setBrowserName("chrome incognito");
driver = new RemoteWebDriver(new URL(NodeChromeIncognito), cap);
}
私はクロームのためaddArguments("--headless")
を使用することができます知っているが、それは私のWebアプリケーションでうまく動作しません。また、私はDesiredCapabilities.merge
とエラーを使用しました。
コード/設定ChromeDriverService
をChromeOptions
またはDesiredCapabilites
にマージするにはどうすればよいですか?
ねえMysoundマジック@オーバーフロースタックを歓迎する適切な形式である必要があり、心の問題への投稿に保管してください簡単に理解できます。 – Dilip