Unable to get parametarize object in keyword

Good Day,

I’m new in automation and I’m working on a keyword for Dropdown, I’m not sure how can I script the parametrize object to the keyword.

Here’s my script

CustomKeywords.'reusableComponents.VerifyValue_Dropdown.verifyDropdownValue'(findTestObject('ordersPage/ddlAccessionStatus'), 
          ['Billing Review', 'Unpriceable', 'Unbillable', 'Priced', 'Priced With Errors', 'Posting', 'Zero Balance', 'Credit Balance'])

Object
//div[@role='listbox']/div/div/div[contains(text(),'${accessionstatus}')]

Keyword

public class VerifyValue_Dropdown {

	@Keyword
	def verifyDropdownValue(TestObject to, List<String> listOfOptions) {

		for (int cnt = 0; cnt < listOfOptions.size(); cnt++) {
			WebUI.verifyElementPresent(findTestObject('to', [('accessionstatus') : listOfOptions.get(cnt)]), 5)
		}
	}
}

FE Dropdown
image

HTML

Example will be appreciated!

Have you tried to run your code? Any error?

wrong:

WebUI.verifyElementPresent(findTestObject('to', [

right:

WebUI.verifyElementPresent(findTestObject(to, [

Hi Kazurayam,

yes I tried to run the script but im getting error *See detail below

And I also tried your script but seems im getting a warning

Error

2022-02-01 18:38:43.014 WARN c.k.k.core.testobject.ObjectRepository - Test object with id ‘Object Repository/to’ does not exist
2022-02-01 18:38:43.048 WARN c.k.k.core.testobject.ObjectRepository - Test object with id ‘Object Repository/’ does not exist
2022-02-01 18:38:43.453 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to verify object is present (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to verify object is present
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.verifyElementPresent(VerifyElementPresentKeyword.groovy:92)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.execute(VerifyElementPresentKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent(WebUiBuiltInKeywords.groovy:1464)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementPresent$7.call(Unknown Source)
at reusableComponents.VerifyValue_Dropdown.verifyDropdownValue(VerifyValue_Dropdown.groovy:29)
at reusableComponents.VerifyValue_Dropdown.invokeMethod(VerifyValue_Dropdown.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
at Bryle-Debugger-TC.run(Bryle-Debugger-TC:32)
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:442)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:433)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:412)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:404)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:281)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1643711892967.run(TempTestCase1643711892967.groovy:25)
Caused by: java.lang.IllegalArgumentException: Object is null
at com.kms.katalon.core.helper.KeywordHelper.checkTestObjectParameter(KeywordHelper.java:33)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.doCall(VerifyElementPresentKeyword.groovy:76)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.call(VerifyElementPresentKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.verifyElementPresent(VerifyElementPresentKeyword.groovy:92)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.execute(VerifyElementPresentKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent(WebUiBuiltInKeywords.groovy:1464)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementPresent$7.call(Unknown Source)
at reusableComponents.VerifyValue_Dropdown.verifyDropdownValue(VerifyValue_Dropdown.groovy:29)
at reusableComponents.VerifyValue_Dropdown.invokeMethod(VerifyValue_Dropdown.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
at Script1641536725472.run(Script1641536725472.groovy:32)
… 11 more
)
2022-02-01 18:38:43.468 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - :x: Unable to verify object is present
2022-02-01 18:38:43.470 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Bryle-Debugger-TC FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to verify object is present
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.verifyElementPresent(VerifyElementPresentKeyword.groovy:92)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.execute(VerifyElementPresentKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent(WebUiBuiltInKeywords.groovy:1464)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementPresent$7.call(Unknown Source)
at reusableComponents.VerifyValue_Dropdown.verifyDropdownValue(VerifyValue_Dropdown.groovy:29)
at reusableComponents.VerifyValue_Dropdown.invokeMethod(VerifyValue_Dropdown.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
at Bryle-Debugger-TC.run(Bryle-Debugger-TC:32)
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:442)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:433)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:412)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:404)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:281)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1643711892967.run(TempTestCase1643711892967.groovy:25)
Caused by: java.lang.IllegalArgumentException: Object is null
at com.kms.katalon.core.helper.KeywordHelper.checkTestObjectParameter(KeywordHelper.java:33)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.doCall(VerifyElementPresentKeyword.groovy:76)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.call(VerifyElementPresentKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 20 more

There must be something wrong in your code, but I do not see what from the code and message you presented.

2022-02-01 18:38:43.014 WARN c.k.k.core.testobject.ObjectRepository - Test object with id ‘Object Repository/to’ does not exist

this is your primary issue to fix.

I would suggest you to slightly modify your script.

import com.kms.katalon.core.webui.testobject.TestObject;

TestObject tObj = findTestObject('ordersPage/ddlAccessionStatus')   // [A]

CustomKeywords.'reusableComponents.VerifyValue_Dropdown.verifyDropdownValue'(
    tObj,
    ['Billing Review', 'Unpriceable', 'Unbillable', 'Priced', 'Priced With Errors', 'Posting', 'Zero Balance', 'Credit Balance']   // [B]
)

Possbily this script will fail again.

Check at which point an error occurs. At [A] ? or at [B] ?

If the error occured at the [A], then you should look at the Object Repository to ensure you created a Test Object and your script is refering to it with appropriate name.

If the error occured at the [B], then your keyword would be in doubt.

I’m not sure if it is the object, as there a dynamic contain text on it.

Object
//div[@role='listbox']/div/div/div[contains(text(),'${accessionstatus}')]

And this part I don’t know how to script in Keywords
WebUI.verifyElementPresent(findTestObject(to [('accessionstatus') : listOfOptions.get(cnt)]), 5)

Wow, how come you forget a comma , between to and [ !

WebUI.verifyElementPresent(findTestObject(to , [('accessionstatus') : listOfOptions.get(cnt)]), 5)

My bad, but it seems it is not also working

You should explain with more information.

Currently I have a working script ‘per’ object dropdown

Here's the script:

	@Keyword
	def verifyAccessionStatusContent() {
		List<String> status = [
			"Billing Review",
			"Unpriceable",
			"Unbillable",
			"Priced",
			"Priced With Errors",
			"Posting",
			"Zero Balance",
			"Credit Balance"
		]

		WebUI.click(findTestObject('ordersPage/drpAccessionStatus'))
		for (int cnt = 0; cnt < status.size(); cnt++) {
			WebUI.verifyElementPresent(findTestObject('ordersPage/ddlAccessionStatus', [('accessionstatus') : status.get(cnt)]), 5)
		}
	}

Now my goal is to create a keyword that whenever I put a dynamic dropdown it should identify the expected values (given by user) and verify the actual values in the dropdown like this:
//div[@role='listbox']/div/div/div[contains(text(),'${accessionstatus}')]

Given by user
['Billing Review', 'Unpriceable', 'Unbillable', 'Priced', 'Priced With Errors', 'Posting', 'Zero Balance', 'Credit Balance'])

In my Keyword this part [(‘accessionstatus’) , is also in the object. So I don’t know how to script it

Object
//div[@role='listbox']/div/div/div[contains(text(),'${accessionstatus}')]

And I already put the comma but the script is not recognizing as it has different color

Very difficult to follow your intention without a running codeset in hand.

Is the URL of your target web application public on Internet?

If so, you should be able to create a subset of your current project, which includes the test case, test object and keyword in question. Please create it, zip it, and share it here.

Currently I’m not able to share as Im doing it in local and private network

but this is the related topic for this that I made previous days ago,

Basically I already made a working script with the help of grylion, and this is per Object
So whenever I will test an object which is a dropdown I need to write a script like this:

And my goal now is to create a keyword that when I put any dynamic dropdown it validates the values given by the user base on the array.

I can not help you much.

And my goal now is to create a keyword that when I put any dynamic dropdown it validates the values given by the user base on the array.

Good luck.

It’s ok thanks for your help and effort!