Pass desired capabilities at runtime

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.

  1. Open the test case in script mode.

  2. 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)
    
  3. Continue writing the script or use Web Spy/Record Utility to complete your test case.

    DC at test script
  4. Run the test with Firefox.

    Run Firefox

    Make sure to update the browser by clicking Tools > Update WebDrivers > Choose browser.

    The test successfully opens a Firefox browser in private mode.

    Open Firefox 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:

Set DC in project settings
  1. 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 the args 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"])
    
  2. Continue writing the script or use Web Spy/Record Utility to complete your test case.

    DC at test script
  3. Run the test with Chrome.

    Set DC in project settings

    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')

References:

Feedback