jessezach / RobotEyes

Image comparison for Robot Framework
MIT License
73 stars 24 forks source link

Don't throw an error if RobotEyes isn't actually used in a test case, but still imported in ***Settings*** #74

Closed janringas closed 4 years ago

janringas commented 4 years ago

Is your feature request related to a problem? Please describe. I'm having an issue when I don't use RobotEyes in one of my tests. Because I globally import it in a resource file (and use it in some cases, but not in others) I can't import it only in those cases I actually need a keyword using RobotEyes. In this "problematic use case" the instance (is that the correct wording?) of the RobotEyes library has no attribute 'lib', because Open Eyes hasn't been called (and the test designer of the test cases maybe even doesn't know of that library in the resource file), causing the test to fail with the following message: [ ERROR ] Calling method '_end_test' of listener 'RobotEyes' failed: AttributeError: 'RobotEyes' object has no attribute 'lib'

A (simple example) test I'm running to reproduce the error message is (here I import the library directly instead of using a resource file):

*** Settings ***
Documentation    123
Library    RobotEyes
Library    SeleniumLibrary

*** Variables ***
${blur}    xpath=//*[@id="tsf"]/div[2]/div[1]/div[3]/center/input[1]

*** Test Cases ***
Open Browser
    Open Browser    https://www.google.com    gc
#   Open Eyes
    Capture Page Screenshot    filename=Test123.png
#   Capture Full Screen    tolerance=85  blur=${blur}  radius=5
    Close Browser
#   Compare Images

Describe the solution you'd like A solution I tested locally and which seemed to work was the following (I edited _end_test to first check if there actually is an attribute 'lib' before doing anything):

    def _end_test(self, data, test):
        if hasattr(self, 'lib'):
            if self.lib.lower() == 'none':
                if self.fail:
                    test.status = 'FAIL'
                    test.message = 'Image dissimilarity exceeds tolerance'

Describe alternatives you've considered An alternative (working in our context) was to manually set 'self.lib' to 'SeleniumLibrary' (which is the web library we are using), but this didn't seem as good to me compared to adding the check to _end_test.

Additional context As we are using Robot Framework distributed across multiple machines having the proposed (or a similar) fix/workaround in the library would help us greatly because we wouldn't need to change the file on all machines manually.

jessezach commented 4 years ago

Fix released in 1.5.2