Skip to content

Commit

Permalink
Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcialRosales committed Jun 18, 2024
1 parent c2b1cde commit f762e8a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
38 changes: 19 additions & 19 deletions deps/rabbitmq_management/selenium/test/basic-auth/unauthorized.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { By, Key, until, Builder } = require('selenium-webdriver')
require('chromedriver')
const assert = require('assert')
const { buildDriver, goToHome, captureScreensFor, teardown, idpLoginPage } = require('../utils')
const { buildDriver, goToHome, captureScreensFor, teardown, delay } = require('../utils')

const SSOHomePage = require('../pageobjects/SSOHomePage')
const LoginPage = require('../pageobjects/LoginPage')
const OverviewPage = require('../pageobjects/OverviewPage')

describe('An user without management tag', function () {
Expand All @@ -15,38 +15,38 @@ describe('An user without management tag', function () {
before(async function () {
driver = buildDriver()
await goToHome(driver)
homePage = new SSOHomePage(driver)
idpLogin = idpLoginPage(driver)
login = new LoginPage(driver)
overview = new OverviewPage(driver)
captureScreen = captureScreensFor(driver, __filename)

await homePage.clickToLogin()
await idpLogin.login('rabbit_no_management', 'rabbit_no_management')
if (!await homePage.isLoaded()) {
throw new Error('Failed to login')
}
assert.ok(!await login.isPopupWarningDisplayed())
await login.login('rabbit_no_management', 'rabbit_no_management')
await !overview.isLoaded()
})

it('cannot log in into the management ui', async function () {
const visible = await homePage.isWarningVisible()
const visible = await login.isWarningVisible()
assert.ok(visible)
})

it('should get "Not authorized" warning message', async function(){
assert.equal('Not authorized', await homePage.getWarning())
//assert.equal('Click here to logout', await homePage.getLogoutButton())
//assert.ok(!await homePage.isBasicAuthSectionVisible())
//assert.ok(!await homePage.isOAuth2SectionVisible())
it('should get "Login failed" warning message', async function(){
assert.equal('Login failed', await login.getWarning())
})

describe("After clicking on logout button", function() {
it('should get popup warning dialog', async function(){
assert.ok(login.isPopupWarningDisplayed())
assert.equal('Not_Authorized', await login.getPopupWarning())
})

describe("After clicking on popup warning dialog button", function() {

before(async function () {
await homePage.clickToLogout()
await login.closePopupWarning()
})

it('should get redirected to home page again without error message', async function(){
const visible = await homePage.isWarningVisible()
it('should close popup warning', async function(){
await delay(1000)
const visible = await login.isPopupWarningDisplayed()
assert.ok(!visible)
})

Expand Down
23 changes: 18 additions & 5 deletions deps/rabbitmq_management/selenium/test/pageobjects/BasePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const EXCHANGES_TAB = By.css('div#menu ul#tabs li#exchanges')
const ADMIN_TAB = By.css('div#menu ul#tabs li#admin')
const STREAM_CONNECTIONS_TAB = By.css('div#menu ul#tabs li#stream-connections')

const FORM_POPUP = By.css('div.form-popup-warn')
const FORM_POPUP_CLOSE_BUTTON = By.css('div.form-popup-warn span')

module.exports = class BasePage {
driver
timeout
Expand Down Expand Up @@ -137,25 +140,35 @@ module.exports = class BasePage {
return table_model
}
async isPopupWarningDisplayed() {
const element = "form-popup-warn"
try {
let element = await driver.findElement(FORM_POPUP)
return element.isDisplayed()
} catch(e) {
return Promise.resolve(false)
}
/*
let element = await driver.findElement(FORM_POPUP)
return this.driver.wait(until.elementIsVisible(element), this.timeout / 2,
'Timed out after [timeout=' + this.timeout + ';polling=' + this.polling + '] awaiting till visible ' + element,
this.polling / 2).then(function onWarningVisible(e) {
return Promise.resolve(true)
}, function onError(e) {
return Promise.resolve(false)
})
*/
}
async getPopupWarning() {
const element = "form-popup-warn"
let element = await driver.findElement(FORM_POPUP)
return this.driver.wait(until.elementIsVisible(element), this.timeout,
'Timed out after [timeout=' + this.timeout + ';polling=' + this.polling + '] awaiting till visible ' + element,
this.polling)
this.polling).getText().then((value) => value.substring(0, value.search('\n\nClose')))
}
async closePopupWarning() {
return this.click(FORM_POPUP_CLOSE_BUTTON)
}

async isDisplayed(locator) {
try {
element = await driver.findElement(locator)
let element = await driver.findElement(locator)

return this.driver.wait(until.elementIsVisible(element), this.timeout,
'Timed out after [timeout=' + this.timeout + ';polling=' + this.polling + '] awaiting till visible ' + element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const FORM = By.css('div#login form')
const USERNAME = By.css('input[name="username"]')
const PASSWORD = By.css('input[name="password"]')
const LOGIN_BUTTON = By.css('div#outer div#login form input[type=submit]')
const WARNING = By.css('div#outer div#login div#login-status p')

module.exports = class LoginPage extends BasePage {
async isLoaded () {
Expand Down

0 comments on commit f762e8a

Please sign in to comment.