]>
Commit | Line | Data |
---|---|---|
1 | import { go } from '../utils' | |
2 | ||
3 | export class LoginPage { | |
4 | ||
5 | constructor (private isMobileDevice: boolean) { | |
6 | ||
7 | } | |
8 | ||
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 | ||
17 | await go(url) | |
18 | ||
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')`) | |
22 | ||
23 | await $('input#username').setValue(username) | |
24 | await $('input#password').setValue(password) | |
25 | ||
26 | await browser.pause(1000) | |
27 | ||
28 | await $('form input[type=submit]').click() | |
29 | ||
30 | if (this.isMobileDevice) { | |
31 | const menuToggle = $('.top-left-block span[role=button]') | |
32 | ||
33 | await $('h2=Our content selection').waitForDisplayed() | |
34 | ||
35 | await menuToggle.click() | |
36 | ||
37 | await this.ensureIsLoggedInAs(displayName) | |
38 | ||
39 | await menuToggle.click() | |
40 | } else { | |
41 | await this.ensureIsLoggedInAs(displayName) | |
42 | } | |
43 | } | |
44 | ||
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 | ||
58 | async loginAsRootUser () { | |
59 | return this.login({ username: 'root', password: 'test' + this.getSuffix() }) | |
60 | } | |
61 | ||
62 | loginOnPeerTube2 () { | |
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 | ||
67 | return this.login({ username: 'e2e', password: process.env.PEERTUBE2_E2E_PASSWORD, url: 'https://peertube2.cpy.re/login' }) | |
68 | } | |
69 | ||
70 | async logout () { | |
71 | const loggedInDropdown = $('.logged-in-more .logged-in-info') | |
72 | ||
73 | await loggedInDropdown.waitForClickable() | |
74 | await loggedInDropdown.click() | |
75 | ||
76 | const logout = $('.dropdown-item*=Log out') | |
77 | ||
78 | await logout.waitForClickable() | |
79 | await logout.click() | |
80 | ||
81 | await browser.waitUntil(() => { | |
82 | return $('.login-buttons-block, my-error-page a[href="/login"]').isDisplayed() | |
83 | }) | |
84 | } | |
85 | ||
86 | async ensureIsLoggedInAs (displayName: string) { | |
87 | await this.getLoggedInInfoElem().waitForExist() | |
88 | ||
89 | await expect(this.getLoggedInInfoElem()).toHaveText(displayName) | |
90 | } | |
91 | ||
92 | private getLoggedInInfoElem () { | |
93 | return $('.logged-in-display-name') | |
94 | } | |
95 | ||
96 | private getSuffix () { | |
97 | return browser.config.baseUrl | |
98 | ? browser.config.baseUrl.slice(-1) | |
99 | : '1' | |
100 | } | |
101 | } |