1

How do I select a random future date from the date picker every time in Katalon studio?

enter image description here

1
  • I know nothing about Katalon, but it should be possible to create a random integer variable and use a date add function to choose a day some number of days in the future.
    – Kate Paulk
    Nov 2, 2022 at 13:20

2 Answers 2

0

The following solution can be used to select a random future date from a date picker in Katalon Studio:

  1. Get the current date and store it in a variable.
  2. Calculate the maximum range of future dates (for example, 3 months from the current date) and store it in a variable. 3 .Generate a random number within the range of future dates.
  3. Add the random number to the current date to get the selected future date.
  4. Use the "Set Text" keyword to enter the selected future date in the date picker.

Example:

SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Calendar calendar = Calendar.getInstance();
String currentDate = dateFormat.format(calendar.getTime());

calendar.add(Calendar.MONTH, 3);
String futureDate = dateFormat.format(calendar.getTime());

long diff = dateFormat.parse(futureDate).getTime() - dateFormat.parse(currentDate).getTime();
int randomFutureDays = (int) (Math.random() * diff / (1000 * 60 * 60 * 24));

calendar.setTime(dateFormat.parse(currentDate));
calendar.add(Calendar.DATE, randomFutureDays);
String selectedFutureDate = dateFormat.format(calendar.getTime());

WebUI.setText(findTestObject('Object Repository/Page_Date Picker/input_Date Picker'), selectedFutureDate);

This solution uses the java.util.Calendar and java.text.SimpleDateFormat classes to manipulate and format dates, respectively. The Math.random() method is used to generate a random number within the range of future dates.

-1

You can have date picker use this: Date todaysDate = new Date()

def screenFormattedDate = todaysDate.format('dd/MM/yyyy')

//Used to enter today's date WebUI.setText(findTestObject('Object Repository/AAAAa/Start_date'), screenFormattedDate)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.