Is it possible to add a date, for example, 7 days from the moment that you run the test?
Now we have it like this so that a hard date will be inserted.
WebUI.setText(findTestObject(‘Object Repository/*** - _3c37a1/input_Datum_phaseDateDay-0’),
‘01’)
WebUI.setText(findTestObject(‘Object Repository/*** - _3c37a1/input_Dag_phaseDateMonth-0’),
‘09’)
WebUI.setText(findTestObject(‘Object Repository/*** - _3c37a1/input_Maand_phaseDateYear-0’),
‘2022’)
Sample Test Case:
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
LocalDateTime now = LocalDateTime.now();
println "today is " + DateTimeFormatter.ofPattern("yyyy-MM-dd").format(now);
LocalDateTime day1weekAfterToday = now.plusDays(7)
println day1weekAfterToday.getDayOfMonth()
println day1weekAfterToday.getMonthValue()
println day1weekAfterToday.getYear()
When I ran this, I got
2021-10-15 19:51:57.066 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2021-10-15 19:51:57.071 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/date1weekAfterToday
2021-10-15 19:51:57.699 DEBUG testcase.date1weekAfterToday - 1: now = LocalDateTime.now()
2021-10-15 19:51:57.735 DEBUG testcase.date1weekAfterToday - 2: println("today is " + ofPattern("yyyy-MM-dd").format(now))
today is 2021-10-15
2021-10-15 19:51:57.803 DEBUG testcase.date1weekAfterToday - 3: day1weekAfterToday = now.plusDays(7)
2021-10-15 19:51:57.806 DEBUG testcase.date1weekAfterToday - 4: println(day1weekAfterToday.getDayOfMonth())
22
2021-10-15 19:51:57.811 DEBUG testcase.date1weekAfterToday - 5: println(day1weekAfterToday.getMonthValue())
10
2021-10-15 19:51:57.822 DEBUG testcase.date1weekAfterToday - 6: println(day1weekAfterToday.getYear())
2021
2021-10-15 19:51:57.844 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/date1weekAfterToday
A tutorial for Java Date/Time API:
Thank you very much. We will take a look beginning of next week.
Sorry, but the way you explain it, you are trying to have a folder with a variable name. That doesn’t sound right–just adding huge complications if it is possible. Just name the folder, “NextWeekItems” or “NextWeekItems_3c37a1”. That’s super simple–no complications at all.
What you probably want is the contents of your elements, such as input_Datum_phaseDateDay-0, input_Dag_phaseDateMonth-0 and input_Maand_phaseDateYear-0 to have a value of next week. That is doable, such as the below link, and with what @kazurayam has given you, you should be good to go.
1 Like
I don’t think @suzanne.vandeneinden wants it.
I suppose that @suzanne.vandeneinden has already created 3 Test Objects in the Object Repository
folder, possibly using the Recorder tool. The folder name contained something that needs to be kept secret, for example:
Object Repository/HeWhoMustNotBeNamed - _3c37a1/input_Dataum_phraseDateDay-0
So that she intentionally replaced it with a harmless string ***
only on the post text above.
1 Like
Yes that is true. Our customer did use the Recorder tool. And I did use the *** because of sensitive data.
What is the best solution to solve this?
I posted a solution 26 days ago.
I see but it is not totally clear for us.
Can you pleas help to get it more clear? Can you give maybe an example with the code that I gave you?
Thank you very much!
If you want more about the Java Date Time API, please read this:
https://www.baeldung.com/java-8-date-time-intro
No, I can’t. Please help yourself.
Combining your code and @kazurayam’s, you may get something like:
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
LocalDateTime now = LocalDateTime.now();
println "today is " + DateTimeFormatter.ofPattern("yyyy-MM-dd").format(now);
LocalDateTime day1weekAfterToday = now.plusDays(7)
WebUI.setText(findTestObject('***_3c37a1/input_Datum_phaseDateDay-0'), day1weekAfterToday.getDayOfMonth().toString())
WebUI.setText(findTestObject('***_3c37a1/input_Dag_phaseDateMonth-0'), day1weekAfterToday.getMonthValue().toString())
WebUI.setText(findTestObject('***_3c37a1/input_Maand_phaseDateYear-0'), day1weekAfterToday.getYear().toString())
1 Like
Thank you. This did help!