cypress-documentation icon indicating copy to clipboard operation
cypress-documentation copied to clipboard

Missing parts of documentation for Cypress.log - end, finish, get, st, snapshot

Open shwarcu opened this issue 5 years ago • 7 comments

I'm submitting a...

[ ] Bug report
[X] Content update
[ ] Process update (build, deployment, ... )

Type of bug / changes

https://docs.cypress.io/api/cypress-api/cypress-log.html#Syntax cypressLog

There is no information what are these methods for and how to use them. In case you don't wan to update documentation, could you explain here what are these for?

shwarcu avatar Sep 09 '20 06:09 shwarcu

I completely agree with you @shwarcu.

Here is a Cypress Webinar containing some information: Webinar Patterns and Practices (slides) with this example:

Cypress.Commands.add("login", (username, password, rememberUser = false) => {
  const signinPath = "/signin";
  const log = Cypress.log({
    name: "login",
    displayName: "LOGIN",
    message: [`🔐 Authenticating | ${username}`],
    autoEnd: false,
  });

  cy.server();
  cy.route("POST", "/login").as("loginUser");
  cy.route("GET", "checkAuth").as("getUserProfile");

  cy.location("pathname", { log: false }).then((currentPath) => {
    if (currentPath !== signinPath) {
      cy.visit(signinPath);
    }
  });

  log.snapshot("before");

  cy.getBySel("signin-username").type(username);
  cy.getBySel("signin-password").type(password);

  if (rememberUser) {
    cy.getBySel("signin-remember-me").find("input").check();
  }

  cy.getBySel("signin-submit").click();
  cy.wait("@loginUser").then((loginUser: any) => {
    log.set({
      consoleProps() {
        return {
          username,
          password,
          rememberUser,
          userId: loginUser.response.body.user?.id,
        };
      },
    });

    log.snapshot("after");
    log.end();
  });
});

DamienCassou avatar Apr 02 '21 06:04 DamienCassou

I'm not sure if it is a problem of missing documentation or of lack of feature, but here is a link to an issue with the Cypress.log() command: https://github.com/cypress-io/cypress/issues/15859.

DamienCassou avatar Apr 07 '21 19:04 DamienCassou

Hi I wonder what is the definition of log.snapshot("before"); and log.snapshot("after");? Are they for visual tests, or for time traveling?

fzyzcjy avatar May 27 '21 02:05 fzyzcjy

@fzyzcjy from experiments we have made it looks like this snapshot function is responsible for taking DOM snapshots for the Cypress runner, but I don't know yet how to use it ;)

Edit: from the example above I can guess that you can take 2 snapshots "before" and "after" and they will be displayed for your custom log when you click on it, just like you would click on a cy.click() command

shwarcu avatar May 27 '21 14:05 shwarcu

The best documentation currently for Cypress.log can be found in this great blog post: https://filiphric.com/improve-your-custom-command-logs-in-cypress Everything in there is accurate.

jennifer-shehane avatar Jun 02 '21 20:06 jennifer-shehane

@fzyzcjy @shwarcu @DamienCassou When writing custom commands, you may want to change the way the command log appears for many reasons e.g easy reading and debugging. Now log.snapshot("before") takes a snapshot of how your application appears before the code that follows it(snapshot before execution of code), log.snapshot("after") takes a snapshot of how your application appears after execution of the code before it(snapshot after execution of code). These two help in reducing the "noise" in the command log.

QuantumAbraham avatar Aug 24 '22 13:08 QuantumAbraham