Please let me know how to get the log file of the sikuli?

Asked by balakrishnan

Dear Sir,

I am started to use sikuli for my project.I felt it is very useful .However i am using it for automation purpose .For example - I may have to click the image and so on.Now after every step it has to be recorded and saved some where say notepad . Please provide me the sample code to open the notepad and write the action after every line in the same notepad.

Question information

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

different possibilities:

--- run from command line
run your script from command line and use the print statement to produce your log messages. Pipe the standard output to a text file.

--- use Python's write()
open a text file for output in your script and write your messages to that file instead of using print. This would solve your problem in the IDE too.

--- use Pythons logging feature
This is the most advanced solution.

Look for coding examples on the different possibilities in this board.

If you want to do more sophisticated things with Sikuli, you need some basic knowledge of Python language and study the docs of Sikuli (http://sikuli.org/docx/).

Revision history for this message
balakrishnan (abkblr) said :
#2

Hi Raiman ...Thanks for your reply

This is my code

pos=("1325080524703.png")
steps =1
max = 100
img = ("HarshaS.png")
if exists("HarshaS.png"):
    click ("HarshaS.png")
else:
    while max > 0:
        wheel(pos,WHEEL_DOWN,steps)
        max -= steps
        if not exists("HarshaS.png"):
            continue
        break
    click ("HarshaS.png")
# exit(1)
# break

Now please let me know where i need to open the notepad and start writing the log of every line in to notepad. Please help us.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

As mentioned above: I do not recommend to "open the notepad and start writing the log of every line in to notepad".

For this you would have a notepad window in your way, need to switch forth and back between notepad and your app and use the mouse simulation in both apps.

I have implemented an example for possibility one. The strings [my...] will allow you to filter your messages from the resulting log file.

Furthermore I have streamlined you script to avoid unnecessary find operations. The exists(img, 0) inside the loop does only one search and does not wait 3 seconds for the image (which makes no sense in this case ;-).

It is up to you to decide about the other options depending on your goals.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

sorry, the code ;-)

def log(typ, msg):
    if loglevel >= 0 and typ == 0:
        print "[myinfo]", msg
    elif loglevel >= 1 and typ == 1:
        print "[mydebug]", msg
    elif loglevel >= 2 and typ == 2:
        print "[myerror]", msg

logLevel = 2
log(0, "script started")
click("1325080524703.png")
pos = getLastMatch()
steps = 1
max = 100
img = ("HarshaS.png")
log(1, "wheeldown: max = %d, steps = %d"%(max, steps))
while max > 0:
    if not exists(img, 0):
        wheel(pos,WHEEL_DOWN,steps)
        max -= 1
        log(1, "wheeldown once")
    else:
        click (getLastMatch())
        log(0, "%s found"%(img))
        break
else:
    log(2, "%s not found"%(img))
    exit(1)

Revision history for this message
balakrishnan (abkblr) said :
#5

Thanks Raiman. It really helped me a lot.