checkbox.mjs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By, Condition } from 'selenium-webdriver'
  4. import {
  5. getRootAndWait,
  6. getActionButton,
  7. takeScreenshotOnFailure,
  8. getTerminalBuffer,
  9. } from '../../lib/elements.js'
  10. async function openCheckboxArgumentForm() {
  11. await getRootAndWait()
  12. const btn = await getActionButton(webdriver, 'Test checkbox argument')
  13. await btn.click()
  14. await webdriver.wait(
  15. new Condition('wait for argument form page', async () => {
  16. const url = await webdriver.getCurrentUrl()
  17. return url.includes('/actionBinding/') && url.includes('/argumentForm')
  18. }),
  19. 5000
  20. )
  21. }
  22. async function getCheckboxInput() {
  23. return await webdriver.findElement(By.id('confirm'))
  24. }
  25. async function submitCheckboxForm() {
  26. const submitButton = await webdriver.findElement(By.css('button[name="start"]'))
  27. await submitButton.click()
  28. }
  29. async function waitForLogsPage() {
  30. await webdriver.wait(
  31. new Condition('wait for logs page', async () => {
  32. const url = await webdriver.getCurrentUrl()
  33. return url.includes('/logs/') && !url.endsWith('/logs')
  34. }),
  35. 5000
  36. )
  37. }
  38. async function waitForExecutionComplete() {
  39. await webdriver.wait(
  40. new Condition('wait for execution status', async () => {
  41. const statusElements = await webdriver.findElements(By.id('execution-dialog-status'))
  42. return statusElements.length > 0
  43. }),
  44. 5000
  45. )
  46. await webdriver.wait(
  47. new Condition('wait for execution to finish', async () => {
  48. try {
  49. const statusElement = await webdriver.findElement(By.id('execution-dialog-status'))
  50. const statusText = await statusElement.getText()
  51. return !statusText.includes('Executing')
  52. } catch (e) {
  53. return false
  54. }
  55. }),
  56. 5000
  57. )
  58. // Small delay to allow terminal to write output
  59. await webdriver.sleep(500)
  60. }
  61. async function waitForTerminalOutput(expectedValue) {
  62. await webdriver.wait(
  63. new Condition(`wait for checkbox value ${expectedValue} in output`, async () => {
  64. try {
  65. const terminalReady = await webdriver.executeScript(`
  66. return !!(window.terminal && window.terminal.getBufferAsString);
  67. `)
  68. if (!terminalReady) {
  69. return false
  70. }
  71. const output = await getTerminalBuffer()
  72. if (!output) {
  73. return false
  74. }
  75. return output.trim().includes(`Checkbox value: ${expectedValue}`)
  76. } catch (e) {
  77. return false
  78. }
  79. }),
  80. 5000
  81. )
  82. }
  83. describe('config: checkbox', function () {
  84. before(async function () {
  85. await runner.start('checkbox')
  86. })
  87. after(async () => {
  88. await runner.stop()
  89. })
  90. afterEach(function () {
  91. takeScreenshotOnFailure(this.currentTest, webdriver)
  92. })
  93. it('Checkbox argument is rendered as a checkbox input', async function () {
  94. await openCheckboxArgumentForm()
  95. const checkboxInput = await getCheckboxInput()
  96. expect(await checkboxInput.getTagName()).to.equal('input')
  97. expect(await checkboxInput.getAttribute('type')).to.equal('checkbox')
  98. const label = await webdriver.findElement(By.css('label[for="confirm"]'))
  99. expect(await label.getText()).to.contain('Confirm option')
  100. })
  101. it('Checkbox argument submits 0 by default when unchecked', async function () {
  102. this.timeout(15000)
  103. await openCheckboxArgumentForm()
  104. const checkboxInput = await getCheckboxInput()
  105. expect(await checkboxInput.isSelected()).to.be.false
  106. await submitCheckboxForm()
  107. await waitForLogsPage()
  108. await waitForExecutionComplete()
  109. await waitForTerminalOutput('0')
  110. })
  111. it('Checkbox argument can be toggled and submitted', async function () {
  112. this.timeout(15000)
  113. await openCheckboxArgumentForm()
  114. const checkboxInput = await getCheckboxInput()
  115. await checkboxInput.click()
  116. await webdriver.sleep(100)
  117. expect(await checkboxInput.isSelected()).to.be.true
  118. await submitCheckboxForm()
  119. await waitForLogsPage()
  120. await waitForExecutionComplete()
  121. await waitForTerminalOutput('1')
  122. })
  123. })