Seeking advice on how to minimize my script regarding Dropdown values

Hi Good Day,

I’m new in automation and I don’t have much experience in scripting and I only rely with Google and Youtube.

Currently Im working on the Dropdown value and look like this:
image

Dropdown xpath:

Dropdown value xpath:

HTML :

And contains value:
image

Currently the script that I made is to verify the values on the dropdown list:

I just want to seek advice from on how can I minimize this script as soon I will be working on the Country Dropdown which list all the countries.

Example will be appreciated if have

For something like you show, I don’t think it worthwhile to “minimize” as it’s not worth the effort, however, for something like countries, it might be.

List<String> status = ["Billing Review", "Unpriceable", "Unbillable", "Priced", "Priced With Errors", "Posting", "Zero Balance", "Credit Balance"]

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

Thanks for this idea grylion54!!!

Will definitely try this one :smiley:

Hi grylion I tried and it works well!

Question, I’m using this in one object and the application that I’m working for has a lot of dropdowns

And I tried to make it as keyword but seems it is not working

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'])

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)
		}
	}
}

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

How can I parametarize the object to the keyword?

Example will be apreciated

In your xpath to your drop-down, you have a parameterized object. Should you not have the same in your statement’s ('accessionstatus') ?
Maybe like

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

Hi grylion54,

This script not working, my goal is to create a keyword as all of the dropdowns that I’m working for has the same xpath but it contains different value

Now in my keyword im not sure how to construct it
I also tried this one but not working

WebUI.verifyElementPresent(tObj, [('${accessionstatus}') : listOfOptions.get(cnt)], 5)



Is there other way?

You are passing in as a parameter the test object and the list of options. What about passing in the parameterized reference also as a third parameter?

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

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

Hi grylion my script is not working

Keyword

public class VerifyValue_Dropdown {

	@Keyword
	def verifyDropdownValue(TestObject tObj, List<String> listOfOptions, String dropdownName ) {
		for (int cnt = 0; cnt < listOfOptions.size(); cnt++) {
			WebUI.verifyElementPresent(tObj, [("${dropdownName}") : listOfOptions.get(cnt)], 5)
			//WebUI.verifyElementPresent(findTestObject(tObj, [('${accessionstatus}') : listOfOptions.get(cnt)]), 5)
			//WebUI.verifyElementPresent(findTestObject(tObj, [('accessionstatus') : listOfOptions.get(cnt)]), 5)
		}
	}
	
}

Calling keyword

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

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

Error

022-02-02 09:13:09.528 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - :x: groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.util.LinkedHashMap, java.lang.Integer) values: [TestObject - ‘Object Repository/ordersPage/ddlAccessionStatus’, …]

Possible solutions: verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)

2022-02-02 09:13:09.545 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Bryle-Debugger-TC FAILED.

Reason:

com.kms.katalon.core.exception.StepErrorException: org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.util.LinkedHashMap, java.lang.Integer) values: [TestObject - ‘Object Repository/ordersPage/ddlAccessionStatus’, …]

Possible solutions: verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)

at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.throwError(CustomKeywordDelegatingMetaClass.java:96)

at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:68)

at Bryle-Debugger-TC.run(Bryle-Debugger-TC:34)

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 TempTestCase1643764370263.run(TempTestCase1643764370263.groovy:25)

Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.util.LinkedHashMap, java.lang.Integer) values: [TestObject - ‘Object Repository/ordersPage/ddlAccessionStatus’, …]

Possible solutions: verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)

at reusableComponents.VerifyValue_Dropdown.invokeMethod(VerifyValue_Dropdown.groovy)

at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)

at Script1641536725472.run(Script1641536725472.groovy:34)

… 11 more

Caused by: groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.util.LinkedHashMap, java.lang.Integer) values: [TestObject - ‘Object Repository/ordersPage/ddlAccessionStatus’, …]

Possible solutions: verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)

at reusableComponents.VerifyValue_Dropdown.verifyDropdownValue(VerifyValue_Dropdown.groovy:28)

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:34)

… 11 more

2022-02-02 09:13:09.568 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Bryle-Debugger-TC FAILED.

Reason:

org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.util.LinkedHashMap, java.lang.Integer) values: [TestObject - ‘Object Repository/ordersPage/ddlAccessionStatus’, …]

Possible solutions: verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)

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:34)

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 TempTestCase1643764370263.run(TempTestCase1643764370263.groovy:25)

Caused by: groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.util.LinkedHashMap, java.lang.Integer) values: [TestObject - ‘Object Repository/ordersPage/ddlAccessionStatus’, …]

Possible solutions: verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)

at reusableComponents.VerifyValue_Dropdown.verifyDropdownValue(VerifyValue_Dropdown.groovy:28)

… 14 more

This error is when you don’t have the number of parameters correct, or if you don’t have the data type of the parameters correct. In this case, you don’t have the data type of the parameters correct for the statement, verifyElementPresent()–you seem to have a LinkedHashMap instead of an int data type.

I updated my script and it is not working
def verifyDropdownValue(TestObject tObj, List listOfOptions, String dropdownName ) {

		for (int cnt = 0; cnt < listOfOptions.size(); cnt++) {

			WebUI.verifyElementPresent(findTestObject('tObj', [("${dropdownName}") : listOfOptions.get(cnt)]), 5)
		
		}
	}

Error

2022-02-02 09:43:06.574 WARN c.k.k.core.testobject.ObjectRepository - Test object with id ‘Object Repository/tObj’ does not exist
2022-02-02 09:43:06.593 WARN c.k.k.core.testobject.ObjectRepository - Test object with id ‘Object Repository/’ does not exist

But when I remove the single quote in the parameter tObj
it is not recognize
WebUI.verifyElementPresent(findTestObject(tObj, [("${dropdownName}") : listOfOptions.get(cnt)]), 5)