Passing testObject to another test case

One more. I’m sure I’m doing something goofy here but I can’t figure it out…

I am trying to pass a testObject from one script to another but something is not quite right…

Script 1 has:

TestObject btnCartAdd = (findTestObject(btnAdd, [('cartProductId') : cartProductId]))

I can interact with this testObject within that script without issue.

I am trying to pass that value into another test case like so…

WebUI.callTestCase(findTestCase('Common/Add to Cart (divSponsored, btnAdd, itemQty, qtyField, action, view)'), ['divSponsored': carouselSponsored, 'btnAdd': btnCartAdd, 'itemQty': newQty, 'qtyField': qtyField, 'action': action, 'view': view], FailureHandling.STOP_ON_FAILURE)

The receiving test case has the following (which fails)…

WebUI.click(findTestObject(btnAdd))

Failure logged when it hits that click event…

groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.testobject.ObjectRepository.findTestObject() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject) values: [TestObject - 'Object Repository/Card Template/RETAILER/btnCartAdd']
Possible solutions: findTestObject(java.lang.String), findTestObject(java.lang.String, java.util.Map)
	at Add to Cart (divSponsored, btnAdd, itemQty, qtyField, action, view).run(Add to Cart (divSponsored, btnAdd, itemQty, qtyField, action, view):31)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:336)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
	at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:66)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:81)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
	at Verify Cart Page Add to Cart Increments Campaign Spends.run(Verify Cart Page Add to Cart Increments Campaign Spends:70)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:336)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1558637445179.run(TempTestCase1558637445179.groovy:21)

Is there some trick to passing in the object defined as a TestObject from one test case to another? :thinking:

Thanks!

In your second test case, instead of:

WebUI.click(findTestObject(btnAdd))

do:

WebUI.click(btnAdd)

The findTestObject() method is for looking in your repository for an object based on some id. In your case, btnAdd has already been found, so no need to use findTestObject().

1 Like

dangit! I was hoping that wouldn’t be the answer. lol… Naturally I’m sharing that script with a number of other scripts but it probably makes more sense to not define what it is there. Thanks!