What is the best way to verify values in two lists?

Hi All,

I have been trying to find different ways to verify the values, text in an application. I came up with the belong method that I use frequently to verify whatever I want. I want to know if there is a better way in verify values using two lists.

Basically I am passing two lists as arguments and verifying if the lists are same. Sometimes using contains if all the values should contain a single text

	def static verifyValuesAreMatchingWithExpected(eleText,textValues,xpath) {
		try {
			KeywordUtil.markPassed(assertEquals(eleText, textValues))
		}catch(AssertionError e) {
			try {
				for(vl in textValues) {
			}catch(AssertionError x) {
				TestObject to = new TestObject("objectName")
				to.addProperty("xpath", ConditionType.EQUALS, xpath)
				def text=WebUI.getText(to)
				try {
				catch(Exception y) {
					for(vl in textValues) {

@kazurayam @Katalon_team @Brandon_Hein @Marek_Melocik @Russ_Thomas

Please I need your help guys with suggestions to improve my code

@samuel.dasari I edited your post to display the code correctly. Edit it yourself to see what I did.

Basically, I can’t even get started to answer your question, since I wouldn’t even use that code as a starting point. You’re mixing up “testing” APIs and comparitors. Sorry. Untangling that is a long job.

Pointer: What you seem to want to do is compare two lists, which is subtly different. But that’s just a guess. Try googling and look for Groovy answers. Then use that and apply your testing code to the results.

1 Like

@Russ_Thomas I have searched in google I found so many, using those only I customized my method as above. Let me know if you can suggest an easy and more effective way of doing that.

Contains is misleading when comparing two lists.
Define your use case.
List A can have elements from list B but not all of them, and opposite.
If you need to compare if the lists are ‘identical’ … well, you may like to sort them first and make sure they have same type for elements.

As long as you don’t provide more details on your actual use cases, Google is you best friend, learn how to ask him specific questions if your time is to precious to provide such into the topics you bring to the community.