]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/po/video-watch.po.ts
Fix protractor with Safari
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
1 import { by, element, browser } from 'protractor'
2
3 export class VideoWatchPage {
4 async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
5 let url: string
6
7 // We did not upload a file on a mobile device
8 if (isMobileDevice === true || isSafari === true) {
9 url = 'https://peertube2.cpy.re/videos/local'
10 } else {
11 url = '/videos/recently-added'
12 }
13
14 await browser.get(url)
15
16 // Waiting the following element does not work on Safari...
17 if (isSafari === true) return browser.sleep(3000)
18
19 const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
20 return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
21 }
22
23 getVideosListName () {
24 return element.all(by.css('.videos .video-miniature .video-miniature-name'))
25 .getText()
26 .then((texts: any) => texts.map(t => t.trim()))
27 }
28
29 waitWatchVideoName (videoName: string, isSafari: boolean) {
30 const elem = element(by.css('.video-info .video-info-name'))
31
32 if (isSafari) return browser.sleep(5000)
33
34 return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName))
35 }
36
37 getWatchVideoPlayerCurrentTime () {
38 return element(by.css('.video-js .vjs-current-time-display'))
39 .getText()
40 .then((t: string) => t.split(':')[1])
41 .then(seconds => parseInt(seconds, 10))
42 }
43
44 async pauseVideo (isAutoplay: boolean, isDesktopSafari: boolean) {
45 if (isAutoplay === false) {
46 const playButton = element(by.css('.vjs-big-play-button'))
47 await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton))
48 await playButton.click()
49 }
50
51 // if (isDesktopSafari === true) {
52 // await browser.sleep(1000)
53 // await element(by.css('.vjs-play-control')).click()
54 // }
55
56 await browser.sleep(1000)
57 await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner'))))
58
59 const videojsEl = element(by.css('div.video-js'))
60 await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl))
61
62 await browser.sleep(7000)
63
64 return videojsEl.click()
65 }
66
67 async clickOnVideo (videoName: string) {
68 const video = element(by.css('.videos .video-miniature .video-thumbnail[title="' + videoName + '"]'))
69 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
70 await video.click()
71
72 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
73 }
74
75 async clickOnFirstVideo () {
76 const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
77 const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
78
79 // Don't know why but the expectation fails on Safari
80 await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
81
82 const textToReturn = videoName.getText()
83 await video.click()
84
85 await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
86 return textToReturn
87 }
88
89 async goOnAssociatedEmbed () {
90 let url = await browser.getCurrentUrl()
91 url = url.replace('/watch/', '/embed/')
92 url = url.replace(':3333', ':9001')
93
94 return browser.get(url)
95 }
96 }