aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/po/login.po.ts
blob: 2c4561b7de08853f9247fca54d6ec50be24ed3fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { go } from '../utils'

export class LoginPage {

  async loginAsRootUser () {
    await go('/login')

    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('root')
    await $('input#password').setValue('test' + this.getSuffix())

    await browser.pause(1000)

    await $('form input[type=submit]').click()

    await this.ensureIsLoggedInAs('root')
  }

  async logout () {
    await $('.logged-in-more').click()

    const logout = () => $('.dropdown-item*=Log out')

    await logout().waitForDisplayed()
    await logout().click()

    await $('.login-buttons-block').waitForDisplayed()
  }

  async ensureIsLoggedInAs (displayName: string) {
    await this.getLoggedInInfoElem().waitForExist()

    await expect(this.getLoggedInInfoElem()).toHaveText(displayName)
  }

  private getLoggedInInfoElem () {
    return $('.logged-in-display-name')
  }

  private getSuffix () {
    return browser.config.baseUrl
      ? browser.config.baseUrl.slice(-1)
      : '1'
  }
}