authChangeEventStream.mjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { By, until } from 'selenium-webdriver'
  2. import {
  3. getRootAndWait,
  4. takeScreenshotOnFailure,
  5. } from '../../lib/elements.js'
  6. const UI_WAIT_MS = 5000
  7. function actionButtonLocator (title) {
  8. return By.xpath(`//*[contains(@class, 'action-button')]//button[contains(., '${title}')]`)
  9. }
  10. async function clickActionAndWaitForSuccess (title) {
  11. const button = await webdriver.wait(until.elementLocated(actionButtonLocator(title)), UI_WAIT_MS)
  12. await button.click()
  13. await webdriver.wait(async () => {
  14. const classes = await button.getAttribute('class')
  15. return classes.includes('action-success')
  16. }, UI_WAIT_MS)
  17. }
  18. describe('config: authChangeEventStream', function () {
  19. before(async function () {
  20. await runner.start('authChangeEventStream')
  21. })
  22. after(async () => {
  23. await webdriver.manage().deleteAllCookies()
  24. await runner.stop()
  25. })
  26. afterEach(function () {
  27. takeScreenshotOnFailure(this.currentTest, webdriver)
  28. })
  29. it('delivers execution events for the new user after logging in without a page refresh', async () => {
  30. await getRootAndWait()
  31. await clickActionAndWaitForSuccess('Guest action')
  32. const loginLink = await webdriver.wait(until.elementLocated(By.css('a.login-link')), UI_WAIT_MS)
  33. await loginLink.click()
  34. const username = await webdriver.wait(until.elementLocated(By.id('username')), UI_WAIT_MS)
  35. await username.sendKeys('alice')
  36. await webdriver.findElement(By.id('password')).sendKeys('password')
  37. await webdriver.findElement(By.css('button.login-button')).click()
  38. await clickActionAndWaitForSuccess('Admin action')
  39. })
  40. })