datetime.mjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. } from '../lib/elements.js'
  9. describe('config: datetime', function () {
  10. before(async function () {
  11. await runner.start('datetime')
  12. })
  13. after(async () => {
  14. await runner.stop()
  15. })
  16. afterEach(function () {
  17. takeScreenshotOnFailure(this.currentTest, webdriver)
  18. })
  19. it('Datetime argument uses datetime-local input type', async function () {
  20. await getRootAndWait()
  21. const btn = await getActionButton(webdriver, 'Test datetime argument')
  22. await btn.click()
  23. // Wait for navigation to argument form page
  24. await webdriver.wait(
  25. new Condition('wait for argument form page', async () => {
  26. const url = await webdriver.getCurrentUrl()
  27. return url.includes('/actionBinding/') && url.includes('/argumentForm')
  28. }),
  29. 8000
  30. )
  31. // Find the datetime input field
  32. const datetimeInput = await webdriver.findElement(By.id('datetime'))
  33. // Verify it's a datetime-local input type
  34. const inputType = await datetimeInput.getAttribute('type')
  35. expect(inputType).to.equal('datetime-local', 'Input type should be datetime-local')
  36. // Verify it has the step attribute set to 1 (for seconds precision)
  37. const step = await datetimeInput.getAttribute('step')
  38. expect(step).to.equal('1', 'Step attribute should be 1')
  39. // Verify it's required
  40. const required = await datetimeInput.getAttribute('required')
  41. expect(required).to.not.be.null
  42. // Verify the label is present
  43. const label = await webdriver.findElement(By.css('label[for="datetime"]'))
  44. expect(await label.getText()).to.contain('Select a date and time')
  45. })
  46. it('Datetime argument can be filled and submitted', async function () {
  47. await getRootAndWait()
  48. const btn = await getActionButton(webdriver, 'Test datetime argument')
  49. await btn.click()
  50. // Wait for navigation to argument form page
  51. await webdriver.wait(
  52. new Condition('wait for argument form page', async () => {
  53. const url = await webdriver.getCurrentUrl()
  54. return url.includes('/actionBinding/') && url.includes('/argumentForm')
  55. }),
  56. 8000
  57. )
  58. // Find the datetime input field
  59. const datetimeInput = await webdriver.findElement(By.id('datetime'))
  60. // Set a datetime value (format: YYYY-MM-DDTHH:mm)
  61. // datetime-local returns values without seconds, backend will add :00
  62. const testDateTime = '2023-12-25T15:30'
  63. // Use JavaScript to set the value directly (more reliable for datetime-local inputs)
  64. await webdriver.executeScript(
  65. 'arguments[0].value = arguments[1]',
  66. datetimeInput,
  67. testDateTime
  68. )
  69. // Trigger input event to ensure Vue reactivity
  70. await webdriver.executeScript(
  71. 'arguments[0].dispatchEvent(new Event("input", { bubbles: true }))',
  72. datetimeInput
  73. )
  74. // Small wait for Vue to process the change
  75. await webdriver.sleep(100)
  76. // Verify the value was set
  77. const value = await datetimeInput.getAttribute('value')
  78. expect(value).to.equal(testDateTime)
  79. // Find and click the submit button
  80. const submitButton = await webdriver.findElement(
  81. By.css('button[name="start"]')
  82. )
  83. await submitButton.click()
  84. // Wait for navigation to logs page
  85. await webdriver.wait(
  86. new Condition('wait for logs page', async () => {
  87. const url = await webdriver.getCurrentUrl()
  88. return url.includes('/logs/')
  89. }),
  90. 8000
  91. )
  92. // Verify we're on the logs page (action was executed)
  93. const url = await webdriver.getCurrentUrl()
  94. expect(url).to.include('/logs/')
  95. })
  96. })