Is there a way to have the Messages window from Sikuli after a test pass has finished to be written to a file

Asked by Bob Hag

Since there is currently no reporting. Would it be possible to create a file each time a Test pass is ran and have the Messages window write to a file that can be used to see what has failed, what has passed and see all the Prints that were made during the test pass?

Thanks

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

run the script from command line with option -t and pipe output to a file.

see docs: http://sikuli.org/docx/faq/010-command-line.html

Revision history for this message
Harry Readinger (temporary22) said :
#2

You could also use python logging, although that may be a bit more involved than you need if all you want is print statements outputted to a file, however I find that it allows for better flexibility.

As an example here is output from my Error.log:

2011-10-07 17:48:27,104 ERROR FAILED TO LOAD C:\path\Grant-Revoke_Entitlements.py Because cannot import name openTicket
2011-10-07 17:48:27,105 ERROR search FAILED
 FindFailed: can not find 1316620375617.png on the screen.
  Line 16, in file C:\path\Edit_MasterAccountDetails.py

2011-10-07 17:48:27,105 ERROR openTicket FAILED
 FindFailed: can not find Dubleddmacco.png on the screen.
  Line 28, in file C:\path\Edit_MasterAccountDetails.py

2011-10-07 17:48:27,107 ERROR changeAccountDetails FAILED
 FindFailed: can not find Ticketstatus-1.png on the screen.
  Line 54, in file C:\path\Edit_MasterAccountDetails.py

2011-10-07 17:48:27,108 ERROR resolveTicket FAILED
 FindFailed: can not find DEQDetailsfo.png on the screen.
  Line 66, in file C:\path\Edit_MasterAccountDetails.py

I have the script log the sys.exec_info, along with other things. Let me know if you want more code snippets.

Revision history for this message
Bob Hag (bobhag) said :
#3

Thanks that would be great. I am open to all suggestions.

Revision history for this message
Harry Readinger (temporary22) said :
#4

My system uses the following structure (for reference, you dont have to use this structure):

Master Script:
  -Does the Actual Logging
  -Does not do the error checking itself
  -sets up the logger
  -Executes Test Scripts

Test Scripts
  -Do the action
  -Keep track of errors/return those errors to the master script via global list

here is the master script itself:
http://pastebin.com/4GNdsKLe

The error handling part of the test scripts (its the same scross all scripts):

global events
events = []

theTests = [name, of, all, functions, in, the, script]
for test in theTests:
    try:
        test()
        events.append([1, test.__name__, " OK"])
    except:
        error = str(sys.exc_info()[1])
        entry = theTests.index(test)
        events.append([2, test.__name__, "\n\t" + error])
        print events[entry][2]

Any time there is an error on a part of the script (I have my whole script broken down into functions that preform one very specific action), an exception is raised, then the function name and exception are appended to events.

If you have any further questions (or dont get something or whatever) ask away

Revision history for this message
Bob Hag (bobhag) said :
#5

What the the prereqs for getting this running?

Revision history for this message
Harry Readinger (temporary22) said :
#6

Pre-reqs should just be having python and sikuli installed, and have a Debug.log/Error.log at the paths you specify on the filehandler.

as long as the master script can find the scripts it needs to run, Then it should be OK.

NOTE: this handling framework was built for scripts that have their functionality broken down into functions

For example:

def DoSetupAction:
    stuff

def DoMainTestAction:
   stuff

def DoCleanupAction:
    stuff

theTests = [DoSetupAction, DoMainTestAction, DoCleanupAction]

ALso as a note, because i need to say it: This is not necessarily the best way to do logging if all you need is a really quick and dirty method on small individual scripts. This framework was written to automate an arbitrary number of scripts and log their results. It has worked for what I need it for. Logging is really simple to implement by itself as well, but gets cumbersome to do it for every script, assuming you are running multiple in succession.

Revision history for this message
Harry Readinger (temporary22) said :
#7

Also: I forgot. If ever you need to force a failure condition, for example, if there is a way to tell something failed without throwing a FildFailed (generally how my scripts fail), you can use the following line:

raise Exception("Exception Text")

that text will show up in the log.

Revision history for this message
Bob Hag (bobhag) said :
#8

Thank you so much

Can you help with this problem?

Provide an answer of your own, or ask Bob Hag for more information if necessary.

To post a message you must log in.