2022-11-08 16:41:47 +08:00
|
|
|
const { By, Key, until, Builder } = require('selenium-webdriver')
|
2022-07-01 20:57:14 +08:00
|
|
|
|
2022-11-08 16:41:47 +08:00
|
|
|
const BasePage = require('./BasePage')
|
2022-07-01 20:57:14 +08:00
|
|
|
|
2024-01-03 16:28:36 +08:00
|
|
|
const LOGIN = By.css('div#outer div#login')
|
|
|
|
const LOGOUT_BUTTON = By.css('div#outer div#login-status button#logout')
|
|
|
|
const OAUTH2_LOGIN_BUTTON = By.css('div#outer div#login button#login')
|
|
|
|
const SELECT_RESOURCES = By.css('div#outer div#login select#oauth2-resource')
|
|
|
|
const WARNING = By.css('div#outer div#login div#login-status p.warning')
|
|
|
|
|
2024-01-27 21:40:22 +08:00
|
|
|
const SECTION_LOGIN_WITH_OAUTH = By.css('div#outer div#login div#login-with-oauth2')
|
2024-01-28 02:45:16 +08:00
|
|
|
const SECTION_LOGIN_WITH_BASIC_AUTH = By.css('div#outer div#login div#login-with-basic-auth')
|
2024-01-03 16:28:36 +08:00
|
|
|
const BASIC_AUTH_LOGIN_BUTTON = By.css('form#basic-auth-form input[type=submit]')
|
|
|
|
|
|
|
|
const BASIC_AUTH_LOGIN_FORM = By.css('form#basic-auth-form')
|
|
|
|
const BASIC_AUTH_LOGIN_USERNAME = By.css('form#basic-auth-form input#username')
|
|
|
|
const BASIC_AUTH_LOGIN_PASSWORD = By.css('form#basic-auth-form input#password')
|
2022-07-01 20:57:14 +08:00
|
|
|
|
2022-08-19 00:20:39 +08:00
|
|
|
module.exports = class SSOHomePage extends BasePage {
|
2022-07-01 20:57:14 +08:00
|
|
|
async isLoaded () {
|
2024-01-03 16:28:36 +08:00
|
|
|
return this.waitForDisplayed(LOGIN)
|
2022-07-01 20:57:14 +08:00
|
|
|
}
|
2022-11-08 16:41:47 +08:00
|
|
|
|
2023-02-21 20:07:37 +08:00
|
|
|
async clickToLogin () {
|
2022-11-08 16:41:47 +08:00
|
|
|
await this.isLoaded()
|
2024-01-03 16:28:36 +08:00
|
|
|
return this.click(OAUTH2_LOGIN_BUTTON)
|
|
|
|
}
|
|
|
|
async clickToBasicAuthLogin () {
|
|
|
|
await this.isLoaded()
|
|
|
|
return this.click(BASIC_AUTH_LOGIN_BUTTON)
|
2022-07-01 20:57:14 +08:00
|
|
|
}
|
2022-11-08 16:41:47 +08:00
|
|
|
|
2024-01-03 16:28:36 +08:00
|
|
|
async clickToLogout() {
|
|
|
|
await this.isLoaded()
|
|
|
|
return this.click(LOGOUT_BUTTON)
|
|
|
|
}
|
2022-11-08 16:41:47 +08:00
|
|
|
async getLoginButton () {
|
2024-01-03 16:28:36 +08:00
|
|
|
return this.getText(OAUTH2_LOGIN_BUTTON)
|
|
|
|
}
|
|
|
|
async getLogoutButton () {
|
|
|
|
return this.getText(LOGOUT_BUTTON)
|
|
|
|
}
|
|
|
|
async getBasicAuthLoginButton () {
|
|
|
|
return this.getValue(BASIC_AUTH_LOGIN_BUTTON)
|
|
|
|
}
|
|
|
|
|
|
|
|
async chooseOauthResource(text) {
|
|
|
|
return this.selectOption(SELECT_RESOURCES, text)
|
2022-07-06 23:38:45 +08:00
|
|
|
}
|
2022-11-08 16:41:47 +08:00
|
|
|
|
2024-01-03 16:28:36 +08:00
|
|
|
async getOAuthResourceOptions () {
|
|
|
|
return this.getSelectableOptions(SELECT_RESOURCES)
|
|
|
|
}
|
2025-03-12 17:31:34 +08:00
|
|
|
async isLoginButtonNotVisible() {
|
|
|
|
return this.isElementNotVisible(OAUTH2_LOGIN_BUTTON)
|
|
|
|
}
|
2024-01-03 16:28:36 +08:00
|
|
|
async isLoginButtonVisible() {
|
|
|
|
try {
|
|
|
|
await this.waitForDisplayed(OAUTH2_LOGIN_BUTTON)
|
|
|
|
return Promise.resolve(true)
|
|
|
|
} catch (e) {
|
|
|
|
return Promise.resolve(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async isLogoutButtonVisible() {
|
|
|
|
try {
|
|
|
|
await this.waitForDisplayed(LOGOUT_BUTTON)
|
|
|
|
return Promise.resolve(true)
|
|
|
|
} catch (e) {
|
|
|
|
return Promise.resolve(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async isOAuth2SectionVisible() {
|
2024-01-28 19:02:15 +08:00
|
|
|
return this.isDisplayed(SECTION_LOGIN_WITH_OAUTH)
|
|
|
|
}
|
|
|
|
async getOAuth2Section() {
|
2024-01-28 19:12:55 +08:00
|
|
|
return this.waitForDisplayed(SECTION_LOGIN_WITH_OAUTH)
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
|
|
|
async isBasicAuthSectionVisible() {
|
2024-01-28 19:02:15 +08:00
|
|
|
return this.isDisplayed(SECTION_LOGIN_WITH_BASIC_AUTH)
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
2024-01-28 19:12:55 +08:00
|
|
|
async getBasicAuthSection() {
|
|
|
|
return this.waitForDisplayed(SECTION_LOGIN_WITH_BASIC_AUTH)
|
|
|
|
}
|
|
|
|
|
2024-01-03 16:28:36 +08:00
|
|
|
async toggleBasicAuthSection() {
|
|
|
|
await this.click(SECTION_LOGIN_WITH_BASIC_AUTH)
|
|
|
|
}
|
|
|
|
|
|
|
|
async basicAuthLogin (username, password) {
|
|
|
|
await this.isLoaded()
|
2024-11-21 23:47:48 +08:00
|
|
|
await this.waitForDisplayed(BASIC_AUTH_LOGIN_USERNAME)
|
2024-01-03 16:28:36 +08:00
|
|
|
await this.sendKeys(BASIC_AUTH_LOGIN_USERNAME, username)
|
2024-11-21 23:47:48 +08:00
|
|
|
await this.waitForDisplayed(BASIC_AUTH_LOGIN_PASSWORD)
|
2024-01-03 16:28:36 +08:00
|
|
|
await this.sendKeys(BASIC_AUTH_LOGIN_PASSWORD, password)
|
2024-11-21 23:47:48 +08:00
|
|
|
await this.waitForDisplayed(BASIC_AUTH_LOGIN_FORM)
|
2024-01-03 16:28:36 +08:00
|
|
|
return this.submit(BASIC_AUTH_LOGIN_FORM)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-08 16:41:47 +08:00
|
|
|
async isWarningVisible () {
|
|
|
|
try {
|
2023-10-31 23:31:37 +08:00
|
|
|
await this.waitForDisplayed(WARNING)
|
2022-11-08 16:41:47 +08:00
|
|
|
return Promise.resolve(true)
|
|
|
|
} catch (e) {
|
|
|
|
return Promise.resolve(false)
|
|
|
|
}
|
2022-07-01 22:34:28 +08:00
|
|
|
}
|
2024-02-10 00:22:17 +08:00
|
|
|
async getWarnings() {
|
|
|
|
try
|
|
|
|
{
|
2025-05-07 23:38:31 +08:00
|
|
|
return this.driver.findElements(WARNING)
|
2024-02-10 00:22:17 +08:00
|
|
|
} catch (NoSuchElement) {
|
|
|
|
return Promise.resolve([])
|
|
|
|
}
|
|
|
|
}
|
2022-11-08 16:41:47 +08:00
|
|
|
async getWarning () {
|
2022-07-01 22:34:28 +08:00
|
|
|
return this.getText(WARNING)
|
|
|
|
}
|
2022-07-01 20:57:14 +08:00
|
|
|
}
|