]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/e2e/src/po/video-watch.po.ts
Improve E2E tests
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / video-watch.po.ts
index 5f61d566883b1bd7c7a1e4e46347acbda2083e57..4a36fce62d1407151114814932fee3fa07d0e105 100644 (file)
@@ -1,4 +1,4 @@
-import { browser, by, element } from 'protractor'
+import { browser, by, element, ElementFinder, ExpectedConditions } from 'protractor'
 
 export class VideoWatchPage {
   async goOnVideosList (isMobileDevice: boolean, isSafari: boolean) {
@@ -14,7 +14,7 @@ export class VideoWatchPage {
     await browser.get(url)
 
     // Waiting the following element does not work on Safari...
-    if (isSafari === true) return browser.sleep(3000)
+    if (isSafari) return browser.sleep(3000)
 
     const elem = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
     return browser.wait(browser.ExpectedConditions.visibilityOf(elem))
@@ -44,6 +44,10 @@ export class VideoWatchPage {
       .then(seconds => parseInt(seconds, 10))
   }
 
+  getVideoName () {
+    return this.getVideoNameElement().getText()
+  }
+
   async playAndPauseVideo (isAutoplay: boolean, isMobileDevice: boolean) {
     if (isAutoplay === false) {
       const playButton = element(by.css('.vjs-big-play-button'))
@@ -69,7 +73,10 @@ export class VideoWatchPage {
   }
 
   async clickOnVideo (videoName: string) {
-    const video = element(by.css('.videos .video-miniature .video-thumbnail[title="' + videoName + '"]'))
+    const video = element.all(by.css('.videos .video-miniature .video-miniature-name'))
+    .filter(e => e.getText().then(t => t === videoName ))
+    .first()
+
     await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
     await video.click()
 
@@ -77,13 +84,12 @@ export class VideoWatchPage {
   }
 
   async clickOnFirstVideo () {
-    const video = element.all(by.css('.videos .video-miniature .video-thumbnail')).first()
-    const videoName = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
+    const video = element.all(by.css('.videos .video-miniature .video-miniature-name')).first()
 
     // Don't know why but the expectation fails on Safari
     await browser.wait(browser.ExpectedConditions.elementToBeClickable(video))
 
-    const textToReturn = videoName.getText()
+    const textToReturn = video.getText()
     await video.click()
 
     await browser.wait(browser.ExpectedConditions.urlContains('/watch/'))
@@ -99,6 +105,53 @@ export class VideoWatchPage {
   }
 
   async goOnP2PMediaLoaderEmbed () {
-    return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50?mode=p2p-media-loader')
+    return browser.get('https://peertube2.cpy.re/videos/embed/969bf103-7818-43b5-94a0-de159e13de50')
+  }
+
+  async clickOnUpdate () {
+    const dropdown = element(by.css('my-video-actions-dropdown .action-button'))
+    await dropdown.click()
+
+    const items: ElementFinder[] = await element.all(by.css('my-video-actions-dropdown .dropdown-menu .dropdown-item'))
+
+    for (const item of items) {
+      const href = await item.getAttribute('href')
+
+      if (href && href.includes('/update/')) {
+        await item.click()
+        return
+      }
+    }
+  }
+
+  async clickOnSave () {
+    return element(by.css('.action-button-save')).click()
+  }
+
+  async createPlaylist (name: string) {
+    await element(by.css('.new-playlist-button')).click()
+
+    await element(by.css('#displayName')).sendKeys(name)
+
+    return element(by.css('.new-playlist-block input[type=submit]')).click()
+  }
+
+  async saveToPlaylist (name: string) {
+    return element.all(by.css('my-video-add-to-playlist .playlist'))
+                  .filter(p => p.getText().then(t => t === name))
+                  .click()
+  }
+
+  waitUntilVideoName (name: string, maxTime: number) {
+    const elem = this.getVideoNameElement()
+
+    return browser.wait(ExpectedConditions.textToBePresentInElement(elem, name), maxTime)
+  }
+
+  private getVideoNameElement () {
+    // We have 2 video info name block, pick the first that is not empty
+    return element.all(by.css('.video-info-first-row .video-info-name'))
+                  .filter(e => e.getText().then(t => !!t))
+                  .first()
   }
 }