Pass desired capabilities at runtime in Katalon Studio
Desired capabilities configured in project settings are applied at the project level. You can also use desired capabilities at the test case level by passing desired capabilities to the test script.
Pass desired capabilities at runtime for WebUI Testing
To apply desired capabilities at runtime, place the following sample code before the test script. This also overrides the desired capabilities predefined in project settings.
import com.kms.katalon.core.configuration.RunConfiguration
RunConfiguration.setWebDriverPreferencesProperty(<key>, <value>)
Open Firefox browser in private mode
The following example demonstrates how to configure the desired capabilities at runtime to open a test case in private mode in Firefox.
-
Open the test case in script mode.
-
Pass the
-private
argument to the sample code as follows. Then place the code before the test script.import com.kms.katalon.core.configuration.RunConfiguration
Map firefoxOptions =[args:"-private"]
RunConfiguration.setWebDriverPreferencesProperty('moz:firefoxOptions', firefoxOptions) -
Continue writing the script or use Web Spy/Record Utility to complete your test case.
-
Run the test with Firefox.
Note:-
Make sure to update the browser by clicking Tools > Update WebDrivers > Choose browser.
The test successfully opens a Firefox browser in private mode.
-
Override desired capabilities in project settings
Suppose you want to override desired capabilities pre-configured in project settings; you can use the above sample code in the test script.
In the following example, we defined the desired capabilities for Chrome window-sized 1200x600 in project settings. We want to override this setting to run a test with a Chrome window in private mode sized 100x100. Do as follows:
-
To override the desired capabilities at runtime, open the test case in script mode. Pass the desired capabilities to the same key with the capabilities defined in project settings. Then place the code before the test script.
Here, we want to override the
--window-size=1200,600
capabilities. We pass the--window-size=100,100
and--incognito
capabilities to theargs
key in the sample code as follows. Then place the code before the test script.import com.kms.katalon.core.configuration.RunConfiguration
RunConfiguration.setWebDriverPreferencesProperty("args", ["--window-size=100,100","--incognito"]) -
Continue writing the script or use Web Spy/Record Utility to complete your test case.
-
Run the test with Chrome.
The test successfully opens a Chrome window-size 100x100 in private mode (overriding Chrome window-size 1200x600).
Pass desired capabilities at runtime for remote execution
To apply desired capabilities at runtime, place the following sample code before the test script. This also overrides the desired capabilities predefined in project settings.
import com.kms.katalon.core.configuration.RunConfiguration
RunConfiguration.setDriverPreferencesProperty('Remote', capsName , capsValue)
For example, we want to set remote execution environment as Windows 10, enter the following sample code before the test script:
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.configuration.RunConfiguration
RunConfiguration.setDriverPreferencesProperty('Remote', 'os', 'Windows')
RunConfiguration.setDriverPreferencesProperty('Remote', 'os_version', '10')
WebUI.openBrowser('google.com')