]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/e2e/src/po/login.po.ts
Remove browserstack.err
[github/Chocobozzz/PeerTube.git] / client / e2e / src / po / login.po.ts
index 90b65c7ea216ba037540d904f664888ffee7c854..91bf46e302225a9103f216931f91c372bb01a5ac 100644 (file)
@@ -1,20 +1,77 @@
-import { browser, element, by } from 'protractor'
+import { go } from '../utils'
 
 export class LoginPage {
+
+  constructor (private isMobileDevice: boolean) {
+
+  }
+
+  async login (username: string, password: string, url = '/login') {
+    await go(url)
+
+    await browser.execute(`window.localStorage.setItem('no_account_setup_warning_modal', 'true')`)
+    await browser.execute(`window.localStorage.setItem('no_instance_config_warning_modal', 'true')`)
+    await browser.execute(`window.localStorage.setItem('no_welcome_modal', 'true')`)
+
+    await $('input#username').setValue(username)
+    await $('input#password').setValue(password)
+
+    await browser.pause(1000)
+
+    await $('form input[type=submit]').click()
+
+    const menuToggle = $('.top-left-block span[role=button]')
+
+    if (this.isMobileDevice) {
+      await browser.pause(1000)
+
+      await menuToggle.click()
+    }
+
+    await this.ensureIsLoggedInAs(username)
+
+    if (this.isMobileDevice) {
+      await menuToggle.click()
+    }
+  }
+
   async loginAsRootUser () {
-    await browser.get('/login')
+    return this.login('root', 'test' + this.getSuffix())
+  }
+
+  loginOnPeerTube2 () {
+    return this.login('e2e', process.env.PEERTUBE2_E2E_PASSWORD, 'https://peertube2.cpy.re/login')
+  }
 
-    element(by.css('input#username')).sendKeys('root')
-    element(by.css('input#password')).sendKeys('test1')
+  async logout () {
+    const loggedInMore = $('.logged-in-more')
 
-    await browser.sleep(1000)
+    await loggedInMore.waitForClickable()
+    await loggedInMore.click()
 
-    await element(by.css('form input[type=submit]')).click()
+    const logout = $('.dropdown-item*=Log out')
+
+    await logout.waitForClickable()
+    await logout.click()
+
+    await browser.waitUntil(() => {
+      return $('.login-buttons-block, my-error-page a[href="/login"]').isDisplayed()
+    })
+  }
+
+  async ensureIsLoggedInAs (displayName: string) {
+    await this.getLoggedInInfoElem().waitForExist()
+
+    await expect(this.getLoggedInInfoElem()).toHaveText(displayName)
+  }
 
-    expect(this.getLoggedInInfo().getText()).toContain('root')
+  private getLoggedInInfoElem () {
+    return $('.logged-in-display-name')
   }
 
-  private getLoggedInInfo () {
-    return element(by.css('.logged-in-display-name'))
+  private getSuffix () {
+    return browser.config.baseUrl
+      ? browser.config.baseUrl.slice(-1)
+      : '1'
   }
 }