commands.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright 2018-2022 Elyra Authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import '@testing-library/cypress/add-commands';
  17. import './../utils/snapshots/add-commands';
  18. Cypress.Commands.add('installRuntimeConfig', ({ type } = {}): void => {
  19. const kfpRuntimeInstallCommand =
  20. 'elyra-metadata create runtimes \
  21. --schema_name=kfp \
  22. --display_name="KFP Test Runtime" \
  23. --api_endpoint=https://kubernetes-service.ibm.com/pipeline \
  24. --cos_endpoint=http://0.0.0.0:9000 \
  25. --cos_username=minioadmin \
  26. --cos_password=minioadmin \
  27. --cos_bucket=test-bucket';
  28. const airflowRuntimeInstallCommand =
  29. 'elyra-metadata create runtimes \
  30. --schema_name=airflow \
  31. --display_name="Airflow Test Runtime" \
  32. --api_endpoint=https://kubernetes-service.ibm.com/pipeline \
  33. --github_repo=akchinstc/test-repo \
  34. --github_branch=main \
  35. --github_repo_token=xxxxxxxx \
  36. --github_api_endpoint=https://api.github.com \
  37. --cos_endpoint=http://0.0.0.0:9000 \
  38. --cos_username=minioadmin \
  39. --cos_password=minioadmin \
  40. --cos_bucket=test-bucket';
  41. cy.exec(
  42. type === 'kfp' ? kfpRuntimeInstallCommand : airflowRuntimeInstallCommand,
  43. { failOnNonZeroExit: false }
  44. );
  45. });
  46. // Only used for testing filling out form for runtime metadata editor
  47. Cypress.Commands.add('createRuntimeConfig', ({ type } = {}): void => {
  48. cy.findByRole('tab', { name: /runtimes/i }).click();
  49. cy.findByRole('button', { name: /create new runtime/i }).click();
  50. if (type === 'kfp') {
  51. cy.findByRole('menuitem', { name: /kubeflow pipelines/i }).click();
  52. } else {
  53. cy.findByRole('menuitem', { name: /apache airflow/i }).click();
  54. }
  55. cy.findByLabelText(/^name/i).type(`${type} Test Runtime`);
  56. if (type === 'kfp') {
  57. cy.findByLabelText(/kubeflow .* endpoint \*/i).type(
  58. 'https://kubernetes-service.ibm.com/pipeline'
  59. );
  60. } else {
  61. cy.findByLabelText(/airflow .* endpoint/i).type(
  62. 'https://kubernetes-service.ibm.com/pipeline'
  63. );
  64. cy.findByLabelText(/github .* repository \*/i).type('akchinstc/test-repo');
  65. cy.findByLabelText(/github .* branch/i).type('main');
  66. cy.findByLabelText(/personal access token/i).type('xxxxxxxx');
  67. // Check the default value is displayed on github api endpoint field
  68. cy.findByLabelText(/github .* endpoint/i).should(
  69. 'have.value',
  70. 'https://api.github.com'
  71. );
  72. }
  73. cy.findByLabelText(/object storage endpoint/i).type('http://0.0.0.0:9000');
  74. cy.findByLabelText(/object storage username/i).type('minioadmin');
  75. cy.findByLabelText(/object storage password/i).type('minioadmin');
  76. cy.findByLabelText(/object storage bucket/i).type('test-bucket');
  77. // save it
  78. cy.findByRole('button', { name: /save/i }).click();
  79. // reset runtimes widget
  80. cy.findByRole('tab', { name: /runtimes/i }).click();
  81. });
  82. Cypress.Commands.add('createExampleComponentCatalog', ({ type } = {}): void => {
  83. cy.on('fail', e => {
  84. console.error(
  85. `Example catalog connectors do not appear to be installed.\n${e}`
  86. );
  87. throw new Error(
  88. `Example catalog connectors do not appear to be installed.\n${e}`
  89. );
  90. });
  91. cy.findByRole('tab', { name: /component catalogs/i }).click();
  92. cy.findByRole('button', { name: /create new component catalog/i }).click();
  93. if (type === 'kfp') {
  94. cy.findByRole('menuitem', {
  95. name: /new kubeflow pipelines example components catalog/i
  96. }).click();
  97. } else {
  98. cy.findByRole('menuitem', {
  99. name: /new apache airflow example components catalog/i
  100. }).click();
  101. }
  102. cy.findByLabelText(/^name/i).type('Example Components');
  103. // save it
  104. cy.findByRole('button', { name: /save/i }).click();
  105. });
  106. Cypress.Commands.add('deleteFile', (name: string): void => {
  107. cy.exec(`find build/cypress-tests/ -name "${name}" -delete`, {
  108. failOnNonZeroExit: false
  109. });
  110. });
  111. Cypress.Commands.add('createPipeline', ({ name, type } = {}): void => {
  112. if (name === undefined) {
  113. switch (type) {
  114. case 'kfp':
  115. cy.get(
  116. '.jp-LauncherCard[data-category="Elyra"][title="Kubeflow Pipelines Pipeline Editor"]'
  117. ).click();
  118. break;
  119. case 'airflow':
  120. cy.get(
  121. '.jp-LauncherCard[data-category="Elyra"][title="Apache Airflow Pipeline Editor"]'
  122. ).click();
  123. break;
  124. default:
  125. cy.get(
  126. '.jp-LauncherCard[data-category="Elyra"][title="Generic Pipeline Editor"]'
  127. ).click();
  128. break;
  129. }
  130. } else {
  131. cy.writeFile(`build/cypress-tests/${name}`, '');
  132. cy.openFile(name);
  133. }
  134. cy.get('.common-canvas-drop-div');
  135. // wait an additional 300ms for the list of items to settle
  136. cy.wait(300);
  137. });
  138. Cypress.Commands.add('openDirectory', (name: string): void => {
  139. cy.findByRole('listitem', {
  140. name: (n, _el) => n.includes(name)
  141. }).dblclick();
  142. });
  143. Cypress.Commands.add('addFileToPipeline', (name: string): void => {
  144. cy.findByRole('listitem', {
  145. name: (n, _el) => n.includes(name)
  146. }).rightclick();
  147. cy.findByRole('menuitem', { name: /add file to pipeline/i }).click();
  148. });
  149. Cypress.Commands.add('dragAndDropFileToPipeline', (name: string): void => {
  150. const dragItem = cy.findByRole('listitem', {
  151. name: (n, _el) => n.includes(name)
  152. });
  153. dragItem.trigger('mousedown', { button: 0 });
  154. // drop item into canvas
  155. cy.get('.d3-svg-background')
  156. .trigger('mousemove')
  157. .trigger('mouseup', { button: 0, force: true })
  158. .wait(100);
  159. });
  160. Cypress.Commands.add('savePipeline', (): void => {
  161. cy.findByRole('button', { name: /save pipeline/i }).click();
  162. // can take a moment to register as saved in ci
  163. cy.wait(1000);
  164. });
  165. Cypress.Commands.add('openFile', (name: string): void => {
  166. cy.findByRole('listitem', {
  167. name: (n, _el) => n.includes(name),
  168. timeout: 50000
  169. }).dblclick();
  170. });
  171. Cypress.Commands.add('bootstrapFile', (name: string): void => {
  172. cy.readFile(`tests/assets/${name}`).then((file: any) => {
  173. cy.writeFile(`build/cypress-tests/${name}`, file);
  174. });
  175. });
  176. Cypress.Commands.add('resetJupyterLab', (): void => {
  177. // open jupyterlab with a clean workspace
  178. cy.visit('?token=test&reset');
  179. cy.findByRole('tab', { name: /file browser/i, timeout: 25000 }).should(
  180. 'exist'
  181. );
  182. });
  183. Cypress.Commands.add('checkTabMenuOptions', (fileType: string): void => {
  184. cy.findByRole('tab', { name: /\.pipeline/i }).rightclick();
  185. cy.findAllByRole('menuitem', { name: new RegExp(fileType, 'i') }).should(
  186. 'exist'
  187. );
  188. //dismiss menu
  189. cy.get('[aria-label="Canvas"]').click({ force: true });
  190. });
  191. Cypress.Commands.add('closeTab', (index: number): void => {
  192. cy.get('.lm-TabBar-tabCloseIcon:visible')
  193. .eq(index)
  194. .click();
  195. });
  196. Cypress.Commands.add('createNewScriptEditor', (language: string): void => {
  197. cy.get(
  198. `.jp-LauncherCard[data-category="Elyra"][title="Create a new ${language} Editor"]:visible`
  199. ).click();
  200. });