Sikuli logs to HTML test runner report --- not possible

Asked by Rares Pasca on 2018-11-26

----------------------- a possible solution

I actually found a solution on how to write my custom logs into html test runner report.For this you need: sikulixIDE,HTMLTestreport and unittest. So I have a file, testRunner for example form where I'm running the tests. Those are organized via unittest.TestSuite and then executed with HTMLTestRunner like this:

if __name__ == "__main__":

    suite = suite()
    unittest.TextTestRunner(verbosity = 2)
    output = open(r"your html.file report location","w+")
    runner = HTMLTestRunner.HTMLTestRunner(stream=output, title='Test Report', description='Logfiles')
    runner.run(suite)

The most important thing is the Logger file, let's say MyLogger, the code looks like this:

from sikuli import *

# Severity of logged behaviour
LEVEL_FATAL, LEVEL_WARNING, LEVEL_INFO = range(0, 3)

class Messenger:

    @staticmethod
    def Log(severity,message):
        switcher = {
            LEVEL_FATAL: 'FATAL ERROR',
            LEVEL_WARNING: 'WARNING',
            LEVEL_INFO: 'INFO',
        }
        severityMessage = switcher.get(severity, "MESSAGE")
        messageLong = severityMessage + message
        if severity == LEVEL_FATAL:
            print Exception(messageLong)
        else:
            print messageLong

Now just import MyLogger file into your tests or where you need this logger and use it like this:

import MyLogger
reload(MyLogger)

#your code

//logger call example for fatal
MyLogger.Messenger.Log(MyLogger.LEVEL_FATAL,'your message')

Now when the htmlfile is generated by HTMLTestreport, the logs should be displayed there for each test(ofc based on how you organized them in your suites in TestRunner file.

I hope this works for you as for me it's really good and helpful.

---------------------------------------------------------------------------------------------------------

Hello, I am using sikuli IDE to automate a desktop app. I'm also using html-testRunner 1.1.2 to generate reports and the sikuli logger to write to a file. Here is my code for this:

    Settings.UserLogs=True
    Settings.UserLogPrefix="LOG"
    Settings.UserLogTime=True
    Debug.setUserLogFile("path\TestRunnerLogs.txt")
    Debug.user('some text')

How can I write my logs directly to the HTML file generated by htlm test runner? And if possible can i write the logs separately for each test?

Thank you!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Rares Pasca
Solved:
2018-12-06
Last query:
2018-12-06
Last reply:
2018-11-26
RaiMan (raimund-hocke) said : #1

--- How can I write my logs directly to the HTML file generated by htlm test runner?
This is not possible, since the HTMLTestRunner does not have such a feature.

I think, it is easier, to write the log for each test into a separate file together with information about the test result (setup/teardown).

Rares Pasca (asheru93) said : #2

Thank you! I assume that this would not be possible with pytest-html either, right?

RaiMan (raimund-hocke) said : #3

had a look into the sources of python-html - but did not test it.

looks rather promising ;-) since it has many features to configure and/or script (hooks), what is going to the HTML file.

Since it does not seem to depend on any C-based stuff (native libs), there is a good chance, that it works with Jython 2.7 (= SikuliX).

IMHO, you must use pytest, to use the HTML reporter.

The challenge is, to get it accessible in the SikuliX/Jython environment, since it seems to need pip for installation.

If you step into it, feedback would be appreciated.

Rares Pasca (asheru93) said : #4

Thanks you very much! I will try this and then return here to give feeback on this.

Rares Pasca (asheru93) said : #6

I actually found a solution on how to write my custom logs into html test runner report.For this you need: sikulixIDE,HTMLTestreport and unittest. So I have a file, testRunner for example form where I'm running the tests. Those are organized via unittest.TestSuite and then executed with HTMLTestRunner like this:

if __name__ == "__main__":

    suite = suite()
    unittest.TextTestRunner(verbosity = 2)
    output = open(r"your html.file report location","w+")
    runner = HTMLTestRunner.HTMLTestRunner(stream=output, title='Test Report', description='Logfiles')
    runner.run(suite)

The most important thing is the Logger file, let's say MyLogger, the code looks like this:

from sikuli import *

# Severity of logged behaviour
LEVEL_FATAL, LEVEL_WARNING, LEVEL_INFO = range(0, 3)

class Messenger:

    @staticmethod
    def Log(severity,message):
        switcher = {
            LEVEL_FATAL: 'FATAL ERROR',
            LEVEL_WARNING: 'WARNING',
            LEVEL_INFO: 'INFO',
        }
        severityMessage = switcher.get(severity, "MESSAGE")
        messageLong = severityMessage + message
        if severity == LEVEL_FATAL:
            print Exception(messageLong)
        else:
            print messageLong

Now just import MyLogger file into your tests or where you need this logger and use it like this:

import MyLogger
reload(MyLogger)

#your code

//logger call example for fatal
MyLogger.Messenger.Log(MyLogger.LEVEL_FATAL,'your message')

Now when the htmlfile is generated by HTMLTestreport, the logs should be displayed there for each test(ofc based on how you organized them in your suites in TestRunner file.

I hope this works for you as for me it's really good and helpful.

RaiMan (raimund-hocke) said : #7

Thanks for the feedback, but your comment #5 "hides" the surely valuable information ;-)

RaiMan (raimund-hocke) said : #8

ok, thanks: you won the race, LOL ;-)

Rares Pasca (asheru93) said : #9

I accidentally posted that message , sorry:D

RaiMan (raimund-hocke) said : #10

ok, understood.

I will test and check, wether This can be an additional feature bundled with SikuliX.

thanks again.

Rares Pasca (asheru93) said : #11

no problem.

waiting for your feedback, or other users feedback

RaiMan (raimund-hocke) said : #12

made it a request bug - see related bug