Tests fail when run with Windows Task Scheduler

When the test suite is run from within Katalon Studio, or manually triggered from the command prompt, the test cases pass. But when the test suite is run via the Windows Task Scheduler the vast majority of the tests fail. Is anyone else running into this issue? Any ideas why they would fail? It is not always the same tests that fail. Also "Run with highest privileges is enabled.

See if this topic helps: (read it all)

Hi @williamrpawul

Please provide an example console log of a failed test case, do you see any similarity between the failures ?

Hi there,

This is an old topic, but i’m actually facing the same issue.

I have a random success / failed with tests collection running by the windows taskscheduler.

This test collection run perfectly fine in KSE or KRE by direct command line but when the command line is launched by the task scheduler, some tests randomly failed. Here is one of the scenario that fails :

  • Set 4569 in a field “CAPITAL”
  • Click the neigbour field
  • Wait 2 sec
  • getText text of a div after cleaning it (deletewhitespace and replaceAll(’[^\p{ASCII}]’, ‘’) )
  • Compare if the div contains the text of “CAPITAL” with a switch case
  • Set succes if true, or failed if false

Console says “Text ‘4569’ is set on object ‘Object Repository/03-Tarificateur/input_Capital_base’”
Then the switch case failed because it retrieve a null value.
The screenshot on testops show me that the field “CAPITAL” is empty, while it says successful before.
I remove all the cleaning instruction to see if i’ve a trouble with it but not.

So i know why it fails (null value) but i definitly not understand why it only fails with the windows task scheduler running the same command line.

The task is run by the same admin account i’m using.

I’m running KSE/ KRE 8.2 with chromedriver 96.0.4664.45, with Chrome Headless or not, and also with Firefox.

I’m lost…

You should make sure if the “CAPITAL” field is loaded and is visible in the web page before accessing it to set a value 4569. Possibly you would want:

...
TestObject tObj = findTestObject("Object Repository/03-Tarificateur/input_Capital_base’")
WebUI.verifyElementPresent(tObj, 10)
WebUI.setText(tObj, "4569")
...

If you do not do appropriate "wait " before “setText”, then your test will be unstable — may pass sometimes, may fail sometimes.

A rule of thumb: In Selenium based tests, you need to explicitly wait for every elements loaded and available before your tests manipulate them. It’s cumbersome, but needed.

thanks Kazurayam.

I can confirm that the field is correctly loaded. Here is a piece of the the script :

DEVISFUN = String.valueOf(4569)

WebUI.verifyElementPresent(findTestObject('03-Tarificateur/input_Devis'), 1)

WebUI.verifyElementPresent(findTestObject('03-Tarificateur/input_Capital_base'), 1)

WebUI.verifyElementPresent(findTestObject('03-Tarificateur/input_Capital_complementaire'), 1)

WebUI.sendKeys(findTestObject(null), Keys.chord(Keys.PAGE_DOWN))

WebUI.delay(2)

'Set 4569 in CAPITAL field'
WebUI.setText(findTestObject('03-Tarificateur/input_Capital_base'), DEVISFUN)

WebUI.click(findTestObject('03-Tarificateur/input_Capital_complementaire'))

WebUI.delay(2)

'Capture text of div CAPITAL A ASSURER'
def CAPITASS = StringUtils.deleteWhitespace(WebUI.getText(findTestObject('03-Tarificateur/div_CAPITAL A ASSURER')).minus('CAPITAL A ASSURER').replaceAll('[^\\p{ASCII}]', ''))

WebUI.comment(">$CAPITASS<")

 'CHECK if CAPITASS match DEVISFUN'

boolean controlcapital = CAPITASS.contains(DEVISFUN)

switch (controlcapital) {
case true:
    KeywordUtil.markPassed('Capital Total OK')

    break
case false:
    KeywordUtil.markFailed('Capital Total KO')

    break

}

I set a new 2 sec delay as you advise me just before the settext, same issue.

There could be many factors that prevents you to set text into a HTML element.

Is the HTML element enabled?
Is it visible in the viewport?
Is it not “hidden”?

Please check the status of the HTML element using Chrome DevTools.

Which browser do you use? With-head, or headless?
Headless browser sometimes behave differently from the with-head browser, especially for user-interactions.

As i said i use Chrome, headless or not, and it works perfectlly until i use task scheduler.

I actually use a .bat file that contains the command line. When i run the command line directly in cmd or launch manually the .bat file all works like a charm.

When the .bat file is launch by the task scheduler, some of the test are failing, randomly. First i though of time lantency, so i put some WebUI.delay , but it still messing.

I have no trouble with elements, they are all found no hidden attribute and perfectly seen on the viewport (set to 1920 x 1082).

i have no more idea

i understand… it’s not easy…
i broke my head since weeks to understand why it doesn’t work correctly only in that damned taskscheduler…