選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

120 行
3.1 KiB

  1. import 'cypress-file-upload';
  2. // ***********************************************
  3. // This example commands.js 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 is will overwrite an existing command --
  26. // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... });
  27. Cypress.Commands.add('login', (email, password) => {
  28. if (!email) {
  29. email = 'Administrator';
  30. }
  31. if (!password) {
  32. password = Cypress.config('adminPassword');
  33. }
  34. cy.request({
  35. url: '/api/method/login',
  36. method: 'POST',
  37. body: {
  38. usr: email,
  39. pwd: password
  40. }
  41. });
  42. });
  43. Cypress.Commands.add('call', (method, args) => {
  44. return cy.window().its('frappe.csrf_token').then(csrf_token => {
  45. return cy.request({
  46. url: `/api/method/${method}`,
  47. method: 'POST',
  48. body: args,
  49. headers: {
  50. 'Accept': 'application/json',
  51. 'Content-Type': 'application/json',
  52. 'X-Frappe-CSRF-Token': csrf_token
  53. }
  54. }).then(res => {
  55. expect(res.status).eq(200);
  56. return res.body;
  57. });
  58. });
  59. });
  60. Cypress.Commands.add('create_records', (doc) => {
  61. return cy.call('frappe.tests.ui_test_helpers.create_if_not_exists', { doc })
  62. .then(r => r.message);
  63. });
  64. Cypress.Commands.add('fill_field', (fieldname, value, fieldtype='Data') => {
  65. let selector = `.form-control[data-fieldname="${fieldname}"]`;
  66. if (fieldtype === 'Text Editor') {
  67. selector = `[data-fieldname="${fieldname}"] .ql-editor[contenteditable=true]`;
  68. }
  69. if (fieldtype === 'Code') {
  70. selector = `[data-fieldname="${fieldname}"] .ace_text-input`;
  71. }
  72. cy.get(selector).as('input');
  73. if (fieldtype === 'Select') {
  74. return cy.get('@input').select(value);
  75. } else {
  76. return cy.get('@input').type(value, {waitForAnimations: false});
  77. }
  78. });
  79. Cypress.Commands.add('awesomebar', (text) => {
  80. cy.get('#navbar-search').type(`${text}{downarrow}{enter}`, { delay: 100 });
  81. });
  82. Cypress.Commands.add('new_form', (doctype) => {
  83. cy.visit(`/desk#Form/${doctype}/New ${doctype} 1`);
  84. });
  85. Cypress.Commands.add('go_to_list', (doctype) => {
  86. cy.visit(`/desk#List/${doctype}/List`);
  87. });
  88. Cypress.Commands.add('clear_cache', () => {
  89. cy.window().its('frappe').then(frappe => {
  90. frappe.ui.toolbar.clear_cache();
  91. });
  92. });
  93. Cypress.Commands.add('dialog', (opts) => {
  94. return cy.window().then(win => {
  95. var d = new win.frappe.ui.Dialog(opts);
  96. d.show();
  97. return d;
  98. });
  99. });
  100. Cypress.Commands.add('get_open_dialog', () => {
  101. return cy.get('.modal:visible').last();
  102. });
  103. Cypress.Commands.add('hide_dialog', () => {
  104. cy.get_open_dialog().find('.btn-modal-close').click();
  105. cy.get('.modal:visible').should('not.exist');
  106. });