Screenshot after test execution

Asked by Leonardo Carvalho Sobral dos Santos

Hi,

I'd like to know, how can I do to after each test execution, sikuli take a Screenshot.
For example;

actually I'm doing like this;

testOk = 0;
testNok = 0;

try:
       .
       .
       .

    monthView()
    print("Test 11 - Passed")
    testOk = testOk +1;

except:

    print("Test 11 Failed")
    testNok = testNok +1;

    .
    .
    .

print ("Test OK",testOk)
print ("Test Not OK",testNok)

what command should I add to if test pass or fail, application take a Screenshot of page?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Leonardo Carvalho Sobral dos Santos
Solved:
Last query:
Last reply:
Revision history for this message
Leonardo Carvalho Sobral dos Santos (leonardocsobral) said :
#1

I'm using Sikuli ide

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

def takeShot(filename):
    import shutil
    shutil.move(capture(SCREEN), filename))

... and then use
takeShot("some-path/.../some-name.png")

and you will have the image on the filesystem at
some-path/.../some-name.png

Revision history for this message
Leonardo Carvalho Sobral dos Santos (leonardocsobral) said :
#3

Ok,

I'm using Sikuli ide to make scripts

This is a part of my scripts;

def monthView():

    try:

        find("1386607213938.png")
        click("1386607213938.png")
        sleep(3)

        while exists("1386591483816.png"):
                find("1386591501792.png")
                click("1386591501792.png")
                sleep(3)
        if exists("1386674062665.png"):
            find("1386674062665.png")
            click("1386674062665.png")

        else:
            print("Error to find month button")

        if exists(Pattern("1386674929878.png").similar(0.80)):
            print("Calendar opened in month view")
            dragDrop("1386676773871.png", "1386676778404.png")
            if exists("1386676800162.png"):
                print("Calendar opened in month view")
            else:
                print("error:Calendar opened in month view")
                raise exception
        else:
            print("error:Calendar opened in month view")
            raise exception

    except:
        raise exception

##########Tests Suits######################

testOk = 0;
testNok = 0;

try:
       .
       .
       .

    monthView()
    print("Test 11 - Passed")
    testOk = testOk +1;

except:

    print("Test 11 Failed")
    testNok = testNok +1;

    .
    .
    .

print ("Test OK",testOk)
print ("Test Not OK",testNok)

So the way you said , I would change to

def takeShot(filename):
try:
    import shutil
    shutil.move(capture(SCREEN), filename))
except:
     raise exception
def monthView():

    try:

        find("1386607213938.png")
        click("1386607213938.png")
        sleep(3)

        while exists("1386591483816.png"):
                find("1386591501792.png")
                click("1386591501792.png")
                sleep(3)
        if exists("1386674062665.png"):
            find("1386674062665.png")
            click("1386674062665.png")

        else:
            print("Error to find month button")

        if exists(Pattern("1386674929878.png").similar(0.80)):
            print("Calendar opened in month view")
            dragDrop("1386676773871.png", "1386676778404.png")
            if exists("1386676800162.png"):
                print("Calendar opened in month view")
            else:
                print("error:Calendar opened in month view")
                raise exception
        else:
            print("error:Calendar opened in month view")
            raise exception

    except:
        raise exception

##########Tests Suits######################

testOk = 0;
testNok = 0;

try:
       .
       .
       .

    monthView()
    print("Test 11 - Passed")
    takeShot(filename)
    testOk = testOk +1;

except:

    print("Test 11 Failed")
    takeShot(filename)
    testNok = testNok +1;

    .
    .
    .

print ("Test OK",testOk)
print ("Test Not OK",testNok)

Revision history for this message
Leonardo Carvalho Sobral dos Santos (leonardocsobral) said :
#4

i did

def printScreen(filename):
    try:
        import shutil
        shutil.move(capture(SCREEN),filename))
    except:
        raise exception

and an error is displayed

[error] script [ *Sanity_RMS ] stopped with error in line 6 at column 45
[error] SyntaxError ( "mismatched input ')' expecting NEWLINE", )

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

-- 1. sorry my fault, but ...
stopped with error in line 6 at column 45
[error] SyntaxError ( "mismatched input ')' expecting NEWLINE", )

... tells us, that there is one wrong extra closing bracket at the end ;-)

def printScreen(filename):
    try:
        import shutil
        shutil.move(capture(SCREEN),filename)
    except:
        raise exception

-- 2: no filename given

    monthView()
    print("Test 11 - Passed")
    takeShot(filename)
    testOk = testOk +1;

except:

    print("Test 11 Failed")
    takeShot(filename)
    testNok = testNok +1;

filename is a variable, that should hold a valid filename (cannot see wether and where you do that)

might be something like
filename = "Test11Passed.png"
and
filename = "Test11Failed.png"

this will save the shots to the current working directory.

Revision history for this message
Leonardo Carvalho Sobral dos Santos (leonardocsobral) said :
#6

Thank you!!!

Working well!!!