0

TC1: 01_UserManagement/Login

String u = WebUI.getAttribute(findTestObject('SignInPage/txt_username'), 'placeholder')

WebUI.setText(findTestObject('SignInPage/txt_username'), username)

String p = WebUI.getAttribute(findTestObject('SignInPage/txt_password'), 'placeholder')

CustomKeywords.'com.fcm.utilities.ClearTextField.ClearText'(findTestObject('SignInPage/txt_password'))

WebUI.setText(findTestObject('SignInPage/txt_password'), password)

WebUI.click(findTestObject('SignInPage/btn_signinButton'))

Map map = [:]
map.put('inlinetextofusername',u)
map.put('inlinetextofpassword',p)
map.each{ k, v -> println "${k}:${v}" }
return map;

TestCase2:

Map TC_1_called = WebUI.callTestCase(findTestCase('01_UserManagement/Login'), [('username') : 'Anna', ('password') : 'Analyst_2017',('inlinetextofusername'):'',('inlinetextofpassword'):''], 
    FailureHandling.STOP_ON_FAILURE)

println(TC_1_called[inlinetextofusername])

println(TC_1_called[inlinetextofpassword]

I am getting following error:-

12-11-2017 04:31:40 PM - [ERROR] - Test Cases/01_UserManagement/Logout FAILED because (of) Variable 'inlinetextofusername' is not defined for test case.

How to take the values which is stored in Map in Test case 1 and to use in Test Case 2.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
ChanGan
  • 4,254
  • 11
  • 74
  • 135

3 Answers3

1
Map TC_1_called = WebUI.callTestCase(findTestCase('01_UserManagement/Login'), [('username') : 'Anna', ('password') : 'Analyst_2017',('map'):''], 
    FailureHandling.STOP_ON_FAILURE)

This returns values..

ChanGan
  • 4,254
  • 11
  • 74
  • 135
1

If you want to pass values from one test case to another in Katalon Studio, you should pass these values from Test Case A to Test Case B

Imagine you have these test cases Log in test and Dashboard test and you need to pass username and email from Log in testto Dashboard test

Go to script mode in Log in test and at the end of script add this line of code

WebUI.callTestCase( findTestCase('Test Cases/dashboard test')  , [('username'): username, ('email'):email]  )

This will pass local variables username and email from Log in test script to dashboard test

Notice: before applying this method, you should create test case variables to the second test case dashboard test from variables tab beside script tab in the lower section of test case editor.

Hope this comes in handy

Amado Saladino
  • 2,114
  • 23
  • 25
-1

I have issue on passing variable that has a random value to another test case.

Solution: I created a Global Variable with empty string then I set that Global Variable on my testCase_1 with a random value. I can now call that Global Variable to my testCase_2 without calling testCase_1. But you must execute testCase_1 first on your test suite.

testCase_1:

GlobalVariable.randomString = yourRandomValue

testCase_2:

String variableFromTestCase_1 = GlobalVariable.randomString

Screenshot