Silk4J を使用して Selenium WebDriver スクリプトを実行すると、テスト実行中に同期を使用したり、TrueLog を作成することができます。Open Agent を実行しているマシン上でブラウザーの種類をケイパビリティ(Capabilities)で指定し、RemoteWebDriver を作成して Open Agent 上で実行している Selenium サーバーに接続する場合は、Silk4J は自動的に対応するブラウザーを起動します。ブラウザーの種類が指定されていない場合、Open Agent は、あらかじめ Silk4J の基本状態の実行によって起動されたブラウザーなど、既存のブラウザー インスタンスを再利用しようとします。
Selenium スクリプトの実行中に、実行をビジュアル化する TrueLog ファイルを生成するには、「Silk Test TrueLog API for Selenium WebDriver」を使用できます。この API は REST インターフェイスとして実装されており、この API によって使用されるエンドポイント ホストとポートは、Selenium サーバーによって使用されるものと同じです。たとえば、http://localhost:4444/silktest/truelog のようになります。
REST API 宣言ファイルを Swagger Editor にインポートして、エディタの Generate Client 機能を使用すると、宣言ファイルを変更をせずに、Python、Ruby、JavaScript、C# などのさまざまな言語のクライアント API ライブラリを生成できます。そして、選択したプログラム言語の TrueLog API をダウンロードできます。
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.chrome());
DesiredCapabilities safari = new DesiredCapabilities();
safari.setCapability("browserName", "SilkSafari");
Map<String, Object> options = new HashMap<>(); options.put( "syncEnabled" , true); capabilities.setCapability( "silkTestOptions" , options);以下のオプションを利用できます。
| オプション | 型 | 説明 |
|---|---|---|
| commandLineArguments | String | 起動するブラウザーに渡すコマンドライン引数を指定します。 |
| connectionString | String | リモート マシン上で実行するブラウザーの接続文字列を指定します。 |
| startUrl | String | ブラウザーの起動時に移動する URL を指定します。 |
| syncEnabled | boolean | Silk Test AJAX 同期の有効/無効を指定します。デフォルト値は、false です。 |
| trueLogEnabled | boolean | このオプションを使用して、TrueLog の有効/無効を指定します。デフォルト値は、true です。 |
| trueLogId | String | TrueLog API の StartTrueLog メソッド呼び出し時に返される TrueLog セッションの識別子です。Open Agent に対して WebDriver 操作を含める TrueLog を指定する場合に、この識別子が必要になります。 |
| trueLogPath | String | カスタム TrueLog ファイルのパスを指定します。デフォルトでは、Silk Test のログ ディレクトリである %LOCALAPPDATA%\Silk\SilkTest\logs の下に TrueLog は出力されます。 |
| trueLogScreenshotMode | String | スクリーンショットを TrueLog に追加するモードを指定します。
|
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Map<String, Object> options = new HashMap<>();
options.put("syncEnabled", true);
capabilities.setCapability("silkTestOptions", options);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
TrueLogAPI truelogAPI = new TrueLogAPI();
truelogAPI.startTrueLog("C:/temp/myTrueLogFile.tlz");
String truelogId = truelogAPI.getTrueLogId();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Map<String, Object> options = new HashMap<>();
options.put("trueLogId", trueLogId);
capabilities.setCapability("silkTestOptions", options);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
driver.get("http://demo.borland.com/InsuranceWebExtJS/");
driver.findElementById("login-form:login");スクリプトを実行すると、すべての Selenium の操作と Silk4J の操作が、スクリーンショットやパラメータと共に TrueLog に記録されます。