Can we pass a value generated in a test case to another test case as a input?

Hi All,

I have come across a situation where , in a test case , i will be creating a name which is going to be the input for the nexttest case.

In detail :

  1. Test case A : This test case is to schedule an audit... I have to schedule an audit by giving Unique " Audit name " each and every time.
Note : Audit name will be randomly generated with the help of script. ( I am not passing the" audit name" value from a data file or as a Global variable )
  1. Test Case B : In this test case... i need to map an audit to the auditor based on the "Audit name " created in the Test case A.
  2. I cannot call the "Test case A " in "Test case B " because "Close browser " is the last step in Test Case A. When the execution of A gets finished automatically the browser will close it stopping me from pass the " Audit name" from A to B.
I have so many scenarios like the above.

SO … I am in need of help from the community to resolve this.

Please help me out of this.

Let me know for further clarifications.

Guys any solutions ???

Thanks & Regards

Sridhar S

 

 

 

 

Hi Vinh Nguyen,

Thanks for your help.

This is how I have declared the global variable :

GlobalVariable.NameOfGlobalVariable = RandomText
— > The above variable " NameOfGlobalVariable " — in the global variable section as follows

Name : NameOfGlobalVariable

initValueType : String

initValue = " " ------- > ( Because I am passing the value " RandomText " from the script to the variable “NameOfGlobalVariable” )

are the above steps / assignments correct ??

awaiting your response. Many thanks in advance.

Thanks

Sridhar S

Hi Vinh Nguyen,

I have a doubt over here… can we declare the above " Audit Name ( Test case A returning String value ) " Variable as a global one… so that i can use it wherever i want.

Could you please assist me.

Thanks

Sridhar S

Hi Vinh Nguyen,

Thank you so much. Its worked finally :slight_smile:

Regards

Sridhar S

Hi Vinh Nguyen,

Thanks for your reply. I tried with the below but it is not working as expected. Please look into it and let me know your opinion.

**Test case A : Script : as follows **

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘https://172.18.1.2/complianceportal/login.aspx’)

WebUI.acceptAlert()

String RandomText = CustomKeywords.‘customKeywordPackage.RandomTextCreator.randomTextCreator’(‘ContentPlaceHolder1_txtAuditName’,
GlobalVariable.PrefixText) — > ( This is To generate the random text and put the value in the Text field )

:

:

:

WebUI.delay(5)

WebUI.acceptAlert()

WebUI.delay(4)

**return RandomText; ------ > Returning the text as Below ( Test case B First step ) **

WebUI.closeBrowser()

Note : Here I am storing the above return value in "Audit Name "

**Test Case B : Script as follows : **

String AuditName = WebUI.callTestCase(findTestCase(‘Audit Scheduling - 003 - Schedule new audit’), [‘AuditName’ : ‘’], FailureHandling.STOP_ON_FAILURE)

:

:

:

WebUI.openBrowser(’’)

:

:

WebUI.setText(findTestObject(‘Audit Mapping/Page_Compliance Portal (2)/textarea_ctl00ContentPlaceHold’), 'AuditName’) ------ > But there instead of the "Audit name ( stored ) text " … the text "Audit name " itself passed to the Text box :frowning:

So could you please help me.

Hey Prithiv,

I am sorry to say as unfortunately your solution did not help me to solve my problem.

Anyways thanks for your help.

Let us wait and see for other solution …Hope solutions from others would really help both of us :slight_smile:

Thanks

Sridhar S

1 Like

I maybe wrong, but i think you can save the Audit name generated in Test Case A as a Global Variable in the Script mode of the same test case. Use that Global Variable in Test Case B as an input. Do give it a try. Thanks.

Hi there,

That’s correct. Please give it a try.

Thanks

Yes you can. You don’t need to ‘return’ it, just assign it with the global variable you want.

Thanks

Hi there

The correct script should be:

WebUI.setText(findTestObject('Audit Mapping/Page_Compliance Portal (2)/textarea_ctl00ContentPlaceHold'), AuditName)

‘AuditName’ will be passed as itself because it’s a string, not the variable. You should remove ’ ’

Thanks

Hi there,

Actually you can have a ‘return’ statement in test case A and then use it in test case B:

Example:

TC_A:

String testString = 'abcdef'

return testString

TC_B:

String returnString = WebUI.callTestCase('TC_A')

println returnString

The results when executing TC_B will print ‘abcdef’ for returnString.So you can ultilize the ‘return’ statement and map it in your test case B per your scenario.

Thanks

4 Likes

Hey Prithviraj,

Firs of all thanks for your response.

Sure … let me check and come back :slight_smile:

Thanks

Can we return multiple variables from one test case

1 Like

how about trying getText and then setText to pass the extracted text from getText

Hi , can u share your solution, how u set a tc1 data as global and reused in TC2 . ?
I followed ur steps but my test pass without doing the action i want

Sandeep said:

Hi , can u share your solution, how u set a tc1 data as global and reused in TC2 . ?
I followed ur steps but my test pass without doing the action i want

When I tried to set value to a global variable in TC1 and then tried to println the value of the same variable in TC2, both part of TS1, I did not get the value in TC2, got Null value. SO it is not working for me at least, then tried passing a regular variable in a call TC2 statement, it is showing up in TC2. But still is giving error saying variable not declared in TC2.

Guys,

This is a fundamental part of Katalon’s testing API – it certainly works so there must be some issue in your code if it doesn’t work.

First of all, let’s set up a global variable called THE_ANSWER with the value “42” and, let’s do this in “TestCase 1”

GlobalVariable.THE_ANSWER = "42"

Now, in “TestCase 2”, let’s print its value using a comment:

WebUI.comment("The answer is ... " + GlobalVariable.THE_ANSWER)

Now execute a suite that runs “TestCase 1” before “TestCase 2”

If that doesn’t work, check to see if the GlobalVariable component is imported correctly – you should see this line in your import section at the top of the file:

import internal.GlobalVariable as GlobalVariable

If it STILL doesn’t work, well… something terrible is wrong with your system Reinstall?

Hope this helped.

Russ

2 Likes

Russ Thomas said:

Guys,

This is a fundamental part of Katalon’s testing API – it certainly works so there must be some issue in your code if it doesn’t work.

First of all, let’s set up a global variable called THE_ANSWER with the value “42” and, let’s do this in “TestCase 1”

GlobalVariable.THE_ANSWER = "42"

Now, in “TestCase 2”, let’s print its value using a comment:

WebUI.comment("The answer is ... " + GlobalVariable.THE_ANSWER)

Now execute a suite that runs “TestCase 1” before “TestCase 2”

If that doesn’t work, check to see if the GlobalVariable component is imported correctly – you should see this line in your import section at the top of the file:

import internal.GlobalVariable as GlobalVariable

If it STILL doesn’t work, well… something terrible is wrong with your system Reinstall?

Hope this helped.

Russ

Hi Russ, first of all thanks for your response. I have created a sample project and following is the set up, I am still getting the error as shown below.

TestCase1 :

import internal.GlobalVariable as GlobalVariable

GlobalVariable.THE_ANSWER = “42”

TestCase2:

import internal.GlobalVariable as GlobalVariable

WebUI.comment("The answer is … " + GlobalVariable.THE_ANSWER)

TestSuite - SampleTest:

1. TestCase1
2. TestCase2

Following are the Console messages I am seeing.

04-18-2018 12:26:25 PM - [START] - Start Test Suite : Test Suites/SampleTest

04-18-2018 12:26:25 PM - [RUN_DATA] - Logging run data ‘hostName’ with value ‘nabhaskar - USBLRNABHASKAR1.us.deloitte.com’

04-18-2018 12:26:25 PM - [RUN_DATA] - Logging run data ‘os’ with value ‘Windows 10 64bit’

04-18-2018 12:26:25 PM - [RUN_DATA] - Logging run data ‘hostAddress’ with value ‘10.31.112.166’

04-18-2018 12:26:25 PM - [RUN_DATA] - Logging run data ‘katalonVersion’ with value ‘5.4.0.1’

04-18-2018 12:26:26 PM - [START] - Start Test Case : Test Cases/TestCase1

04-18-2018 12:26:26 PM - [INFO] - Evaluating variables for test case

04-18-2018 12:26:26 PM - [START] - Start action : Statement - THE_ANSWER = “42”

04-18-2018 12:26:26 PM - [END] - End action : Statement - THE_ANSWER = “42”

04-18-2018 12:26:26 PM - [ERROR] - Test Cases/TestCase1 FAILED because (of) Variable ‘THE_ANSWER’ is not defined for test case.

04-18-2018 12:26:26 PM - [END] - End Test Case : Test Cases/TestCase1

04-18-2018 12:26:26 PM - [START] - Start Test Case : Test Cases/TestCase2

04-18-2018 12:26:26 PM - [INFO] - Evaluating variables for test case

04-18-2018 12:26:27 PM - [START] - Start action : comment

04-18-2018 12:26:27 PM - [END] - End action : comment

04-18-2018 12:26:27 PM - [ERROR] - Test Cases/TestCase2 FAILED because (of) Variable ‘THE_ANSWER’ is not defined for test case.

04-18-2018 12:26:27 PM - [END] - End Test Case : Test Cases/TestCase2

04-18-2018 12:26:27 PM - [END] - End Test Suite : Test Suites/SampleTest

Any help would be greatly appreciated, thanks.

Narendra Bhaskar said:

Russ Thomas said:

Guys,

This is a fundamental part of Katalon’s testing API – it certainly works so there must be some issue in your code if it doesn’t work.

First of all, let’s set up a global variable called THE_ANSWER with the value “42” and, let’s do this in “TestCase 1”

GlobalVariable.THE_ANSWER = "42"

Now, in “TestCase 2”, let’s print its value using a comment:

WebUI.comment("The answer is ... " + GlobalVariable.THE_ANSWER)

Now execute a suite that runs “TestCase 1” before “TestCase 2”

If that doesn’t work, check to see if the GlobalVariable component is imported correctly – you should see this line in your import section at the top of the file:

import internal.GlobalVariable as GlobalVariable

If it STILL doesn’t work, well… something terrible is wrong with your system Reinstall?

Hope this helped.

Russ

Hi Russ, first of all thanks for your response. I have created a sample project and following is the set up, I am still getting the error as shown below.

TestCase1 :

import internal.GlobalVariable as GlobalVariable

GlobalVariable.THE_ANSWER = “42”

TestCase2:

import internal.GlobalVariable as GlobalVariable

WebUI.comment("The answer is … " + GlobalVariable.THE_ANSWER)

TestSuite - SampleTest:

1. TestCase1
2. TestCase2

Following are the Console messages I am seeing.

04-18-2018 12:26:25 PM - [START] - Start Test Suite : Test Suites/SampleTest

04-18-2018 12:26:25 PM - [RUN_DATA] - Logging run data ‘hostName’ with value ‘nabhaskar - USBLRNABHASKAR1.us.deloitte.com’

04-18-2018 12:26:25 PM - [RUN_DATA] - Logging run data ‘os’ with value ‘Windows 10 64bit’

04-18-2018 12:26:25 PM - [RUN_DATA] - Logging run data ‘hostAddress’ with value ‘10.31.112.166’

04-18-2018 12:26:25 PM - [RUN_DATA] - Logging run data ‘katalonVersion’ with value ‘5.4.0.1’

04-18-2018 12:26:26 PM - [START] - Start Test Case : Test Cases/TestCase1

04-18-2018 12:26:26 PM - [INFO] - Evaluating variables for test case

04-18-2018 12:26:26 PM - [START] - Start action : Statement - THE_ANSWER = “42”

04-18-2018 12:26:26 PM - [END] - End action : Statement - THE_ANSWER = “42”

04-18-2018 12:26:26 PM - [ERROR] - Test Cases/TestCase1 FAILED because (of) Variable ‘THE_ANSWER’ is not defined for test case.

04-18-2018 12:26:26 PM - [END] - End Test Case : Test Cases/TestCase1

04-18-2018 12:26:26 PM - [START] - Start Test Case : Test Cases/TestCase2

04-18-2018 12:26:26 PM - [INFO] - Evaluating variables for test case

04-18-2018 12:26:27 PM - [START] - Start action : comment

04-18-2018 12:26:27 PM - [END] - End action : comment

04-18-2018 12:26:27 PM - [ERROR] - Test Cases/TestCase2 FAILED because (of) Variable ‘THE_ANSWER’ is not defined for test case.

04-18-2018 12:26:27 PM - [END] - End Test Case : Test Cases/TestCase2

04-18-2018 12:26:27 PM - [END] - End Test Suite : Test Suites/SampleTest

Any help would be greatly appreciated, thanks.

Hi, I have got this figured out, when I used default profile, global variables set in one test case was not available in another test case, but when created a new execution profile and tagged my test cases and test suite to the same profile, every thing started working fine. Thanks for your suggestion.

Bis thanks for providing the solution for this usage of variable from one test case in another test case issue. I was struggling for a long time to get this done.