question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow hiding assertion logs for `.should()` and `.and()` except on failure

See original GitHub issue

Current behavior:

There is no way to hide logs when making assertions, for example, with should.

Desired behavior:

There is a way to hide passing assertions while still reporting failing assertions. Ideally these successful assertions could also be turned back on when running under a different log level.

This came up because I wanted a “safer” version of the get command, which would by default assert that there is only 1 element found (unless an explicit length option was passed) and that the element is visible (unless an explicit noVisibleCheck option was passed), since I’ve seen tests fail or falsely succeed because of overbroad selectors or when an element was present in the DOM but not visible. Cypress tests run fast enough that doing this shouldn’t add significantly to the test run time.

However, when I do this, I end up with a ton of extra logs for each get, which clutters the test output. I’d like a way to disable these logs by default, unless the assertions fail.

Test code to reproduce

https://github.com/ncknuna/cypress-test-tiny/blob/master/cypress/support/commands.js#L45

Versions

Cypress 4.8.0 OSX 10.15.5 Chrome 83.0.4103.61

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:40
  • Comments:27 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
pcjcommented, May 27, 2021

I would like this feature as well, to only log assertions that fail.

As a workaround for assertions that are easily checked up front, you can use a somewhat redundant approach like:

            let actual = ctx.maybeGet(key);
            // if we always perform the 'expect', cypress log becomes very busy.
            // detect the failure condition and repeat with chai assertion so it 
            // surfaces in the log and fails the test
            if (!actual) {
                expect(actual, `${this.id}:unreadactBody:${key}`).to.not.be.empty;
            }
3reactions
northkevincommented, Mar 8, 2021

+1

I like to check that a cookie exists before each outgoing api request & suppressing this assertion would clean up test logs quite nicely 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

assert - How to handle AssertionError in Python and find out ...
First, if you are having trouble identifying where the exception is happening in your try..except , that's a sign your try..except block is...
Read more >
should | Cypress Documentation
Create an assertion. Assertions are automatically retried until they pass or time out. An alias of .and() Note: .should() assumes you are already....
Read more >
Logging and Logging Downsides to Defensive Programming ...
WARNING) 4 log = logging.getLogger('example') 5 try: 6 throws() 7 return 0 8 except Exception, err: 9 log.exception('Error from throws():') ...
Read more >
How to capture warnings — pytest documentation
def test_one(): > assert api_v1() == 1 test_show_warnings.py:10: _ _ _ _ _ _ ... allowing you to have finer control of which...
Read more >
Chapter 10 – Debugging - Automate the Boring Stuff with Python
First, you will look at logging and assertions, two features that can help you ... A string with a helpful error message passed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found