commands.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /// <reference types="cypress" />
  2. // ***********************************************
  3. // This example commands.ts shows you how to
  4. // create various custom commands and overwrite
  5. // existing commands.
  6. //
  7. // For more comprehensive examples of custom
  8. // commands please read more here:
  9. // https://on.cypress.io/custom-commands
  10. // ***********************************************
  11. //
  12. //
  13. // -- This is a parent command --
  14. // Cypress.Commands.add('login', (email, password) => { ... })
  15. //
  16. //
  17. // -- This is a child command --
  18. // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
  19. //
  20. //
  21. // -- This is a dual command --
  22. // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
  23. //
  24. //
  25. // -- This will overwrite an existing command --
  26. // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
  27. //
  28. // declare global {
  29. // namespace Cypress {
  30. // interface Chainable {
  31. // login(email: string, password: string): Chainable<void>
  32. // drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
  33. // dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
  34. // visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
  35. // }
  36. // }
  37. // }
  38. Cypress.Commands.add("networkStub", () => {
  39. cy.intercept("POST", "/login", "true");
  40. cy.intercept("POST", "/mark/clear", "true");
  41. cy.intercept("POST", "/mark/updateSetting", "true");
  42. cy.intercept("GET", "/mark/subject-select", "true");
  43. cy.intercept("POST", "/mark/subject-select", "true");
  44. cy.intercept(
  45. "POST",
  46. "/mark/subject/query",
  47. `[
  48. {
  49. "id": 426,
  50. "subjectCode": "431",
  51. "subjectName": "金融学综合"
  52. }
  53. ]`
  54. );
  55. cy.intercept("POST", "/mark/getSetting", {
  56. fixture: "settings-1.json",
  57. });
  58. cy.intercept("POST", "/mark/getStatus", {
  59. fixture: "status-1.json",
  60. });
  61. cy.intercept("POST", "/mark/getGroup", {
  62. fixture: "groups-1.json",
  63. });
  64. cy.intercept("POST", "/mark/getTask", {
  65. fixture: "task-1.json",
  66. });
  67. cy.intercept("GET", "/slice/**", (req) => {
  68. function getFixtureFilenameForUrl(url: string) {
  69. return "assets/" + url.split("/").pop() + ",null";
  70. }
  71. const fixtureFilename = getFixtureFilenameForUrl(req.url);
  72. req.reply({ fixture: fixtureFilename });
  73. });
  74. });