How to schedule test run on a certain day of the week?

Hello everyone! :wave:
Maybe someone has faced the need of schedule test run on a certain day of the week?
I have some case that must running only on Monday, Wednesday and Friday and the other one must running only on Tuesday, Thursday and Saturday.
In the TestOps I can set intervals by days, hours, weeks and minutes - in fact weeks not suitable for this task. Continuing the thought, I can use days or hours - if I can skip Sunday, I can set interval “repeat every 2 days”: Mon(+), Tuesday(-), Wednesday(+), Thursday(-), Friday(+), Saturday(-), Sunday(skip) and vice versa. It will be cool, BUT how we can skip Sunday? :slight_smile:

Maybe other ideas? Not the one proposed above

Need any solution. I think someone had to deal with this before me :thinking:

1 Like

I made a Test Case named “check_the_day_of_the_week”:

import java.time.DayOfWeek
import java.time.LocalDate

import com.kms.katalon.core.util.KeywordUtil

List<DayOfWeek> myWorkingDays = [DayOfWeek.MONDAY, DayOfWeek.WEDNESDAY, DayOfWeek.FRIDAY]

Boolean isDayOn(LocalDate theDate, List<DayOfWeek> daysOn) {
	return (theDate.getDayOfWeek() in daysOn)
}

LocalDate today = LocalDate.now()
LocalDate yesterday = today.minusDays(1)
LocalDate tomorrow = today.plusDays(1)
LocalDate dayAfterTomorrow = today.plusDays(2)

println("yesterday was " + yesterday.getDayOfWeek() + " which was a day on: " + isDayOn(yesterday, myWorkingDays))
println("today is " + today.getDayOfWeek() + " which is a day on: " + isDayOn(today, myWorkingDays))
println("tomorrow will be " + tomorrow.getDayOfWeek() + " which is a day on: " + isDayOn(tomorrow, myWorkingDays))
println("day after tomorrow will be " + dayAfterTomorrow.getDayOfWeek() + " which is a day on: " + isDayOn(dayAfterTomorrow, myWorkingDays))

if (! isDayOn(today, myWorkingDays)) {
	KeywordUtil.markFailed("today is " + today.getDayOfWeek() + " which is not a day to work")
}

When I ran this on satuarday, it quickly stopped. I saw in the console:

yesterday was FRIDAY which was a day on: true
today is SATURDAY which is a day on: false
tomorrow will be SUNDAY which is a day on: false
day after tomorrow will be MONDAY which is a day on: true
2022-09-10 17:26:21.598 ERROR com.kms.katalon.core.util.KeywordUtil    - ❌ today is SATURDAY which is not a day to work
2022-09-10 17:26:21.625 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/check_days_of_the_week FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: today is SATURDAY which is not a day to work
	at com.kms.katalon.core.util.KeywordUtil.markFailed(KeywordUtil.java:19)
	at com.kms.katalon.core.util.KeywordUtil$markFailed.call(Unknown Source)
	at check_days_of_the_week.run(check_days_of_the_week:23)
	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:445)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1662798376875.run(TempTestCase1662798376875.groovy:25)

@n.naumchik

You can make a similar test case that checks the day. You can insert it into your Test suite at the very begining of the test cases sequence.

When ran and found it is Monday, Wednesday or Friday, the test case will success. The Test Suite will continue. If it is not the day to work, the Test Suite will finish quickly.

This achieves almost what you want to, doesn’t it?

1 Like

Why do you try to achieve it by a single schedule?
You can and 6 events, for each day of week needed, with repeat every week, and each should run the corresponding project.

Looks like solution, but I can’t understand the reason of

As I know, KeywordUtil.markFailed doesn’t stop even test case (only mark failed) and even more so test suit…

Because It’s inconvenient to make so much events for schedule one certain test suit, not to mention the number of test suits and several events are needed for each

You can choose KeywordUtil.markFailedAndStop().

The test case “check_the_day_of_the_week” will be stopped, but the test suite will continue

You can not control the flow of a Test Suite, which is mere a bunch of Test Cases.
You can replace a Test Suite with a Test Case “main” which calls constituant Test Cases with a flow controlled.

import java.time.DayOfWeek
import java.time.LocalDate

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

List<DayOfWeek> myWorkingDays = [DayOfWeek.MONDAY, DayOfWeek.WEDNESDAY, DayOfWeek.FRIDAY]

Boolean isDayOn(LocalDate theDate, List<DayOfWeek> daysOn) {
	return (theDate.getDayOfWeek() in daysOn)
}

LocalDate today = LocalDate.now()

if (! isDayOn(today, myWorkingDays)) {
	KeywordUtil.markFailedAndStop("today is " + today.getDayOfWeek() + " which is not a day to work")
}

WebUI.callTestCases("TC1", [:])
WebUI.callTestCases("TC2", [:])
WebUI.callTestCases("TC3", [:])
// and more

The following might be better:

if (! isDayOn(today, myWorkingDays)) {
	KeywordUtil.markWarn("today is " + today.getDayOfWeek() + " which is not a day to work")
} else {
    WebUI.callTestCases("TC1", [:])
    WebUI.callTestCases("TC2", [:])
    WebUI.callTestCases("TC3", [:])
}

This passes with a warning message without “FAILED” mark when today is not a working day.

2 Likes

Thank you :smiley:

1 Like