]>
Commit | Line | Data |
---|---|---|
1 | import { browser, by, element, ElementFinder, ExpectedConditions } 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: any) => t.trim())) | |
27 | } | |
28 | ||
29 | waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) { | |
30 | // On mobile we display the first node, on desktop the second | |
31 | const index = isMobileDevice ? 0 : 1 | |
32 | ||
33 | const elem = element.all(by.css('.video-info .video-info-name')).get(index) | |
34 | ||
35 | if (isSafari) return browser.sleep(5000) | |
36 | ||
37 | return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName)) | |
38 | } | |
39 | ||
40 | getWatchVideoPlayerCurrentTime () { | |
41 | return element(by.css('.video-js .vjs-current-time-display')) | |
42 | .getText() | |
43 | .then((t: string) => t.split(':')[1]) | |
44 | .then(seconds => parseInt(seconds, 10)) | |
45 | } | |
46 | ||
47 | getVideoName () { | |
48 | return this.getVideoNameElement().getText() | |
49 | } | |
50 | ||
51 | async playAndPauseVideo (isAutoplay: boolean, isMobileDevice: boolean) { | |
52 | if (isAutoplay === false) { | |
53 | const playButton = element(by.css('.vjs-big-play-button')) | |
54 | await browser.wait(browser.ExpectedConditions.elementToBeClickable(playButton)) | |
55 | await playButton.click() | |
56 | } | |
57 | ||
58 | await browser.sleep(1000) | |
59 | await browser.wait(browser.ExpectedConditions.invisibilityOf(element(by.css('.vjs-loading-spinner')))) | |
60 | ||
61 | const videojsEl = element(by.css('div.video-js')) | |
62 | await browser.wait(browser.ExpectedConditions.elementToBeClickable(videojsEl)) | |
63 | ||
64 | // On Android, we need to click twice on "play" (BrowserStack particularity) | |
65 | if (isMobileDevice) { | |
66 | await browser.sleep(3000) | |
67 | await videojsEl.click() | |
68 | } | |
69 | ||
70 | await browser.sleep(7000) | |
71 | ||
72 | return videojsEl.click() | |
73 | } | |
74 | ||
75 | async clickOnVideo (videoName: string) { | |
76 | const video = element(by.css('.videos .video-miniature .video-thumbnail[title="' + videoName + '"]')) | |
77 | await browser.wait(browser.ExpectedConditions.elementToBeClickable(video)) | |
78 | await video.click() | |
79 | ||
80 | await browser.wait(browser.ExpectedConditions.urlContains('/watch/')) | |
81 | } | |
82 | ||
83 | async clickOnFirstVideo () { | |
84 | const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first() | |
85 | const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first() | |
86 | ||
87 | // Don't know why but the expectation fails on Safari | |
88 | await browser.wait(browser.ExpectedConditions.elementToBeClickable(video)) | |
89 | ||
90 | const textToReturn = videoName.getText() | |
91 | await video.click() | |
92 | ||
93 | await browser.wait(browser.ExpectedConditions.urlContains('/watch/')) | |
94 | return textToReturn | |
95 | } | |
96 | ||
97 | async goOnAssociatedEmbed () { | |
98 | let url = await browser.getCurrentUrl() | |
99 | url = url.replace('/watch/', '/embed/') | |
100 | url = url.replace(':3333', ':9001') | |
101 | ||
102 | return browser.get(url) | |
103 | } | |
104 | ||
105 | async goOnP2PMediaLoaderEmbed () { | |
106 | return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50?mode=p2p-media-loader') | |
107 | } | |
108 | ||
109 | async clickOnUpdate () { | |
110 | const dropdown = element(by.css('my-video-actions-dropdown .action-button')) | |
111 | await dropdown.click() | |
112 | ||
113 | const items: ElementFinder[] = await element.all(by.css('my-video-actions-dropdown .dropdown-menu .dropdown-item')) | |
114 | ||
115 | for (const item of items) { | |
116 | const href = await item.getAttribute('href') | |
117 | ||
118 | if (href && href.includes('/update/')) { | |
119 | await item.click() | |
120 | return | |
121 | } | |
122 | } | |
123 | } | |
124 | ||
125 | async clickOnSave () { | |
126 | return element(by.css('.action-button-save')).click() | |
127 | } | |
128 | ||
129 | async createPlaylist (name: string) { | |
130 | await element(by.css('.new-playlist-button')).click() | |
131 | ||
132 | await element(by.css('#displayName')).sendKeys(name) | |
133 | ||
134 | return element(by.css('.new-playlist-block input[type=submit]')).click() | |
135 | } | |
136 | ||
137 | async saveToPlaylist (name: string) { | |
138 | return element.all(by.css('my-video-add-to-playlist .playlist')) | |
139 | .filter(p => p.getText().then(t => t === name)) | |
140 | .click() | |
141 | } | |
142 | ||
143 | waitUntilVideoName (name: string, maxTime: number) { | |
144 | const elem = this.getVideoNameElement() | |
145 | ||
146 | return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime) | |
147 | } | |
148 | ||
149 | private getVideoNameElement () { | |
150 | // We have 2 video info name block, pick the first that is not empty | |
151 | return element.all(by.css('.video-bottom .video-info-name')) | |
152 | .filter(e => e.getText().then(t => !!t)) | |
153 | .first() | |
154 | } | |
155 | } |