12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- // cypress/support/commands.js
- // ***********************************************
- // This example commands.js shows you how to
- // create various custom commands and overwrite
- // existing commands.
- //
- // For more comprehensive examples of custom
- // commands please read more here:
- // https://on.cypress.io/custom-commands
- // ***********************************************
- //
- //
- // -- This is a parent command --
- // Cypress.Commands.add('login', (email, password) => { ... })
- //
- //
- // -- This is a child command --
- // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
- //
- //
- // -- This is a dual command --
- // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
- //
- //
- // -- This will overwrite an existing command --
- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
- Cypress.Commands.add('logWithDate', (message, ...args) => {
- const timestamp = new Date().toISOString();
- const formattedMessage = `[${timestamp}] ${message}`;
-
- // 输出到控制台
- console.log(formattedMessage, ...args);
-
- // 也可以输出到 Cypress 的命令日志(可选)
- cy.log(formattedMessage);
-
- return null; // Cypress 命令需要返回 null 或 Promise
- });
- // Cypress.on('window:before:load', (win) => {
- // // 每打开/刷新一页都会触发
- // cy.then(() => {
- // console.log('[全局] 内存 href:', win.location.href);
- // const [, stamp] = win.location.href.match(/[?&]stamp=([^&]*)/) || [];
- // if (stamp) console.log('[全局] 当前 stamp:', stamp);
- // });
- // });
|