]>
Commit | Line | Data |
---|---|---|
3419e0e1 | 1 | import { go } from '../utils' |
5f92c4dc C |
2 | |
3 | export class LoginPage { | |
6d210220 | 4 | |
814e9e07 C |
5 | constructor (private isMobileDevice: boolean) { |
6 | ||
7 | } | |
8 | ||
5bdfa604 C |
9 | async login (options: { |
10 | username: string | |
11 | password: string | |
12 | displayName?: string | |
13 | url?: string | |
14 | }) { | |
15 | const { username, password, url = '/login', displayName = username } = options | |
16 | ||
814e9e07 | 17 | await go(url) |
5f92c4dc | 18 | |
814e9e07 | 19 | await browser.execute(`window.localStorage.setItem('no_account_setup_warning_modal', 'true')`) |
3419e0e1 C |
20 | await browser.execute(`window.localStorage.setItem('no_instance_config_warning_modal', 'true')`) |
21 | await browser.execute(`window.localStorage.setItem('no_welcome_modal', 'true')`) | |
51b66ea7 | 22 | |
814e9e07 C |
23 | await $('input#username').setValue(username) |
24 | await $('input#password').setValue(password) | |
0b33c520 | 25 | |
3419e0e1 | 26 | await browser.pause(1000) |
5f92c4dc | 27 | |
3419e0e1 | 28 | await $('form input[type=submit]').click() |
5f92c4dc | 29 | |
814e9e07 | 30 | if (this.isMobileDevice) { |
b9b3d18d C |
31 | const menuToggle = $('.top-left-block span[role=button]') |
32 | ||
33 | await $('h2=Our content selection').waitForDisplayed() | |
814e9e07 C |
34 | |
35 | await menuToggle.click() | |
814e9e07 | 36 | |
5bdfa604 | 37 | await this.ensureIsLoggedInAs(displayName) |
814e9e07 | 38 | |
814e9e07 | 39 | await menuToggle.click() |
b9b3d18d | 40 | } else { |
5bdfa604 | 41 | await this.ensureIsLoggedInAs(displayName) |
814e9e07 C |
42 | } |
43 | } | |
44 | ||
5bdfa604 C |
45 | async getLoginError (username: string, password: string) { |
46 | await go('/login') | |
47 | ||
48 | await $('input#username').setValue(username) | |
49 | await $('input#password').setValue(password) | |
50 | ||
51 | await browser.pause(1000) | |
52 | ||
53 | await $('form input[type=submit]').click() | |
54 | ||
55 | return $('.alert-danger').getText() | |
56 | } | |
57 | ||
814e9e07 | 58 | async loginAsRootUser () { |
5bdfa604 | 59 | return this.login({ username: 'root', password: 'test' + this.getSuffix() }) |
814e9e07 C |
60 | } |
61 | ||
62 | loginOnPeerTube2 () { | |
5b94394a C |
63 | if (!process.env.PEERTUBE2_E2E_PASSWORD) { |
64 | throw new Error('PEERTUBE2_E2E_PASSWORD env is missing for user e2e on peertube2.cpy.re') | |
65 | } | |
66 | ||
5bdfa604 | 67 | return this.login({ username: 'e2e', password: process.env.PEERTUBE2_E2E_PASSWORD, url: 'https://peertube2.cpy.re/login' }) |
84c7cde6 C |
68 | } |
69 | ||
6d210220 | 70 | async logout () { |
5bdfa604 | 71 | const loggedInDropdown = $('.logged-in-more .logged-in-info') |
814e9e07 | 72 | |
5bdfa604 C |
73 | await loggedInDropdown.waitForClickable() |
74 | await loggedInDropdown.click() | |
6d210220 | 75 | |
814e9e07 | 76 | const logout = $('.dropdown-item*=Log out') |
6d210220 | 77 | |
814e9e07 C |
78 | await logout.waitForClickable() |
79 | await logout.click() | |
6d210220 | 80 | |
814e9e07 C |
81 | await browser.waitUntil(() => { |
82 | return $('.login-buttons-block, my-error-page a[href="/login"]').isDisplayed() | |
83 | }) | |
6d210220 C |
84 | } |
85 | ||
1db86422 C |
86 | async ensureIsLoggedInAs (displayName: string) { |
87 | await this.getLoggedInInfoElem().waitForExist() | |
88 | ||
89 | await expect(this.getLoggedInInfoElem()).toHaveText(displayName) | |
90 | } | |
91 | ||
3419e0e1 C |
92 | private getLoggedInInfoElem () { |
93 | return $('.logged-in-display-name') | |
5f92c4dc | 94 | } |
6d210220 C |
95 | |
96 | private getSuffix () { | |
97 | return browser.config.baseUrl | |
98 | ? browser.config.baseUrl.slice(-1) | |
99 | : '1' | |
100 | } | |
5f92c4dc | 101 | } |