これは、このセクションの複数ページの印刷可能なビューです。 印刷するには、ここをクリックしてください.
コンポーネントの構成
- 1: 構成ヘルプ
- 2: Selenium GridのCLI オプション
- 3: Toml オプション
1 - 構成ヘルプ
ヘルプコマンドは、現在のコード実装に基づいて情報を表示します。 したがって、ドキュメントが更新されない場合に備えて、正確な情報を提供します。 それは、新しいバージョンのグリッド 4 の構成について学習する最も簡単な方法です。
Info コマンド
info コマンドは、次のトピックに関する詳細なドキュメントを提供します。
- Selenium の構成
- セキュリティ
- セッションマップの設定
- トレース
構成ヘルプ
クイック設定のヘルプと概要は、以下を実行することで提供されます。
java -jar selenium-server-<version>.jar info config
セキュリティ
安全な通信とノード登録のためのグリッドサーバーの設定の詳細を取得するには、以下を実行します。
java -jar selenium-server-<version>.jar info security
セッションマップの設定
デフォルトでは、グリッドはローカルセッションマップを使用してセッション情報を保存します。 グリッドは、Redis や JDBC-SQL がサポートするデータベースなどの追加のストレージオプションをサポートしています。 別のセッションストレージをセットアップするには、次のコマンドを使用してセットアップ手順を取得します。
java -jar selenium-server-<version>.jar info sessionmap
OpenTelemetry と Jaeger を使用したトレースの設定
デフォルトでは、トレースは有効になっています。 トレースをエクスポートして Jaeger 経由で視覚化するには、次のコマンドを使用して手順を実行します。
java -jar selenium-server-<version>.jar info tracing
SeleniumGrid コマンドを一覧表示する
java -jar selenium-server-<version>.jar --config-help
使用可能なすべてのコマンドとそれぞれの説明が表示されます。
コンポーネントヘルプコマンド
Selenium ロールの後に–help config オプションを渡して、コンポーネント固有の構成情報を取得します。
スタンドアロン
java -jar selenium-server-<version>.jar standalone --help
ハブ
java -jar selenium-server-<version>.jar hub --help
セッション
java -jar selenium-server-<version>.jar sessions --help
新規セッションキュー
java -jar selenium-server-<version>.jar sessionqueue --help
ディストリビューター
java -jar selenium-server-<version>.jar distributor --help
ルーター
java -jar selenium-server-<version>.jar router --help
ノード
java -jar selenium-server-<version>.jar node --help
2 - Selenium GridのCLI オプション
Grid の設定には、さまざまなセクションが用意されています。 各セクションには、コマンドライン引数で設定可能なオプションがあります。コマンドライン引数で設定できます。
コンポーネントとセクションの対応は以下の通りです。
オプションが変更、または追加されたが文書化されていない場合、 このドキュメントは古くなる可能性があることに注意してください。 もしそのような状況を見つけたら、“構成ヘルプ”を確認し、 ドキュメントを更新するプルリクエストを気軽に送ってください。
セクション
スタンドアロン | ハブ | ノード | ディストリビューター | ルーター | セッション | 新規セッションキュー | |
---|---|---|---|---|---|---|---|
Distributor | |||||||
Docker | |||||||
Events | |||||||
Logging | |||||||
Network | |||||||
Node | |||||||
Router | |||||||
Relay | |||||||
Server | |||||||
SessionQueue | |||||||
Sessions |
Distributor
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--healthcheck-interval |
int | 120 |
全てのノードに対してヘルスチェックを実行する頻度(秒)を指定します。これにより、サーバーは全てのノードに対して正常に ping を送信できるようになります。 |
--distributor |
uri | http://localhost:5553 |
ディストリビューターの URL。 |
--distributor-host |
string | localhost |
ディストリビューターがリッスンするホスト名。 |
--distributor-implementation |
string | org.openqa.selenium.grid.distributor.local.LocalDistributor |
デフォルトでないディストリビューター実装の完全なクラス名。 |
--distributor-port |
int | 5553 |
ディストリビューターがリッスンするポート番号。 |
--reject-unsupported-caps |
boolean | false |
Grid がサポートしていない capabilities をリクエストされた時、ディストリビューターがリクエストを即座に今日できるようにします。これはオンデマンドでノードを立ち上げをしない Grid の設定に適しています。 |
--slot-matcher |
string | org.openqa.selenium.grid.data.DefaultSlotMatcher |
デフォルト以外で使用するスロットマッチャーの完全なクラス名。これはノードが特定のセッションをサポートできるかを判断するために使用されます。 |
--slot-selector |
string | org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector |
デフォルト以外のスロットセレクターの完全なクラス名。これは、ノードがマッチした後ノード内のスロットを選択するために使用されます。 |
Docker
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--docker-assets-path |
string | /opt/selenium/assets |
アセットが保存される絶対パス。 |
--docker- |
string[] | selenium/standalone-firefox:latest '{"browserName": "firefox"}' |
イメージとステレオタイプの capabilities を対応付ける Docker 設定 (例 `-D selenium/standalone-firefox:latest ‘{“browserName”: “firefox”}’) |
--docker-devices |
string[] | /dev/kvm:/dev/kvm |
コンテナに対してデバイスを公開します。各デバイスマッピングは、ホストとコンテナの両方のデバイスへのパスを、コロンで区切って保つ必要があります。例: /device/path/in/host:/device/path/in/container |
--docker-host |
string | localhost |
Docker デーモンが動作しているホスト名。 |
--docker-port |
int | 2375 |
Docker デーモンが動作しているポート名。 |
--docker-url |
string | http://localhost:2375 |
Docker デーモンに接続するための URL。 |
--docker-video-image |
string | selenium/video:latest |
ビデオレコーディングが有効になっているときに利用される Docker イメージ。 |
Events
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--bind-bus |
boolean | false |
接続をバインドするかコネクトするかを指定します。 true の場合、コンポーネントはイベントバスにバインドされます(イベントバスもコンポーネントによって起動されます、通常はディストリビューターとハブによって起動されます)。 false の場合、コンポーネントがイベントバスにコネクトします。 |
--events-implementation |
string | org.openqa.selenium.events.zeromq.ZeroMqEventBus |
デフォルトでないイベントバス実装の完全なクラス名。 |
--publish-events |
string | tcp://*:4442 |
イベントをイベントバスに配信するための接続文字列。 |
--subscribe-events |
string | tcp://*:4443 |
イベントをイベントバスから購読するための接続文字列。 |
Logging
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--http-logs |
boolean | false |
http ログを有効にします。http ログを記録するには、トレースを有効にする必要があります。 |
--log-encoding |
string | UTF-8 |
ログのエンコーディング。 |
--log |
string | Windows パスの例: '\path\to\file\gridlog.log' or 'C:\path\path\to\file\gridlog.log' Linux/Unix/MacOS パスの例: '/path/to/file/gridlog.log' |
ログを出力するファイル。OS のファイルパスと互換性があることを確認してください。 |
--log-level |
string | “INFO” |
ログレベル。デフォルトは INFO です。 ログレベルはこちらを参照してください。 https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html |
--plain-logs |
boolean | true |
プレーンなログを使用します。 |
--structured-logs |
boolean | false |
構造化ログを使用します。 |
--tracing |
boolean | true |
トレースを有効にします。 |
--log-timestamp-format |
string | HH:mm:ss.SSS |
ログのタイムスタンプ形式を設定できます。 |
Network
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--relax-checks |
boolean | false |
受信リクエストのオリジンヘッダーとコンテンツタイプに対する、厳格な W3C 準拠の検証をを緩和します。 |
Node
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--detect-drivers |
boolean | true |
現在のシステム上で利用可能なドライバーを自動で検出してノードに追加します。 |
--driver-configuration |
string[] | display-name="Firefox Nightly" max-sessions=2 webdriver-path="/usr/local/bin/geckodriver" stereotype='{"browserName": "firefox", "browserVersion": "86", "moz:firefoxOptions": {"binary":"/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin"}}' |
ノードがサポートするドライバーの一覧。可読性向上のため TOML ファイルで設定することを推奨します。 |
--driver-factory |
string[] | org.openqa.selenium.example.LynxDriverFactory '{"browserName": "lynx"}' |
完全修飾クラス名と、そのクラスが対応するブラウザの設定とのマッピング。 |
--driver-implementation |
string[] | "firefox" |
チェックされるドライバー。指定された場合、自動設定はスキップされます。 |
--node-implementation |
string | "org.openqa.selenium.grid.node.local.LocalNodeFactory" |
デフォルトでないノード実装の完全なクラス名。これはセッションのライフサイクルを管理するために使用されます。 |
--grid-url |
string | https://grid.example.com |
Grid 全体のパブリックな URL (通常ハブかルーターのアドレスです)。 |
--heartbeat-period |
int | 60 |
ノードが生存していることを知らせるため、ノードがディストリビューターに送るハードビートを、どのくらいの頻度(秒)で送るか。 |
--max-sessions |
int | 8 |
最大同時接続セッション数。デフォルトは利用可能なプロセッサーの数です。 |
--override-max-sessions |
boolean | false |
利用可能なプロセッサーの数は、推奨される最大セッション数(プロセッサーごとに 1 つのブラウザセッション)です。このフラグを true に設定すると、推奨される最大値を上書きすることができます。セッションの安定性と信頼性が損なわれ、ホストがリソースを使い果たす可能性があります。 |
--register-cycle |
int | 10 |
ノードがディストリビューターに初回登録を試みる頻度(秒)。 |
--register-period |
int | 120 |
ノードが初めてディストリビューターに初回登録を試みるのにかかる時間(秒)。この時間が経過すると、ノードは再登録を試みない。 |
--session-timeout |
int | 300 |
X をセッションタイムアウト(秒)としたとき、 ノード は、過去 X 秒間に何の活動もなかったセッションを自動的に終了させます。 これにより他のテストが利用できるようスロットを解放します。 |
--vnc-env-var |
string | START_XVFB |
VNC ストリームが利用可能かどうかを判断するために利用する環境変数。 |
--no-vnc-port |
int | 7900 |
VNC が利用可能な場合、ローカルの noVNC ストリームを取得できるポートを設定します。 |
--drain-after-session-count |
int | 1 |
X 個のセッションが実行された後に、ノードをドレインしてシャットダウンします。 Kubernetes のような環境で有用です。 0 より大きい値を指定すると、この機能が有効になります。 |
--hub |
string | http://localhost:4444 |
ハブ・ノード構成におけるハブのアドレスを指定します。ホスト名か IP アドレスが指定できます。この場合、ハブは http://hostname:4444 とみなされ、 --grid-url は同じものになります。 --publish-events は tcp://hostname:4442 、--subscribe-events は tcp://hostname:4443 となります。 hostname にポート番号が含まれている場合は、それが --grid-url に使用されますが、イベントバスの URI は変更されません。これらのデフォルト値は、適切なフラグを設定することでオーバーライドすることができます。ホスト名にプロトコル(https のような)が含まれる場合もそれが利用されます。 |
--enable-cdp |
boolean | true |
Grid 内で CDP プロキシーを有効にします。もしネットワークが web socket を許可していない場合、Grid 管理者は CDP を無効にできます。デフォルトは true です。 |
--downloads-path |
string | /usr/downloads |
The default location wherein all browser triggered file downloads would be available to be retrieved from. This is usually the directory that you configure in your browser as the default location for storing downloaded files. |
--selenium-manager |
boolean | false |
When drivers are not available on the current system, use Selenium Manager. False by default. |
Relay
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--service-url |
string | http://localhost:4723 |
Appium サーバーやクラウドサービスなど、WebDriver コマンドをサポートするサービスに接続するための URL です。 |
--service-host |
string | localhost |
WebDriver コマンドをサポートしてるサービスが稼働しているホスト名。 |
--service-port |
int | 4723 |
WebDriver コマンドをサポートしてるサービスが稼働しているポート番号。 |
--service-status-endpoint |
string | /status |
WebDriver サービスの状態を問い合わせるエンドポイント、オプショナルです。HTTP 200 レスポンスが期待されます。 |
--service-configuration |
string[] | max-sessions=2 stereotype='{"browserName": "safari", "platformName": "iOS", "appium:platformVersion": "14.5"}}' |
呼び出しの中継先となるサービスの設定。可読性向上のため、TOML ファイルで設定することを推奨します。 |
Router
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--password |
string | myStrongPassword |
クライアントがサーバーに接続する際に使用するパスワード。このパスワードとユーザー名の両方が設定されていないと使用できません。 |
--username |
string | admin |
クライアントがサーバーに接続する際に使用するユーザー名。このユーザー名とパスワードの両方が設定されていないと使用できません。 |
Server
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--allow-cors |
boolean | true |
Selenium サーバーが任意のホストからのウェブブラウザ接続を許可するかどうか。 |
--host |
string | localhost |
サーバーの IP もしくはホスト名、通常自動的に決定されます。 |
--bind-host |
boolean | true |
サーバがホストアドレス/ホスト名にバインドするか、あるいは到達可能な URL を知らせるためだけに使用するかを指定します。複雑なネットワーク構成で、サーバが現在の IP やホスト名ではなく、 外部の IP やホスト名で自分自身を公開する場合に有用です (例: Docker コンテナ内)。 |
--https-certificate |
path | /path/to/cert.pem |
HTTPS のためのサーバー証明書。詳細は “java -jar selenium-server.jar info security” を実行してください。 |
--https-private-key |
path | /path/to/key.pkcs8 |
HTTPS のための秘密鍵。 詳細は “java -jar selenium-server.jar info security” を実行してください。 |
--max-threads |
int | 24 |
リスナースレッドの最大数。デフォルトは、有効なプロセッサーの * 3 です。 |
--port |
int | 4444 |
リッスンポート。このパラメータは異なるコンポーネントによって使用されるため、デフォルトはありません。例えば、ルータ/ハブ/スタンドアロンは 4444 を使用し、ノードは 5555 を使用します。 |
SessionQueue
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--sessionqueue |
uri | http://localhost:1237 |
新規セッションキューサーバーのアドレス。 |
-sessionqueue-host |
string | localhost |
新規セッションキューがリッスンするホスト。 |
--sessionqueue-port |
int | 1234 |
新規セッションキューがリッスンするポート |
--session-request-timeout |
int | 300 |
タイムアウト(秒)。 新規セッションリクエストはキューに追加され、設定された時間以上キューに残っているリクエストはタイムアウトします。 |
--session-retry-interval |
int | 5 |
リトライ間隔(秒)。すべてのスロットがビジーな場合、 新規セッションリクエストはこの時間の間隔をおいてからリトライされます。 |
Sessions
オプション | 型 | 値/例 | 概要 |
---|---|---|---|
--sessions |
uri | http://localhost:1234 |
セッションマップサーバーのアドレス。 |
--sessions-host |
string | localhost |
セッションマップサーバーがリッスンするホスト。 |
--sessions-port |
int | 1234 |
セッションマップサーバーがリッスンするポート。 |
設定例
上記のオプションはすべて、Grid コンポーネントを起動する際に使用することができます。 Grid の適切な設定を模索するのに利用してください。
TOML ファイル を使用して Grid を設定することをおすすめします。 設定ファイルは読みやすく、コード管理できます。
必要に応じて TOML ファイルと CLI オプションを併用することができます。
コマンドラインフラグ
コマンドラインフラグとしてオプションを渡すには、適切なコンポーネントを特定し以下のテンプレートのようにします。
java -jar selenium-server-<version>.jar <component> --<option> value
スタドアロン、最大セッションとメインポートを設定する
java -jar selenium-server-<version>.jar standalone --max-sessions 4 --port 4444
ハブ、新規セッションリクエストのタイムアウト、メインポートを設定し、トレースを無効にする
java -jar selenium-server-<version>.jar hub --session-request-timeout 500 --port 3333 --tracing false
ノード、最大 4 セッション、デバッグログ、ポート 7777, FireFox と Edge のみ
java -jar selenium-server-<version>.jar node --max-sessions 4 --log-level "fine" --port 7777 --driver-implementation "firefox" --driver-implementation "edge"
ディストリビューター、セッションマップ・新規セッションキューの URL を指定、バスを無効にする
java -jar selenium-server-<version>.jar distributor --sessions http://localhost:5556 --sessionqueue http://localhost:5559 --bind-bus false
特定ノードにカスタム capabilities を設定する
重要: カスタム capabilities は全てのノードに設定される必要があります。 また全てのセッションリクエストに含まれなければいけません。
ハブの起動
java -jar selenium-server-<version>.jar hub
customcap に true
をセットしてノード A を起動する
java -jar selenium-server-<version>.jar node --detect-drivers false --driver-configuration display-name="Chrome (custom capability true)" max-sessions=1 stereotype='{"browserName":"chrome","gsg:customcap":true}' --port 6161
customcap に false
をセットしてノード B を起動する
java -jar selenium-server-<version>.jar node --detect-drivers false --driver-configuration display-name="Chrome (custom capability true)" max-sessions=1 stereotype='{"browserName":"chrome","gsg:customcap":false}' --port 6262
ノード A とマッチ
ChromeOptions options = new ChromeOptions();
options.setCapability("gsg:customcap", true);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"), options);
driver.get("https://selenium.dev");
driver.quit();
ノード B とマッチさせるにはカスタム capability を false
に設定します。
Specifying path from where downloaded files can be retrieved
At times a test may need to access files that were downloaded by it on the Node. To retrieve such files, following can be done.
Start the Hub
java -jar selenium-server-<version>.jar hub
Start the Node with downloads path specified
java -jar selenium-server-<version>.jar node --downloads-path /usr/downloads
Important information when dowloading a file:
- The endpoint to
GET
from is/session/<sessionId>/se/file?filename=
- The session needs to be active in order for the command to work.
- The response blob contains two keys,
filename
- Same as what was specified in the request.contents
- Base64 encoded zipped contents of the file.
- The file contents are Base64 encoded and they need to be unzipped.
Sample that retrieves the downloaded file
Assuming the downloaded file is named my_file.pdf
, and using curl
, the
file could be downloaded with the following command:
curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
Below is an example in Java that shows how to download a file named my_file.pdf
.
import static org.openqa.selenium.remote.http.Contents.string;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.io.Zip;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpMethod;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
public class DownloadsSample {
public static void main(String[] args) throws InterruptedException, IOException {
// Make sure the following directory exists on your machine
File dirToCopyTo = new File("/usr/downloads/file");
// Assuming the Grid is running locally.
URL gridUrl = new URL("http://localhost:4444");
RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions());
// This public website resets the available files for dowload on a daily basis,
// check the name of the file that will be downloaded and replace it below.
driver.get("http://the-internet.herokuapp.com/download");
WebElement element = driver.findElement(By.cssSelector(".example a"));
element.click();
// The download happens in a remote Node, which makes difficult to know when the file
// has been completely downloaded. For demonstration purposes, this example uses a
// 10 second sleep which should be enough time for a file to be downloaded.
// We strongly recommend to avoid hardcoded sleeps, and ideally, to modify your
// application under test so it offers a way to know when the file has been completely
// downloaded.
TimeUnit.SECONDS.sleep(10);
HttpRequest request = new HttpRequest(HttpMethod.GET, String.format("/session/%s/se/file", driver.getSessionId()));
request.addQueryParameter("filename", "my_file.pdf");
try (HttpClient client = HttpClient.Factory.createDefault().createClient(gridUrl)) {
HttpResponse response = client.execute(request);
Map<String, Object> map = new Json().toType(string(response), Json.MAP_TYPE);
// The returned map would contain 2 keys,
// filename - This represents the name of the file (same as what was provided by the test)
// contents - Base64 encoded String which contains the zipped file.
String encodedContents = map.get("contents").toString();
//The file contents would always be a zip file and has to be unzipped.
Zip.unzip(encodedContents, dirToCopyTo);
} finally {
driver.quit();
}
}
private static FirefoxOptions firefoxOptions() {
FirefoxOptions options = new FirefoxOptions();
// Options specific for Firefox to avoid prompting a dialog for downloads. They might
// change in the future, so please refer to the Firefox documentation for up to date details.
options.addPreference("browser.download.manager.showWhenStarting", false);
options.addPreference("browser.helperApps.neverAsk.saveToDisk",
"images/jpeg, application/pdf, application/octet-stream");
options.addPreference("pdfjs.disabled", true);
return options;
}
}
3 - Toml オプション
CLI オプション に記載されている全てのオプションは TOML ファイルでも設定ができます。 このページでは異なる Grid コンポーネントの設定例を紹介します。
オプションが変更、または追加されたが文書化されていない場合、 このドキュメントは古くなる可能性があることに注意してください。 もしそのような状況を見つけたら、“構成ヘルプ”を確認し、 ドキュメントを更新するプルリクエストを気軽に送ってください。
概要
Selenium Grid はTOMLフォーマットの設定ファイルを使用します。 設定ファイルはセクションで構成され、各セクションはオプションとその値が設定されています。
詳しい使い方はTOML ドキュメントを参照してください。 パースエラーに遭遇した場合、TOML リンターを使って検証してください。
一般的な設定の構成は以下のパターンです:
[section1]
option1="value"
[section2]
option2=["value1","value2"]
option3=true
TOML ファイルで設定された Grid コンポーネントを起動するには以下のように起動できます:
java -jar selenium-server-<version>.jar <component> --config /path/to/file/<file-name>.toml
スタンドアロン
ポート 4449 で動作し、新規セッションリクエストのタイムアウトが 500 秒のスタンドアロンサーバー。
[server]
port = 4449
[sessionqueue]
session-request-timeout = 500
特定のブラウザとセッションの上限
Firefox と Chrome のみがデフォルトで有効になっているスタンドアロンサーバー、またはノード
[node]
drivers = ["chrome", "firefox"]
max-sessions = 3
ドライバーのカスタマイズと設定
Firefox Beta や Nightly のような、異なるブラウザのバージョンを持つことができるカスタマイズされた ドライバを用いた、スタンドアロン、またはノード。
[node]
detect-drivers = false
[[node.driver-configuration]]
max-sessions = 100
display-name = "Firefox Nightly"
stereotype = "{\"browserName\": \"firefox\", \"browserVersion\": \"93\", \"platformName\": \"MAC\", \"moz:firefoxOptions\": {\"binary\": \"/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin\"}}"
[[node.driver-configuration]]
display-name = "Chrome Beta"
stereotype = "{\"browserName\": \"chrome\", \"browserVersion\": \"94\", \"platformName\": \"MAC\", \"goog:chromeOptions\": {\"binary\": \"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta\"}}"
[[node.driver-configuration]]
display-name = "Chrome Dev"
stereotype = "{\"browserName\": \"chrome\", \"browserVersion\": \"95\", \"platformName\": \"MAC\", \"goog:chromeOptions\": {\"binary\": \"/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev\"}}"
webdriver-executable = '/path/to/chromedriver/95/chromedriver'
Docker を利用したスタンドアロン、またはノード
Docker コンテナでセッションを実行できるスタンドアロン、またはノードサーバー。
ドライバを検出を無効にし、最大 2 つの同時セッションを持ちます。
ステレオタイプは、Docker イメージにマッピングされる必要があり、
Docker デーモンが http/tcp で公開されている必要があります。
また、devices
プロパティを用いて、ホスト上でアクセス可能なデバイスファイルを、コンテナで利用できるようにすることも可能です。
Docker デバイスをマッピングする詳しい方法はdocker
を参照してください。
[node]
detect-drivers = false
max-sessions = 2
[docker]
configs = [
"selenium/standalone-chrome:93.0", "{\"browserName\": \"chrome\", \"browserVersion\": \"91\"}",
"selenium/standalone-firefox:92.0", "{\"browserName\": \"firefox\", \"browserVersion\": \"92\"}"
]
#Optionally define all device files that should be mapped to docker containers
#devices = [
# "/dev/kvm:/dev/kvm"
#]
url = "http://localhost:2375"
video-image = "selenium/video:latest"
WebDriver をサポートするサービスエンドポイントへのコマンド中継
WebDriver をサポートする外部サービスを Selenium Grid に接続すると便利です。 例えばクラウドプロバイダーや Appium サーバーなどです。 Grid はローカルに存在しないプラットフォームやバージョンなどを幅広くカバーできるようになります。
以下は Appium サーバーを Grid に接続する例です。
[node]
detect-drivers = false
[relay]
# Default Appium/Cloud server endpoint
url = "http://localhost:4723/wd/hub"
status-endpoint = "/status"
# Stereotypes supported by the service. The initial number is "max-sessions", and will allocate
# that many test slots to that particular configuration
configs = [
"5", "{\"browserName\": \"chrome\", \"platformName\": \"android\", \"appium:platformVersion\": \"11\"}"
]
Basic 認証の有効化
ルーター、ハブ、スタンドアロンにユーザー名とパスワードを設定することで、 Basic 認証で Grid を保護することができます。 このユーザーとパスワードは、Grid UI を読み込む時や 新しいセッションを開始する時に必要になります。
[router]
username = "admin"
password = "myStrongPassword"
Java でユーザーとパスワードを使ってセッションを開始する方法の例です。
URL gridUrl = new URL("http://admin:myStrongPassword@localhost:4444");
RemoteWebDriver webDriver = new RemoteWebDriver(gridUrl, new ChromeOptions());
特定のノードにマッチするカスタム capabilities の設定
重要: カスタム capabilities は全てのノードで設定する必要があります。 また全てのセッションリクエストで常に含まれる必要があります。
[node]
detect-drivers = false
[[node.driver-configuration]]
display-name = "firefox"
stereotype = '{"browserName": "firefox", "platformName": "macOS", "browserVersion":"96", "networkname:applicationName":"node_1", "nodename:applicationName":"app_1" }'
max-sessions = 5
Java でノードにマッチさせる方法の例です。
FirefoxOptions options = new FirefoxOptions();
options.setCapability("networkname:applicationName", "node_1");
options.setCapability("nodename:applicationName", "app_1");
options.setBrowserVersion("96");
options.setPlatformName("macOS");
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"), options);
driver.get("https://selenium.dev");
driver.quit();
Retrieving downloaded files from Node.
To be able to retrieve the files that were downloaded by a test at the Node, its location can be specified as below:
[node]
downloads-path = "/usr/downloads"
Refer to the CLI section for a complete example.