Set default variables for test-cases

When calling a test-case I supply variables:

WebUI.callTestCase(findTestCase('TESTCASE'), [('Gebruikersnaam') : 'katalon1', ('Wachtwoord') : 'katalon1'], FailureHandling.STOP_ON_FAILURE)

However, I often use the same variables. Is there a way to set a default value inside TESTCASE that’s set in case a variable is undefined?
I had to do some complicated work-around now with try/excepts. There must be simpler way?
Just using:

if(Gebruikersnaam == undefined) {

Doesn’t work, because the script won’t run because… “Gebruikersnaam” isn’t defined :biohazard:

@safihre

In the UI of the test case, you can see the Variables tab where you can create Test Case Variables with default values. Once defined there, you can use the variables in the test case.

Oh wow, very obvious.
Thank you!

Hi Thanh, I want to set a global variable as default value of a Test case variable - any solution?

Hi,

Katalon does not directly allow this setting but you can use Grooby as the following:

def globalValue = GlobalVariable.groovyUtils.getByName('default_value')
return globalValue
1 Like

Maybe I don’t understand, but you can set a Global Variable the same as any variable within your project. If the Global Variable never changes, then just set it with the value in the Profile. If you want it to change, then do like below.

GlobalVariable.gSiteUrl = "https://www.sears.com"

WebUI.navigateToUrl(GlobalVariable.gSiteURL)
WebUI.waitForPageLoad(10)

Sorry for bothering you, I’ve found it
image
Leave screenshot here just in case somebody will need it.
Thank you for your support.

It is my pleasure to help you and glad to know you have found it.