diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-30 16:24:25 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-09-01 15:06:46 +0200 |
commit | 3419e0e1fe8e48a08b63ca0ded31087f913eb2b6 (patch) | |
tree | 63ac7190b79194e93aec9bbfd3c336e60f469e9d /client/e2e/src/po/video-watch.po.ts | |
parent | 2a4c9669d2d6ac6cd4ae43544698f826ae98080f (diff) | |
download | PeerTube-3419e0e1fe8e48a08b63ca0ded31087f913eb2b6.tar.gz PeerTube-3419e0e1fe8e48a08b63ca0ded31087f913eb2b6.tar.zst PeerTube-3419e0e1fe8e48a08b63ca0ded31087f913eb2b6.zip |
Migrate to webdriverio
Diffstat (limited to 'client/e2e/src/po/video-watch.po.ts')
-rw-r--r-- | client/e2e/src/po/video-watch.po.ts | 132 |
1 files changed, 83 insertions, 49 deletions
diff --git a/client/e2e/src/po/video-watch.po.ts b/client/e2e/src/po/video-watch.po.ts index c875d5854..01061d5d4 100644 --- a/client/e2e/src/po/video-watch.po.ts +++ b/client/e2e/src/po/video-watch.po.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor' | 1 | import { browserSleep, go } from '../utils' |
2 | import { browserSleep, isMobileDevice } from '../utils' | ||
3 | 2 | ||
4 | export class VideoWatchPage { | 3 | export class VideoWatchPage { |
5 | async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) { | 4 | async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) { |
@@ -12,19 +11,19 @@ export class VideoWatchPage { | |||
12 | url = '/videos/recently-added' | 11 | url = '/videos/recently-added' |
13 | } | 12 | } |
14 | 13 | ||
15 | await browser.get(url, 20000) | 14 | await go(url) |
16 | 15 | ||
17 | // Waiting the following element does not work on Safari... | 16 | // Waiting the following element does not work on Safari... |
18 | if (isSafari) return browserSleep(3000) | 17 | if (isSafari) return browserSleep(3000) |
19 | 18 | ||
20 | const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first() | 19 | await $('.videos .video-miniature .video-miniature-name').waitForDisplayed() |
21 | return browser.wait(browser.ExpectedConditions.visibilityOf(elem)) | ||
22 | } | 20 | } |
23 | 21 | ||
24 | getVideosListName () { | 22 | async getVideosListName () { |
25 | return element.all(by.css('.videos .video-miniature .video-miniature-name')) | 23 | const elems = await $$('.videos .video-miniature .video-miniature-name') |
26 | .getText() | 24 | const texts = await Promise.all(elems.map(e => e.getText())) |
27 | .then((texts: any) => texts.map((t: any) => t.trim())) | 25 | |
26 | return texts.map(t => t.trim()) | ||
28 | } | 27 | } |
29 | 28 | ||
30 | waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) { | 29 | waitWatchVideoName (videoName: string, isMobileDevice: boolean, isSafari: boolean) { |
@@ -33,99 +32,134 @@ export class VideoWatchPage { | |||
33 | // On mobile we display the first node, on desktop the second | 32 | // On mobile we display the first node, on desktop the second |
34 | const index = isMobileDevice ? 0 : 1 | 33 | const index = isMobileDevice ? 0 : 1 |
35 | 34 | ||
36 | const elem = element.all(by.css('.video-info .video-info-name')).get(index) | 35 | return browser.waitUntil(async () => { |
37 | return browser.wait(browser.ExpectedConditions.textToBePresentInElement(elem, videoName)) | 36 | return (await $$('.video-info .video-info-name')[index].getText()).includes(videoName) |
37 | }) | ||
38 | } | 38 | } |
39 | 39 | ||
40 | getVideoName () { | 40 | getVideoName () { |
41 | return this.getVideoNameElement().getText() | 41 | return this.getVideoNameElement().then(e => e.getText()) |
42 | } | 42 | } |
43 | 43 | ||
44 | async goOnAssociatedEmbed () { | 44 | async goOnAssociatedEmbed () { |
45 | let url = await browser.getCurrentUrl() | 45 | let url = await browser.getUrl() |
46 | url = url.replace('/w/', '/videos/embed/') | 46 | url = url.replace('/w/', '/videos/embed/') |
47 | url = url.replace(':3333', ':9001') | 47 | url = url.replace(':3333', ':9001') |
48 | 48 | ||
49 | return browser.get(url) | 49 | return go(url) |
50 | } | 50 | } |
51 | 51 | ||
52 | async goOnP2PMediaLoaderEmbed () { | 52 | goOnP2PMediaLoaderEmbed () { |
53 | return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50') | 53 | return go( |
54 | 'https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50' | ||
55 | ) | ||
54 | } | 56 | } |
55 | 57 | ||
56 | async goOnP2PMediaLoaderPlaylistEmbed () { | 58 | goOnP2PMediaLoaderPlaylistEmbed () { |
57 | return browser.get('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 59 | return go( |
60 | 'https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a' | ||
61 | ) | ||
58 | } | 62 | } |
59 | 63 | ||
60 | async clickOnVideo (videoName: string) { | 64 | async clickOnVideo (videoName: string) { |
61 | const video = element.all(by.css('.videos .video-miniature .video-miniature-name')) | 65 | const video = async () => { |
62 | .filter(e => e.getText().then(t => t === videoName )) | 66 | const videos = await $$('.videos .video-miniature .video-miniature-name').filter(async e => { |
63 | .first() | 67 | const t = await e.getText() |
68 | |||
69 | return t === videoName | ||
70 | }) | ||
71 | |||
72 | return videos[0] | ||
73 | } | ||
74 | |||
75 | await browser.waitUntil(async () => { | ||
76 | const elem = await video() | ||
64 | 77 | ||
65 | await browser.wait(browser.ExpectedConditions.elementToBeClickable(video)) | 78 | return elem?.isClickable() |
66 | await video.click() | 79 | }); |
67 | 80 | ||
68 | await browser.wait(browser.ExpectedConditions.urlContains('/w/')) | 81 | (await video()).click() |
82 | |||
83 | await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/')) | ||
69 | } | 84 | } |
70 | 85 | ||
71 | async clickOnFirstVideo () { | 86 | async clickOnFirstVideo () { |
72 | const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first() | 87 | const video = () => $('.videos .video-miniature .video-thumbnail') |
73 | const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first() | 88 | const videoName = () => $('.videos .video-miniature .video-miniature-name') |
89 | |||
90 | await video().waitForClickable() | ||
74 | 91 | ||
75 | // Don't know why but the expectation fails on Safari | 92 | const textToReturn = await videoName().getText() |
76 | await browser.wait(browser.ExpectedConditions.elementToBeClickable(video)) | 93 | await video().click() |
77 | 94 | ||
78 | const textToReturn = videoName.getText() | 95 | await browser.waitUntil(async () => (await browser.getUrl()).includes('/w/')) |
79 | await video.click() | ||
80 | 96 | ||
81 | await browser.wait(browser.ExpectedConditions.urlContains('/w/')) | ||
82 | return textToReturn | 97 | return textToReturn |
83 | } | 98 | } |
84 | 99 | ||
85 | async clickOnUpdate () { | 100 | async clickOnUpdate () { |
86 | const dropdown = element(by.css('my-video-actions-dropdown .action-button')) | 101 | const dropdown = $('my-video-actions-dropdown .action-button') |
87 | await dropdown.click() | 102 | await dropdown.click() |
88 | 103 | ||
89 | const items: ElementFinder[] = await element.all(by.css('.dropdown-menu.show .dropdown-item')) | 104 | await $('.dropdown-menu.show .dropdown-item').waitForDisplayed() |
105 | const items = await $$('.dropdown-menu.show .dropdown-item') | ||
90 | 106 | ||
91 | for (const item of items) { | 107 | for (const item of items) { |
92 | const href = await item.getAttribute('href') | 108 | const href = await item.getAttribute('href') |
93 | 109 | ||
94 | if (href && href.includes('/update/')) { | 110 | if (href?.includes('/update/')) { |
95 | await item.click() | 111 | await item.click() |
96 | return | 112 | return |
97 | } | 113 | } |
98 | } | 114 | } |
99 | } | 115 | } |
100 | 116 | ||
101 | async clickOnSave () { | 117 | clickOnSave () { |
102 | return element(by.css('.action-button-save')).click() | 118 | return $('.action-button-save').click() |
103 | } | 119 | } |
104 | 120 | ||
105 | async createPlaylist (name: string) { | 121 | async createPlaylist (name: string) { |
106 | await element(by.css('.new-playlist-button')).click() | 122 | const newPlaylistButton = () => $('.new-playlist-button') |
123 | |||
124 | await newPlaylistButton().waitForClickable() | ||
125 | await newPlaylistButton().click() | ||
126 | |||
127 | const displayName = () => $('#displayName') | ||
107 | 128 | ||
108 | await element(by.css('#displayName')).sendKeys(name) | 129 | await displayName().waitForDisplayed() |
130 | await displayName().setValue(name) | ||
109 | 131 | ||
110 | return element(by.css('.new-playlist-block input[type=submit]')).click() | 132 | return $('.new-playlist-block input[type=submit]').click() |
111 | } | 133 | } |
112 | 134 | ||
113 | async saveToPlaylist (name: string) { | 135 | async saveToPlaylist (name: string) { |
114 | return element.all(by.css('my-video-add-to-playlist .playlist')) | 136 | const playlist = () => $('my-video-add-to-playlist').$(`.playlist=${name}`) |
115 | .filter(p => p.getText().then(t => t === name)) | 137 | |
116 | .click() | 138 | await playlist().waitForDisplayed() |
139 | |||
140 | return playlist().click() | ||
117 | } | 141 | } |
118 | 142 | ||
119 | waitUntilVideoName (name: string, maxTime: number) { | 143 | waitUntilVideoName (name: string, maxTime: number) { |
120 | const elem = this.getVideoNameElement() | 144 | return browser.waitUntil(async () => { |
121 | 145 | return (await this.getVideoName()) === name | |
122 | return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime) | 146 | }, { timeout: maxTime }) |
123 | } | 147 | } |
124 | 148 | ||
125 | private getVideoNameElement () { | 149 | private async getVideoNameElement () { |
126 | // We have 2 video info name block, pick the first that is not empty | 150 | // We have 2 video info name block, pick the first that is not empty |
127 | return element.all(by.css('.video-info-first-row .video-info-name')) | 151 | const elem = async () => { |
128 | .filter(e => e.getText().then(t => !!t)) | 152 | const elems = await $$('.video-info-first-row .video-info-name').filter(e => e.isDisplayed()) |
129 | .first() | 153 | |
154 | return elems[0] | ||
155 | } | ||
156 | |||
157 | await browser.waitUntil(async () => { | ||
158 | const e = await elem() | ||
159 | |||
160 | return e?.isDisplayed() | ||
161 | }) | ||
162 | |||
163 | return elem() | ||
130 | } | 164 | } |
131 | } | 165 | } |