AtVideoView.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const { I } = inject();
  2. const Helpers = require("../tests/helpers");
  3. /**
  4. * @typedef BoundingClientRect
  5. * @property {number} x
  6. * @property {number} y
  7. * @property {number} width
  8. * @property {number} height
  9. */
  10. module.exports = {
  11. _rootSelector: ".lsf-video-segmentation",
  12. _videoRootSelector: ".lsf-video__main",
  13. _trackSelector: ".lsf-seeker__track",
  14. _indicatorSelector: ".lsf-seeker__indicator",
  15. _positionSelector: ".lsf-seeker__position",
  16. _seekStepForwardSelector: 'button[aria-label="Step forward"]',
  17. _seekStepBackwardSelector: 'button[aria-label="Step backward"]',
  18. _playButtonSelector: 'button[aria-label="Play"]',
  19. locateRootSelector() {
  20. return locate(this._rootSelector);
  21. },
  22. locateVideoContainer() {
  23. return locate(this._videoRootSelector);
  24. },
  25. videoLocate(locator) {
  26. return locator ? locate(locator).inside(this.locateVideoContainer()) : this.locateVideoContainer();
  27. },
  28. seekStepForwardSelector() {
  29. return locate(this._seekStepForwardSelector).inside(this.locateRootSelector());
  30. },
  31. seekStepBackwardSelector() {
  32. return locate(this._seekStepBackwardSelector).inside(this.locateRootSelector());
  33. },
  34. playButtonSelector() {
  35. return locate(this._playButtonSelector).inside(this.locateRootSelector());
  36. },
  37. getCurrentVideo() {
  38. return I.executeScript(Helpers.getCurrentMedia, "video");
  39. },
  40. /**
  41. * Grab the bounding rect of the video track
  42. * @returns {Promise<BoundingClientRect>}
  43. */
  44. async grabTrackBoundingRect() {
  45. return I.grabElementBoundingRect(this._trackSelector);
  46. },
  47. /**
  48. * Grab the bounding rect of the video indicator (the slider that outlines the viewable region)
  49. * @returns {Promise<BoundingClientRect>}
  50. */
  51. async grabIndicatorBoundingRect() {
  52. return I.grabElementBoundingRect(this._indicatorSelector);
  53. },
  54. /**
  55. * Grab the bounding rect of the video position (the playhead/cursor element).
  56. * @returns {Promise<BoundingClientRect>}
  57. */
  58. async grabPositionBoundingRect() {
  59. return I.grabElementBoundingRect(this._positionSelector);
  60. },
  61. /**
  62. * Drag the element to the given position
  63. * @param {BoundingClientRect} bbox
  64. * @param {number} x
  65. * @param {number} [y=undefined]
  66. * @returns {Promise<void>}
  67. */
  68. async drag(bbox, x, y) {
  69. const from = { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 };
  70. const to = { x, y: y || from.y };
  71. return I.dragAndDropMouse(from, to);
  72. },
  73. /**
  74. * Seek forward steps
  75. * @param {number} steps
  76. * @returns {Promise<void>}
  77. */
  78. async clickSeekStepForward(steps = 1) {
  79. for (let i = 0; i < steps; i++) {
  80. I.click(this.seekStepForwardSelector());
  81. }
  82. },
  83. /**
  84. * Seek backward steps
  85. * @param {number} steps
  86. * @returns {Promise<void>}
  87. */
  88. async clickSeekStepBackward(steps = 2) {
  89. for (let i = 0; i < steps; i++) {
  90. I.click(this.seekStepBackwardSelector());
  91. }
  92. },
  93. /**
  94. * Click the video controls play button.
  95. * @returns {Promise<void>}
  96. */
  97. async clickPlayButton() {
  98. I.click(this.playButtonSelector());
  99. },
  100. /**
  101. * Click the video controls pause button.
  102. * @returns {Promise<void>}
  103. */
  104. async clickPauseButton() {
  105. I.click(this.playButtonSelector());
  106. },
  107. };