1 import { go } from '../utils'
3 export class LoginPage {
5 constructor (private isMobileDevice: boolean) {
9 async login (options: {
15 const { username, password, url = '/login', displayName = username } = options
19 await browser.execute(`window.localStorage.setItem('no_account_setup_warning_modal', 'true')`)
20 await browser.execute(`window.localStorage.setItem('no_instance_config_warning_modal', 'true')`)
21 await browser.execute(`window.localStorage.setItem('no_welcome_modal', 'true')`)
23 await $('input#username').setValue(username)
24 await $('input#password').setValue(password)
26 await browser.pause(1000)
28 await $('form input[type=submit]').click()
30 if (this.isMobileDevice) {
31 const menuToggle = $('.top-left-block span[role=button]')
33 await $('h2=Our content selection').waitForDisplayed()
35 await menuToggle.click()
37 await this.ensureIsLoggedInAs(displayName)
39 await menuToggle.click()
41 await this.ensureIsLoggedInAs(displayName)
45 async getLoginError (username: string, password: string) {
48 await $('input#username').setValue(username)
49 await $('input#password').setValue(password)
51 await browser.pause(1000)
53 await $('form input[type=submit]').click()
55 return $('.alert-danger').getText()
58 async loginAsRootUser () {
59 return this.login({ username: 'root', password: 'test' + this.getSuffix() })
63 if (!process.env.PEERTUBE2_E2E_PASSWORD) {
64 throw new Error('PEERTUBE2_E2E_PASSWORD env is missing for user e2e on peertube2.cpy.re')
67 return this.login({ username: 'e2e', password: process.env.PEERTUBE2_E2E_PASSWORD, url: 'https://peertube2.cpy.re/login' })
71 const loggedInDropdown = $('.logged-in-more .logged-in-info')
73 await loggedInDropdown.waitForClickable()
74 await loggedInDropdown.click()
76 const logout = $('.dropdown-item*=Log out')
78 await logout.waitForClickable()
81 await browser.waitUntil(() => {
82 return $('.login-buttons-block, my-error-page a[href="/login"]').isDisplayed()
86 async ensureIsLoggedInAs (displayName: string) {
87 await this.getLoggedInInfoElem().waitForExist()
89 await expect(this.getLoggedInInfoElem()).toHaveText(displayName)
92 private getLoggedInInfoElem () {
93 return $('.logged-in-display-name')
96 private getSuffix () {
97 return browser.config.baseUrl
98 ? browser.config.baseUrl.slice(-1)