$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - Cypress: How do I overwrite the visit command to always attempt to dismiss a popup after the page is loaded? - Stac|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Cypress: How do I overwrite the visit command to always attempt to dismiss a popup after the page is loaded? - Stac

matteradmin13PV0评论

Cypress overwrite: I would like to overwrite the existing visit mand so that it still operates as is, but will attempt to dismiss a popup after the visit has successfully executed.

The popup is something we have very little control over and it appears after you login. Seeing as we're bypassing the login screen and logging in programmatically, we'll see the popup when we navigate to any page. The insufficient code I currently have:

Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
originalFn(url, options);

cy.get("body").then($body => {
  if ($body.find("[text='Got it']").length > 0) { 
     cy.contains("Got it", { matchCase: false }).click();
  }
});
});

Thanks

Cypress overwrite: I would like to overwrite the existing visit mand so that it still operates as is, but will attempt to dismiss a popup after the visit has successfully executed.

The popup is something we have very little control over and it appears after you login. Seeing as we're bypassing the login screen and logging in programmatically, we'll see the popup when we navigate to any page. The insufficient code I currently have:

Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
originalFn(url, options);

cy.get("body").then($body => {
  if ($body.find("[text='Got it']").length > 0) { 
     cy.contains("Got it", { matchCase: false }).click();
  }
});
});

Thanks

Share Improve this question edited Jan 21, 2021 at 14:34 mckenzit asked Jan 21, 2021 at 14:29 mckenzitmckenzit 531 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You can do this by overwriting cy.visit() mand. Try this:

Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
  originalFn(url, options);
  // make sure to add a return here!
  return cy.get('body').then($body => {
    if ($body.find("[text='Got it']").length > 0) {
      cy.contains('Got it', { matchCase: false }).click();
    }
  });
});

source: https://docs.cypress.io/api/cypress-api/custom-mands#Overwrite-visit-mand

Post a comment

comment list (0)

  1. No comments so far