Take Screenshot for pass case also

Asked by Lakshmi

Hi RaiMan,
I am using Sikuli r930 version on Windows 7 machine.
I am using sikuli for automation.Its helping a lot in our work.
I want to achieve:
I execute the python scripts from sikuli on a device ( windows mobile) and using HTMLTestRunner also.
HTMLTestRunner takes screenshot for failure case and redirects all print statements to HTML report.
I redirected to stdout also for my purpose.
I want to get the screenshots for each step, whether it is pass/fail/error to stdout as well as in report also.
For Example:
try:
   click("start.png")
   print "start found"
   assert True
except:
   print "Start NOT found"
   assert False
try:
   click("menu.png")
   print "menu found"
   assert True
except:
   print "menu NOT found"
   assert False
In this example , I want screenshot for each step ( pass/fail/error) in stdout and in report also,
like ,
pt1.1 : start found
           screenshot
           menu found
           screenshot, etc..
 because I want to track the device status after each step.
I am running sikuli from eclipse.So, In eclipse stdout part also I want the screenshots after each step.

I tried modifying HTMLTestRunner.py , but no success.

One doubt is that what happens exactly when execution went to 'assert False' statement?
which function will it call in HTMLTestRunner?
Once one 'assert False' statement occured means , will the script exits or will it proceed to next statemet?
How many failure images can be taken?

Please suggest how to proceed for this , its helps a lot.
Thanks in advance.

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
obiwan-92 (obiwan-92) said :
#1

Hello.

First things first : you should upgrade your Sikuli version to the 1.0.1 before the 1.1.0.

Secondly : Normally assert is just a python command who print a message to help the debug.
Some example :
try:
    print "abc"
    1/0 # Exception
    print "def"
except: assert False, "Error message" # assert condition, message print in the error
 The result :
abc
[error] script [ *Untitled ] stopped with error in line 5
[error] AssertionError ( Error message )

Hope it's help.
Regards

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

HTMLTestRunner is an "extension" of the normal Python unittest TextTestRunner.

So it only comes into existence/usage if you have organised your stuff in test suites and or test cases.
I assume, you are doing that.

The HTMLTestRunner, that saves screenshots on test fail (a test function terminates with assert false) is a modification I have done on the original HTMLTestrunner. I assume this is the one you use.

This is the modification I made to get the shot at failure: (line 629)

    def addFailure(self, test, err):
        self.failure_count += 1
        TestResult.addFailure(self, test, err)
        _, _exc_str = self.failures[-1]
        output = self.complete_output()
        self.result.append((1, test, output, _exc_str, self.generateTestScreenshot(test))) # modified by RaiMan
        if self.verbosity > 1:
            sys.stderr.write('F ')
            sys.stderr.write(str(test))
            sys.stderr.write('\n')
        else:
            sys.stderr.write('F')

there are the 2 other functions for error (some Python error not being assert false) and success (assert true):

line 616
    def addError(self, test, err):
...

line 604
    def addSuccess(self, test):

these functions need the same modification, to get a shot in any case supported by unittest.

Revision history for this message
chandan parida (chandan-parida) said :
#3

Hi RaiMan,
Hope you are doing well..

Adding to Varalakshmi query we have setup our execution env, as (Eclipse with pydev and sikuli) in Eclipse console we want to see the execution image at present we are able to see the execution log which we have given as print statement but our requirement to see the execution image in Eclipse console log.Please help us.

Thanks
Chandan

Revision history for this message
Lakshmi (varalakshmi-s) said :
#4

Hi,
I have modified HTMLTestRunner.py as you said.,

  def addSuccess(self, test):
        self.success_count += 1
        TestResult.addSuccess(self, test)
        output = self.complete_output()
        self.result.append((0, test, output, '',self.generateTestScreenshot(test)))
        #self.result.append((0, test, output, '',''))
        if self.verbosity > 1:
            sys.stderr.write('ok ')
            sys.stderr.write(str(test))
            sys.stderr.write('\n')
        else:
            sys.stderr.write('.')

    def addError(self, test, err):
        self.error_count += 1
        TestResult.addError(self, test, err)
        _, _exc_str = self.errors[-1]
        output = self.complete_output()
        #self.result.append((2, test, output, _exc_str, ''))
        self.result.append((2, test, output, _exc_str,self.generateTestScreenshot(test)))
        if self.verbosity > 1:
            sys.stderr.write('E ')
            sys.stderr.write(str(test))
            sys.stderr.write('\n')
        else:
            sys.stderr.write('E')

But still I am getting only one screenshot in the report,
I want at each step.
I am running sikuli from eclipse with pydev environment.I need screenshots in eclipse stdout.
I added assert True line , but its not taking all screenshots.
Please post the 'generateTestScreenshot(test)))' code.
Please answer the below questions, which I asked yesterday,

1. Once one 'assert False' statement occured means , will the script exits or will it proceed to next statemet?
2. How many failure images can be taken?

Thanks in advance.

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

the function addError is only fired in case you get any exception that is not an assert exception (e.g. syntax error).

you have to modify the function addSuccess as well, to get a shot for passed tests (assert true).

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

@ chandan
please make a new question - has nothing to do with this case.

Can you help with this problem?

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

To post a message you must log in.