How can I set up my test case to always input the current time, in the time-picker?

HI
I have a test case to create an event, I need the event start time to always be the current time, as in the time the test is currently being executed (by default the start time is set to an hour in the future). Within the UI the date is set to the current/today date by default so I have no need to change that, the time is separate “time picker” with 24 hour value that can manually be selected by scrolling the time picker to the value required i.e. 5.00, 18.00

I recorded what I want to achieve using the Katalon chrome extension

here is my script that I need to add the time picker to
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows

import internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys

WebUI.setText(findTestObject(‘Pre-existingObjects/input_Add Event Title_eventName’), ‘Katalon test event’)

WebUI.setText(findTestObject(‘Pre-existingObjects/input_Event Venue_address’), ‘Katalon test venue’)

WebUI.click(findTestObject(‘EventDatePicker/Page_UAT Dashboard/input_Start time_rc-time-picker-input’))

WebUI.setText(findTestObject(‘Pre-existingObjects/div_Katalon test description’), ‘Katalon test description’)

WebUI.click(findTestObject(‘Pre-existingObjects/button_Save details (1)’)) import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows

import internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys

WebUI.setText(findTestObject(‘Pre-existingObjects/input_Add Event Title_eventName’), ‘Katalon test event’)

WebUI.setText(findTestObject(‘Pre-existingObjects/input_Event Venue_address’), ‘Katalon test venue’)

WebUI.click(findTestObject(‘EventDatePicker/Page_UAT Dashboard/input_Start time_rc-time-picker-input’))

WebUI.setText(findTestObject(‘Pre-existingObjects/div_Katalon test description’), ‘Katalon test description’)

WebUI.click(findTestObject(‘Pre-existingObjects/button_Save details (1)’))

The “time-picker” GUI component is designed for human; it is impossible for a WebDriver-based test script to control. You should not waste your time trying to find out how to.

You just want to set the “current time” string into the target <INPUT> field. You should be able to set a string value as “current time” into the INPUT field. Therefore you can replace this:

to something like:

WebUI.setText(findTestObject(‘EventDatePicker/Page_UAT Dashboard/input_Start time_rc-time-picker-input'),
        '05:00')

Probably you are not happy with a constant string '05:00'; you want a varying string of “hh:mm” as current titme. Your next question will be how to get a string representation of the current time in “hh:mm” format.

Read the following article and find a solution to it:

1 Like