katalon-studiokatalon

Retrieve the count of value from the global variable and select any random from the value


I have defined a list variable in the global variable section in Katalon studio, I want to retrieve the count of the list item and select any random value from it .

enter image description here

I have around 25 values,

enter image description here.


Solution

  • Please try the below code:

    def patientName = []
    patientName = GlobalVariable.patientList
    int length = patientName.size()
        
    println "---->"+ length
        
    int min = 0;
    int max = length-1;
    int random_int = (int)Math.floor(Math.random()*(max-min+1)+min);
        
    def patientRetrieve = patientName[random_int]
    println "---->"+ patientRetrieve