Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating message with FAIL level fails if test itself passes #4

Open
joaonc opened this issue Nov 27, 2018 · 8 comments
Open

Validating message with FAIL level fails if test itself passes #4

joaonc opened this issue Nov 27, 2018 · 8 comments
Milestone

Comments

@joaonc
Copy link

joaonc commented Nov 27, 2018

I'm trying to update the test case Page Should Contain with

Page Should Contain
    [Documentation]    Default log level does not have html output.
    ...    LOG 2:7 Current page contains text 'needle'.
    ...    LOG 4.1:14 FAIL REGEXP: .*
    Page Should Contain    needle
    Page Should Contain    This is the haystack
    Run Keyword And Expect Error
    ...    Page should have contained text 'non existing text' but did not.
    ...    Page Should Contain    non existing text

Basically, my code is to make it so that keyword does not log the DOM at INFO and that test case runs at INFO level and should check that the DOM is indeed not logged.

To check that the DOM is not logged, it needs to check line 14 of step 4.1.
So I need to check that that line has status FAIL.

LOG 4.1:14 FAIL REGEXP: .* indeed checks that that line has status FAIL (LogMessageChecker._check_msg_level(...) passes), but also uses that information to check that the test case has status FAIL (TestStatusChecker._check_status(...) fails).

Looks like TestStatusChecker._check_status(...) should not use the values from LOG to check for test case status.

image

@joaonc
Copy link
Author

joaonc commented Nov 27, 2018

Note: Another way to check that the DOM is not there, would be to add
LOG 4.1:14 REGEXP: (?i)^(?!<html).*$ (this regex matches when the line doesn't start with '<html', case insensitive)

But that fails at LogMessageChecker._check_msg_level(...).

Would be good to have a NONE option to ignore log level, something like:
LOG 4.1:14 NONE REGEXP: (?i)^(?!<html).*$

@pekkaklarck
Copy link
Member

Could you try adding PASS into the beginning of the doc to explicitly specify that the test should pass? The reminder of the doc ought to then be used for validating log messages.

@joaonc
Copy link
Author

joaonc commented Nov 28, 2018

That didn't work b/c here we have

    def _get_status(self, doc):
        return 'FAIL' if 'FAIL' in doc else 'PASS'

Which returns FAIL if we have LOG 4.1:14 FAIL The failure message but the test case passes.

Created a fix for this in PR #5 but there's something I can't point my finger in the test cases that verify this functionality..

@pekkaklarck
Copy link
Member

pekkaklarck commented Nov 28, 2018

You are right, if there's FAIL anywhere the expected status is FAIL even if there would be PASS as well.

@pekkaklarck pekkaklarck added this to the v1.4 milestone Nov 28, 2018
@pekkaklarck pekkaklarck changed the title Can't check messages with FAIL level Validating message with FAIL level fails if test itself passes Nov 28, 2018
@pekkaklarck
Copy link
Member

If I've understood this issue correctly, it only manifests itself if the test itself is expected to pass but there are log messages with FAIL level. This can happen, for example, when using 'Run Keyword And Expect Errorto validate that the expected error occurs. That's definitely a bug, but in many cases it can be avoided by not usingRun Keyword And Expect Error(i.e. letting the test fail) and adding the neededFAIL Whatever the message is` into the documentation.

@joaonc
Copy link
Author

joaonc commented Nov 28, 2018

This issue manifested itself when the test case status was different than the log status.
Ex. Log status = FAIL, but test case is PASS or the other way around.

I think you got it, per your comment, but IMO, this should be fixed and supported, as opposed to work around the limitation in the tests.

The latest commits in the PR should make it work now.

@pekkaklarck
Copy link
Member

There's no log level PASS so the problem only occurs if test is expected to pass but to have FAIL messages. This obviously needs to be fixed, but because there's a workaround I don't consider the fix (and the needed release) urgent.

@joaonc
Copy link
Author

joaonc commented Nov 28, 2018

There's no log level PASS

Right, my bad on the previous comment.
These test cases were name appropriately:

  • Test case PASS log INFO
  • Test case FAIL log INFO

I'll try to get the PR in SeleniumLibrary working with the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants