-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Allow hiding assertion logs for .should()
and .and()
except on failure
#7693
Comments
|
.should()
and .and()
except on failure
Got it, that makes sense! Thanks for accepting it as an valid potential enhancement :) |
Would like to +1 this, i'm asserting that 3 strings are contained in a file (represented as a string), and the entire contents of the file are printed, 3 times over. |
+1 |
+1 |
+1 I like to check that a cookie exists before each outgoing api request & suppressing this assertion would clean up test logs quite nicely 👍 |
+1. The use case this would solve for us is for example: cy.request(myUrl).then((response) => {
expect(response.headers['content-type']).to.contain('application/pdf');
expect(response.body).to.have.length.gt(500);
}); This is checking that the response is a reasonably sized pdf. This currently prints out the whole pdf in the log. :( I'm open to other ideas of how to do this if there's a better way. :) |
@ncknuna I found this issue when attempting to define the exact same thing as I found myself constantly checking I'm now using this: type VGetOptions = { length: number; visible: boolean } & Parameters<
typeof cy.get
>[1];
Cypress.Commands.add(
'vget',
(
selector: string,
{ length, visible, ...rest }: VGetOptions = { visible: true, length: 1 }
): Cypress.Chainable<JQuery<HTMLElement>> =>
cy
.get(selector, rest)
.should('have.length', length)
.and(visible ? 'be.visible' : 'not.be.visible')
);
// ...
cy.vget('.foo'); // most common scenario
cy.vget('.foos', { length: 10 });
cy.vget('.bar', { visible: false });
cy.vget('.bars', { visible: false, length: 5 }); But yes, It would be great if passing assertions could optionally be removed from the command log. |
I'm using retry-ability to wait for SSE connection to establish. In this case I have no need for
A little background for why it is done like this: for connecting to SSE we use |
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;
} |
I'll add my name to the list - this would be great |
Hard +1 on this. |
It would be very usefull |
This comment has been minimized.
This comment has been minimized.
We're checking for downloads of ZIP files, using the cypress examples as a basis, which has an assertion for the files length to be at least 300 bytes which floods the log - does not look that nice.. |
@jennifer-shehane is there any news about this enhancement? |
I'm using a function like this, that keeps running into "element is detached", so I had to add assertions, but they're a whole lot of clutter. I'd like to be able to hide the interim assertions if they pass. export function getTableVal(row: string, column: 'left' | 'center' | 'right' = 'center') {
return cy.get(`[data-row=${row}]`).should('exist').find(`[data-column=${column}]`).should('exist').find(`[data-testid=value]`)
} |
I'd love this too. |
@DanaGoyette, you can combine your selectors into a single get. return cy.get(`[data-row=${row}] [data-column=${column}] [data-testid=value]`); |
I've tried that, and the result is that I get tests failing with "component became detached from the DOM" quite often. Using the separate selectors seems to fix that. Also, the log tends to show line breaks at the dashes, which is ugly, instead of breaking at the logical place of the space between selectors. What I get:
What I'd want:
The chained .get/.find makes the logs neater, except for the assertions in between. |
+1 Would be great to check password input values! |
+1 |
+1. I have a custom command with several |
As a work around, "native" chai
If assertion fails, the error appears in the log in the normal way. Anybody see any cons for this method? |
+1 |
Aside from the issue of log clutter, when performing some large validations, I noticed that using expect() takes far longer than a plain JS conditional, which I assume is due to the logging behavior. Here's a sample I prepared to reproduce the behavior.
Using expect() took ~30 seconds, whereas the conditional took about 0.02 seconds. For the time being, is there anything lacking in simply using a plain conditional to trigger expect() when the assertion should fail? |
Hi all, I just found on web a solution to hide all the "xhr" logs. So I´ve just included the "..command-name-assert" (class for the <"Li"> selector that displays the assert logs). I know that´s not the best way to do that, but it works (sorry for the poor english rs): //Put the code below in the support/index.js file, create a hideXHR config (just in case u want to disable) and add in //style.innerHTML all the classes (LI lines) u want hide. if (Cypress.config('hideXHR')) { |
+1 |
+1. |
If you use the function signature form of
Cypress.Commands.add('waitOnLoad', () => {
cy.get(".fa-spinner", { log: false })
.should($subject => {
if (!$subject.length) throw new Error("Should exist.");
})
.then($el =>
Cypress.log({
name: "waitOnLoad",
displayName: "waitOnLoad",
message: "",
$el
})
);
cy.get(".fa-spinner", { log: false }).should($subject => {
if ($subject.length) throw new Error("Should not exist.");
});
}) |
+1 |
allowing hiding assertion logs would be a good option, just like you can hide every other log |
+1 |
+1 I'd also love this enhancement, it'd make it a lot nicer for plugin developers (like me), especially if you use any form of |
it sucks that there is still no solution to this issue after more than 3 years. In our case we want to assert on the contents of a file, which results in the whole file being printed out on the log... :-( |
+1 Would be great to have |
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 explicitlength
option was passed) and that the element is visible (unless an explicitnoVisibleCheck
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
The text was updated successfully, but these errors were encountered: