Can I take ignore the lowest value and the high value?

Hello,
I use Katalon to take some data from google page speed and I want to ignore the lowest value and highest value like the example I got these values:
64, 83, 78, 97, 85, and I want to ignore the 64 and 97.

Do you know if I can do that with Katalon?

Thank you in advance!

KS can use the Groovy/Java language, so store the values in a list (or array) and the use a sort routine to order your list (or array). Then, start your final routine from the second item (probably 1) to the last item, minus 1.

Yes but this list is generated with other values any time and I search on google for some help and I got this code and adapt for my case:

def arrayOfInts = actual_speed_mobile_1.toInteger(); actual_speed_mobile_2.toInteger(); actual_speed_mobile_3.toInteger();  actual_speed_mobile_4.toInteger(); actual_speed_mobile_5.toInteger()

arrayOfInts.remove(min);
if (min != max)
arrayOfInts.remove(max);
println(arrayOfInts)

But it generates an error I am thinking because I am not important min and max.

Error:
Reason:
groovy.lang.MissingPropertyException: No such property: min for class: Script1614030591279
at Aspire_cashout.run(Aspire_cashout:102)
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:394)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:385)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:364)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:356)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:251)
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 TempTestCase1618415032099.run(TempTestCase1618415032099.groovy:25)

But I am not sure what to imported

Okay, you are using a method called, remove, and supplying it with a variable called, min. And you’re correct, where is min defined and collected? Is it supposed to be some “automatic” reference. Same for the variable called, max.

I update the code:

def arrayOfInts = {actual_speed_mobile_1.toInteger(); actual_speed_mobile_2.toInteger(); actual_speed_mobile_3.toInteger();  actual_speed_mobile_4.toInteger(); actual_speed_mobile_5.toInteger()}

def min = Collections.min(arrayOfInts);
def max = Collections.max(arrayOfInts);
arrayOfInts.remove(min);
if (min != max)
arrayOfInts.remove(max);
println(arrayOfInts)

But I got error with:

Test Cases/Aspire_cashout FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static java.util.Collections.min() is applicable for argument types: (Script1614030591279$_run_closure1) values: [Script1614030591279$_run_closure1@265bd546]
Possible solutions: min(java.util.Collection), min(java.util.Collection, java.util.Comparator), find(), max(java.util.Collection), is(java.lang.Object), find(groovy.lang.Closure)
at Aspire_cashout.run(Aspire_cashout:102)
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:394)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:385)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:364)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:356)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:251)
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 TempTestCase1618416923176.run(TempTestCase1618416923176.groovy:25)

Try square brackets instead of curly ones:
`def arrayOfInts = [actual_speed_mobile_1.toInteger(), actual_speed_mobile_2.toInteger(), actual_speed_mobile_3.toInteger(), actual_speed_mobile_4.toInteger(), actual_speed_mobile_5.toInteger()]

I tried before curly ones and I got an error in code and then I was thinking lest try to curly one
Error:
Unexpected node type: CLOSURE_LIST found when expecting type: ELIST at line: 100 column: 20. File: script1618417706470.groovy @ line 100, column 20.

And change the semi-colons between the list of items to commas.
def arrayOfInts = [actual_speed_mobile_1.toInteger(), actual_speed_mobile_2.toInteger(), actual_speed_mobile_3.toInteger(), actual_speed_mobile_4.toInteger(), actual_speed_mobile_5.toInteger()]

Also, for safety sake, you should use curly brackets in the below code block:

if (min != max) {
   arrayOfInts.remove(max);
}

Now I got this error:
Reason:
java.lang.IndexOutOfBoundsException: Index: 58, Size: 5
at java_util_List$remove$0.call(Unknown Source)
at Aspire_cashout.run(Aspire_cashout:98)
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:394)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:385)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:364)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:356)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:251)
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 TempTestCase1618418483725.run(TempTestCase1618418483725.groovy:25)

How about instead of remove(min), we change it to removeAt(0)? See if we get it past the first hurdle. Another alternative is to use, removeElement(min)

def arrayOfInts = [actual_speed_mobile_1.toInteger(), actual_speed_mobile_2.toInteger(), actual_speed_mobile_3.toInteger(), actual_speed_mobile_4.toInteger(), actual_speed_mobile_5.toInteger()]

"this is **important** if we use removeAt"
Collections.sort(arrayOfInts)

def min = Collections.min(arrayOfInts);
WebUI.comment("our min value is " + min.toString())

def max = Collections.max(arrayOfInts);
WebUI.comment("our max value is " + max.toString())

WebUI.comment("our list of values are " + arrayOfInts.toString())

arrayOfInts.removeAt(0);
WebUI.comment("our list of values are " + arrayOfInts.toString())

if (min != max) {
    arrayOfInts.removeAt(arrayOfInts.size() - 1);
    WebUI.comment("our list of values are " + arrayOfInts.toString())
}
WebUI.comment("our values are " + arrayOfInts.toString())
Alternatively
def arrayOfInts = [actual_speed_mobile_1.toInteger(), actual_speed_mobile_2.toInteger(), actual_speed_mobile_3.toInteger(), actual_speed_mobile_4.toInteger(), actual_speed_mobile_5.toInteger()]

def min = Collections.min(arrayOfInts);
def max = Collections.max(arrayOfInts);
arrayOfInts.removeElement(min);
if (min != max) {
   arrayOfInts.removeElement(max);
}
WebUI.comment("our list of values are " + arrayOfInts.toString())
1 Like

Is working perfectly

Thank you!