video-watch.po.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { FIXTURE_URLS } from '../urls'
  2. import { browserSleep, go } from '../utils'
  3. export class VideoWatchPage {
  4. async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
  5. let url: string
  6. // We did not upload a file on a mobile device
  7. if (isMobileDevice === true || isSafari === true) {
  8. url = 'https://peertube2.cpy.re/videos/local'
  9. } else {
  10. url = '/videos/recently-added'
  11. }
  12. await go(url)
  13. // Waiting the following element does not work on Safari...
  14. if (isSafari) return browserSleep(3000)
  15. await $('.videos .video-miniature .video-miniature-name').waitForDisplayed()
  16. }
  17. async getVideosListName () {
  18. const elems = await $$('.videos .video-miniature .video-miniature-name')
  19. const texts = await Promise.all(elems.map(e => e.getText()))
  20. return texts.map(t => t.trim())
  21. }
  22. waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) {
  23. if (isSafari) return browserSleep(5000)
  24. // On mobile we display the first node, on desktop the second
  25. const index = isMobileDevice ? 0 : 1
  26. return browser.waitUntil(async () => {
  27. return (await $$('.video-info .video-info-name')[index].getText()).includes(videoName)
  28. })
  29. }
  30. getVideoName () {
  31. return this.getVideoNameElement().then(e => e.getText())
  32. }
  33. async goOnAssociatedEmbed () {
  34. let url = await browser.getUrl()
  35. url = url.replace('/w/', '/videos/embed/')
  36. url = url.replace(':3333', ':9001')
  37. return go(url)
  38. }
  39. goOnP2PMediaLoaderEmbed () {
  40. return go(FIXTURE_URLS.HLS_EMBED)
  41. }
  42. goOnP2PMediaLoaderPlaylistEmbed () {
  43. return go(FIXTURE_URLS.HLS_PLAYLIST_EMBED)
  44. }
  45. async clickOnVideo (videoName: string) {
  46. const video = async () => {
  47. const videos = await $$('.videos .video-miniature .video-miniature-name').filter(async e => {
  48. const t = await e.getText()
  49. return t === videoName
  50. })
  51. return videos[0]
  52. }
  53. await browser.waitUntil(async () => {
  54. const elem = await video()
  55. return elem?.isClickable()
  56. });
  57. (await video()).click()
  58. await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
  59. }
  60. async clickOnFirstVideo () {
  61. const video = () => $('.videos .video-miniature .video-thumbnail')
  62. const videoName = () => $('.videos .video-miniature .video-miniature-name')
  63. await video().waitForClickable()
  64. const textToReturn = await videoName().getText()
  65. await video().click()
  66. await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/'))
  67. return textToReturn
  68. }
  69. async clickOnUpdate () {
  70. const dropdown = $('my-video-actions-dropdown .action-button')
  71. await dropdown.click()
  72. await $('.dropdown-menu.show .dropdown-item').waitForDisplayed()
  73. const items = await $$('.dropdown-menu.show .dropdown-item')
  74. for (const item of items) {
  75. const href = await item.getAttribute('href')
  76. if (href?.includes('/update/')) {
  77. await item.click()
  78. return
  79. }
  80. }
  81. }
  82. clickOnSave () {
  83. return $('.action-button-save').click()
  84. }
  85. async createPlaylist (name: string) {
  86. const newPlaylistButton = () => $('.new-playlist-button')
  87. await newPlaylistButton().waitForClickable()
  88. await newPlaylistButton().click()
  89. const displayName = () => $('#displayName')
  90. await displayName().waitForDisplayed()
  91. await displayName().setValue(name)
  92. return $('.new-playlist-block input[type=submit]').click()
  93. }
  94. async saveToPlaylist (name: string) {
  95. const playlist = () => $('my-video-add-to-playlist').$(`.playlist=${name}`)
  96. await playlist().waitForDisplayed()
  97. return playlist().click()
  98. }
  99. waitUntilVideoName (name: string, maxTime: number) {
  100. return browser.waitUntil(async () => {
  101. return (await this.getVideoName()) === name
  102. }, { timeout: maxTime })
  103. }
  104. private async getVideoNameElement () {
  105. // We have 2 video info name block, pick the first that is not empty
  106. const elem = async () => {
  107. const elems = await $$('.video-info-first-row .video-info-name').filter(e => e.isDisplayed())
  108. return elems[0]
  109. }
  110. await browser.waitUntil(async () => {
  111. const e = await elem()
  112. return e?.isDisplayed()
  113. })
  114. return elem()
  115. }
  116. }