Failed test cases are displayed under Error on HTML test Report

Asked by Hina on 2017-12-21

Hi, I have created a test suite which generates test execution results in HTML format.
But if some image finds failed then it will show results in Error column and not Failed.
Could you please guide what could be the issue.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-02-02
Last query:
2018-02-02
Last reply:
2018-02-01
RaiMan (raimund-hocke) said : #1

If you do not catch the FindFailed exception and turn it into assert False, then this is the defined behavior.

Hina (hina-amir) said : #2

Do we have any example for FindFailed exception?

RaiMan (raimund-hocke) said : #3

see:
http://sikulix-2014.readthedocs.io/en/latest/region.html#exception-findfailed

the rest simply is unit-testing behaviour.

you might use exists() to avoid FindFailed handling.

Hina (hina-amir) said : #4

Thanks RaiMan,
It solves bit of problem but now the assertion failed is printing traceback in the HTML report.

from sikuli import *
import IL #importing image library
import Env_Var #importing environment variable
try:
    wait("Login",15)#wait for login screen
    #enter email ID
    type(find("Email").below(25), "Test ID")
    #enter password
    type(find("Password").below(30),"TestPassword")
    click(find("//ogin")) #FindFailed exception should occur
 #catch exception and print error.
except FindFailed, err:
    print err
    assert False

************The output is *************

ft1.2: FindFailed: //ogin as text
  Line 2759, in file Region.java

Traceback (most recent call last):
  File "D:\Testing_Tools\Sikuli\Works\Login_Main.sikuli\Login_Main.py", line 10, in Login
    import Login
  File "D:\Testing_Tools\Sikuli\sikulix.jar\Lib\sikuli\SikuliImporter.py", line 45, in load_module
    return self._load_module(module_name)
  File "D:\Testing_Tools\Sikuli\sikulix.jar\Lib\sikuli\SikuliImporter.py", line 34, in _load_module
    return imp.load_module(fullname, file, pathname, desc)
  File "D:\Testing_Tools\Sikuli\Works\Login.sikuli\Login.py", line 22, in <module>
    assert False
AssertionError: !!WHILE IMPORTING!!

I want to skip Traceback and only display FindFailed: //ogin as text with line number.
How can we achieve this?

Best RaiMan (raimund-hocke) said : #5

The snippet in comment #4 is not a unittest setup.

Apparently you are using import in Login_Main.sikuli to run this snippet.

Using assert in a non-unittest setup throws AssertionError (catched by unittest in a unittest setup), so you get the traceback.

You have to decide, to either use unitttesting or your own setup without unittesting.

See the other question, where someone else brought himself on the wrong way and my suggestion how to proceed:
https://answers.launchpad.net/sikuli/+question/663899

BTW: do not use import to run other snippets, that is not according to the design of Python.

your case:

# LoginTest.sikuli
from sikuli import *
import IL #importing image library
import Env_Var #importing environment variable

def loginTest():
  try:
      wait("Login",15)#wait for login screen
      #enter email ID
      type(find("Email").below(25), "Test ID")
      #enter password
      type(find("Password").below(30),"TestPassword")
      click(find("//ogin")) #FindFailed exception should occur
      return True
  #catch exception and print error.
  except FindFailed, err:
    print err
    return False

... and then in main:
import LoginTest
assert LoginTest

But as mentioned in the other question:
Use RobotFrameWork or revise your setup, to get it designed according to the rules of unittesting.

Hina (hina-amir) said : #6

Thanks RaiMan, that solved my question.

Hina (hina-amir) said : #7

Thanks RaiMan, It's solved my problem :)