aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/suites-all/videos.e2e-spec.ts
blob: 3b8305a25fa4ef8295cd36a9eff4608f9f3a887d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import { LoginPage } from '../po/login.po'
import { MyAccountPage } from '../po/my-account'
import { PlayerPage } from '../po/player.po'
import { VideoListPage } from '../po/video-list.po'
import { VideoUpdatePage } from '../po/video-update.po'
import { VideoUploadPage } from '../po/video-upload.po'
import { VideoWatchPage } from '../po/video-watch.po'
import { FIXTURE_URLS, go, isIOS, isMobileDevice, isSafari, waitServerUp } from '../utils'

function isUploadUnsupported () {
  if (isMobileDevice() || isSafari()) {
    console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
    return true
  }

  return false
}

describe('Videos all workflow', () => {
  let videoWatchPage: VideoWatchPage
  let videoListPage: VideoListPage
  let videoUploadPage: VideoUploadPage
  let videoUpdatePage: VideoUpdatePage
  let myAccountPage: MyAccountPage
  let loginPage: LoginPage
  let playerPage: PlayerPage

  let videoName = Math.random() + ' video'
  const video2Name = Math.random() + ' second video'
  const playlistName = Math.random() + ' playlist'
  let videoWatchUrl: string

  before(async () => {
    if (isIOS()) {
      console.log('iOS detected')
    } else if (isMobileDevice()) {
      console.log('Android detected.')
    } else if (isSafari()) {
      console.log('Safari detected.')
    }

    if (isUploadUnsupported()) return

    await waitServerUp()
  })

  beforeEach(async () => {
    videoWatchPage = new VideoWatchPage(isMobileDevice(), isSafari())
    videoUploadPage = new VideoUploadPage()
    videoUpdatePage = new VideoUpdatePage()
    myAccountPage = new MyAccountPage()
    loginPage = new LoginPage()
    playerPage = new PlayerPage()
    videoListPage = new VideoListPage(isMobileDevice(), isSafari())

    if (!isMobileDevice()) {
      await browser.maximizeWindow()
    }
  })

  it('Should log in', async () => {
    if (isMobileDevice() || isSafari()) {
      console.log('Skipping because we are on a real device or Safari and BrowserStack does not support file upload.')
      return
    }

    return loginPage.loginAsRootUser()
  })

  it('Should upload a video', async () => {
    if (isUploadUnsupported()) return

    await videoUploadPage.navigateTo()

    await videoUploadPage.uploadVideo()
    return videoUploadPage.validSecondUploadStep(videoName)
  })

  it('Should list videos', async () => {
    await videoListPage.goOnVideosList()

    if (isUploadUnsupported()) return

    const videoNames = await videoListPage.getVideosListName()
    expect(videoNames).toContain(videoName)
  })

  it('Should go on video watch page', async () => {
    let videoNameToExcept = videoName

    if (isMobileDevice() || isSafari()) {
      await go(FIXTURE_URLS.WEBTORRENT_VIDEO)
      videoNameToExcept = 'E2E tests'
    } else {
      await videoListPage.clickOnVideo(videoName)
    }

    return videoWatchPage.waitWatchVideoName(videoNameToExcept)
  })

  it('Should play the video', async () => {
    videoWatchUrl = await browser.getUrl()

    await playerPage.playAndPauseVideo(true, 2)
    expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
  })

  it('Should watch the associated embed video', async () => {
    await videoWatchPage.goOnAssociatedEmbed()

    await playerPage.playAndPauseVideo(false, 2)
    expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
  })

  it('Should watch the p2p media loader embed video', async () => {
    await videoWatchPage.goOnP2PMediaLoaderEmbed()

    await playerPage.playAndPauseVideo(false, 2)
    expect(await playerPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)
  })

  it('Should update the video', async () => {
    if (isUploadUnsupported()) return

    await go(videoWatchUrl)

    await videoWatchPage.clickOnUpdate()

    videoName += ' updated'
    await videoUpdatePage.updateName(videoName)

    await videoUpdatePage.validUpdate()

    const name = await videoWatchPage.getVideoName()
    expect(name).toEqual(videoName)
  })

  it('Should add the video in my playlist', async () => {
    if (isUploadUnsupported()) return

    await videoWatchPage.clickOnSave()

    await videoWatchPage.createPlaylist(playlistName)

    await videoWatchPage.saveToPlaylist(playlistName)
    await browser.pause(5000)

    await videoUploadPage.navigateTo()

    await videoUploadPage.uploadVideo()
    await videoUploadPage.validSecondUploadStep(video2Name)

    await videoWatchPage.clickOnSave()
    await videoWatchPage.saveToPlaylist(playlistName)
  })

  it('Should have the playlist in my account', async () => {
    if (isUploadUnsupported()) return

    await myAccountPage.navigateToMyPlaylists()

    const videosNumberText = await myAccountPage.getPlaylistVideosText(playlistName)
    expect(videosNumberText).toEqual('2 videos')

    await myAccountPage.clickOnPlaylist(playlistName)

    const count = await myAccountPage.countTotalPlaylistElements()
    expect(count).toEqual(2)
  })

  it('Should watch the playlist', async () => {
    if (isUploadUnsupported()) return

    await myAccountPage.playPlaylist()

    await videoWatchPage.waitUntilVideoName(video2Name, 30 * 1000)
  })

  it('Should watch the webtorrent playlist in the embed', async () => {
    if (isUploadUnsupported()) return

    const accessToken = await browser.execute(`return window.localStorage.getItem('access_token');`)
    const refreshToken = await browser.execute(`return window.localStorage.getItem('refresh_token');`)

    await myAccountPage.goOnAssociatedPlaylistEmbed()

    await playerPage.waitUntilPlayerWrapper()

    console.log('Will set %s and %s tokens in local storage.', accessToken, refreshToken)

    await browser.execute(`window.localStorage.setItem('access_token', '${accessToken}');`)
    await browser.execute(`window.localStorage.setItem('refresh_token', '${refreshToken}');`)
    await browser.execute(`window.localStorage.setItem('token_type', 'Bearer');`)

    await browser.refresh()

    await playerPage.playVideo()

    await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
  })

  it('Should watch the HLS playlist in the embed', async () => {
    await videoWatchPage.goOnP2PMediaLoaderPlaylistEmbed()

    await playerPage.playVideo()

    await playerPage.waitUntilPlaylistInfo('2/2', 30 * 1000)
  })

  it('Should delete the video 2', async () => {
    if (isUploadUnsupported()) return

    // Go to the dev website
    await go(videoWatchUrl)

    await myAccountPage.navigateToMyVideos()

    await myAccountPage.removeVideo(video2Name)
    await myAccountPage.validRemove()

    await browser.waitUntil(async () => {
      const count = await myAccountPage.countVideos([ videoName, video2Name ])

      return count === 1
    })
  })

  it('Should delete the first video', async () => {
    if (isUploadUnsupported()) return

    await myAccountPage.removeVideo(videoName)
    await myAccountPage.validRemove()
  })
})