aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/videos.e2e-spec.ts
blob: c19ab30927d1a4ad817233d7503e5e8ce3a47d31 (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
import { VideoWatchPage } from './po/video-watch.po'
import { VideoUploadPage } from './po/video-upload.po'
import { LoginPage } from './po/login.po'
import { browser } from 'protractor'
import { VideoUpdatePage } from './po/video-update.po'
import { MyAccountPage } from './po/my-account'

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

  return false
}

async function isMobileDevice () {
  const caps = await browser.getCapabilities()
  return caps.get('realMobile') === 'true' || caps.get('realMobile') === true
}

async function isSafari () {
  const caps = await browser.getCapabilities()
  return caps.get('browserName') && caps.get('browserName').toLowerCase() === 'safari'
}

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

  const videoName = new Date().getTime() + ' video'
  let videoWatchUrl: string

  beforeEach(async () => {
    videoWatchPage = new VideoWatchPage()
    videoUploadPage = new VideoUploadPage()
    videoUpdatePage = new VideoUpdatePage()
    myAccountPage = new MyAccountPage()
    loginPage = new LoginPage()

    if (await isMobileDevice()) {
      console.log('Mobile device detected.')
    }

    if (await isSafari()) {
      console.log('Safari detected.')
    }
  })

  it('Should log in', async () => {
    if (await isMobileDevice() || await 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 (await skipIfUploadNotSupported()) return

    await videoUploadPage.navigateTo()

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

  it('Should list videos', async () => {
    await videoWatchPage.goOnVideosList(await isMobileDevice(), await isSafari())

    if (await skipIfUploadNotSupported()) return

    const videoNames = videoWatchPage.getVideosListName()
    expect(videoNames).toContain(videoName)
  })

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

    if (await isMobileDevice() || await isSafari()) videoNameToExcept = await videoWatchPage.clickOnFirstVideo()
    else await videoWatchPage.clickOnVideo(videoName)

    return videoWatchPage.waitWatchVideoName(videoNameToExcept, await isMobileDevice(), await isSafari())
  })

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

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

  it('Should watch the associated embed video', async () => {
    await browser.waitForAngularEnabled(false)

    await videoWatchPage.goOnAssociatedEmbed()

    await videoWatchPage.playAndPauseVideo(false, await isMobileDevice())
    expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)

    await browser.waitForAngularEnabled(true)
  })

  it('Should watch the p2p media loader embed video', async () => {
    await browser.waitForAngularEnabled(false)

    await videoWatchPage.goOnP2PMediaLoaderEmbed()

    await videoWatchPage.playAndPauseVideo(false, await isMobileDevice())
    expect(videoWatchPage.getWatchVideoPlayerCurrentTime()).toBeGreaterThanOrEqual(2)

    await browser.waitForAngularEnabled(true)
  })

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

    await browser.get(videoWatchUrl)

    await videoWatchPage.clickOnUpdate()

    await videoUpdatePage.updateName('my new name')

    await videoUpdatePage.validUpdate()

    const name = await videoWatchPage.getVideoName()
    expect(name).toEqual('my new name')
  })

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

    await videoWatchPage.clickOnSave()
    await videoWatchPage.saveToWatchLater()

    await videoUploadPage.navigateTo()

    await videoUploadPage.uploadVideo()
    await videoUploadPage.validSecondUploadStep('second video')

    await videoWatchPage.clickOnSave()
    await videoWatchPage.saveToWatchLater()
  })

  it('Should have the watch later playlist in my account', async () => {
    if (await skipIfUploadNotSupported()) return

    await myAccountPage.navigateToMyPlaylists()

    const name = await myAccountPage.getLastUpdatedPlaylistName()
    expect(name).toEqual('Watch later')

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

    await myAccountPage.clickOnLastUpdatedPlaylist()

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

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

    await myAccountPage.playPlaylist()

    await videoWatchPage.waitUntilVideoName('second video', 20000 * 1000)
  })

  it('Should have the video in my account', async () => {
    if (await skipIfUploadNotSupported()) return

    await myAccountPage.navigateToMyVideos()

    const lastVideoName = await myAccountPage.getLastVideoName()
    expect(lastVideoName).toEqual('second video')
  })

  it('Should delete the last video', async () => {
    if (await skipIfUploadNotSupported()) return

    await myAccountPage.removeLastVideo()
    await myAccountPage.validRemove()

    const count = await myAccountPage.countVideos()
    expect(count).toEqual(1)
  })

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

    await myAccountPage.removeLastVideo()
    await myAccountPage.validRemove()

    const count = await myAccountPage.countVideos()
    expect(count).toEqual(0)
  })
})