To incorporate the Failed screen shots inside robot result

Asked by subhabrata pal

Hi,

Thanks for ur time;

Can we incorporate the Failed screen shots inside robot result.

Intention is if no match is found then it will be handled as an exception i.e. 1st it will take a screen shot and will throw an error and exit - this error message should get incorporated inside robot result too.

My code is:

def sikFind(arg):
    try:
       find(Pattern("Bar Horizontal.png").similar(0.99))
   except FindFailed:
      theImage = robot.createScreenCapture(Rectangle(Toolkit.getDefaultToolkit().getScreenSize()))
      ImageIO.write(theImage, "png", File(r"D:\Selenium-screen.png"))
#########################################################
Now if I put exit(1) at the last line of my code it definetly comes out but this message is not incorporated inside robot result - infact no result file gets created.
If 'try/except' is not used - then no screen shot is taken in the result

Note: Taking screen shot has been refferd from "https://answers.launchpad.net/sikuli/+question/164161";

Regards
Subha

Question information

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

Since you are acting on the Python level, I do not understand your approach.

def sikFind(arg):
    import shutil
    if not exists(Pattern("Bar Horizontal.png").similar(0.99)):
        shutil.move(capture(SCREEN), r"D:\Selenium-screen.png"))

Revision history for this message
subhabrata pal (subhabratapal12) said :
#2

Hi,

Thank you for the answer.

May be I was not clear in explaining my question sorry for that.

I robo framework - if any step fails it takes a screen shot for the failed step; Now as per my knowledge (correct me if I am wrong) - this activity of taking screen shot happens as long as we use 'Selenium Keyword'; When we use a user defined keyword - built with command's of any other tool, for example in my case it is 'Sikuli' - then if any step fails - it exit, without taking any screen shot - but 'error message' is captured in the log and result file.

Now with ur solution/solution given buy u or others in this forum previously -it definetly takes a screen shot - but it does not exits/stops the execution there. If we put an 'exit()' command at then end i.e. after 'screen shot' command. It exits but the problem is it neither creats a log nor a result file.

So my intention is - if any step fails then:
1. It will exit
2. Take a screen shot i.e. exactly like when we use 'Selenium' Command.
3. Create a log and result file with the error message and the above screen shot

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

I still do not understand your approach.

I guess, you are setting up your Selenium stuff in Java code.

So why do you not use the Java API to integrate your Sikuli features?

Revision history for this message
subhabrata pal (subhabratapal12) said :
#4

Hi,

Thanks for ur mail.

"So why do you not use the Java API to integrate your Sikuli features?"

That can be a good approach..Thanks for that