You can execute Selenium WebDriver scripts with Silk4J to use synchronization and to create a detailed TrueLog during test execution. If a browser type is specified in the capabilities on a machine on which the Open Agent is running, and you create a RemoteWebDriver and connect it to the Selenium server which is running on the Open Agent, Silk4J automatically launches the corresponding browser. If the browser type is not specified, the Open Agent tries to reuse an existing browser instance that has been launched in advance for example by executing a Silk4J base state.
To generate a visual execution TrueLog file during the execution of a Selenium script, you can use the Silk Test TrueLog API for Selenium WebDriver. This API is implemented as a REST interface, and the endpoint host and port used by this API are identical to the ones used by the Selenium server, for example http://localhost:4444/silktest/truelog.
By importing the REST API declaration file into the Swagger Editor and then using the Generate Client functionality of the editor, without making any changes to the declaration file, you can generate the client API library for a vast amount of languages like Python, Ruby, JavaScript, C#, and others. You can then download the TrueLog API in the selected programming language.
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);The following options are allowed:
Option | Type | Description |
---|---|---|
commandLineArguments | String | Passes command line arguments to the browser that is launched. |
connectionString | String | Specifies a connection string to a browser running on a remote machine. |
startUrl | String | The URL that the browser navigates to when the browser is launched. |
syncEnabled | boolean | Turns the Silk Test AJAX synchronization on or off. The default value is false. |
trueLogEnabled | boolean | You can use this option to enable or disable Truelog. The default value is true. |
trueLogId | String | The identifier of the TrueLog session that is returned when calling the StartTrueLog method of the TrueLog API. This identifier is required if you want to specify the TrueLog that should include the WebDriver actions for the Open Agent. |
trueLogPath | String | The custom Truelog file path. By default, Truelogs are written to the Silk Test log directory under %LOCALAPPDATA%\Silk\SilkTest\logs. |
trueLogScreenshotMode | String | Specifies when screenshots are added to Truelogs.
|
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");When you execute the script, all Selenium and Silk4J actions, along with any screenshots and parameters, are logged to the TrueLog.