Test with selenium export/import definitions

This commit is contained in:
Marcial Rosales 2022-12-15 20:09:17 +01:00 committed by Michael Klishin
parent bf172af236
commit 36728042ec
No known key found for this signature in database
GPG Key ID: FF4F6501646A9C9A
8 changed files with 166 additions and 4 deletions

View File

@ -303,7 +303,7 @@
</div>
<% } %>
<div class="section-hidden administrator-only">
<div class="section-hidden administrator-only" id="download-definitions">
<h2>Export definitions</h2>
<div class="hider">
<table class="two-col-layout">
@ -340,10 +340,10 @@
</div>
</div>
<div class="section-hidden administrator-only">
<div class="section-hidden administrator-only" id="upload-definitions">
<h2>Import definitions</h2>
<div class="hider">
<form method="post" enctype="multipart/form-data">
<form method="post" enctype="multipart/form-data" name="upload-definitions">
<table class="two-col-layout">
<tr>
<td>
@ -354,7 +354,7 @@
</td>
<td>
<p>
<input type="submit" value="Upload broker definitions" onclick="submit_import($(this).closest('form')[0]); return false"/>
<input type="submit" name="upload-definitions" value="Upload broker definitions" onclick="submit_import($(this).closest('form')[0]); return false"/>
<span class="help" id="import-definitions"></span>
</p>
</td>

View File

@ -0,0 +1,14 @@
.ONESHELL:# single shell invocation for all lines in the recipe
SHELL = bash# we depend on bash expansion for e.g. queue patterns
.DEFAULT_GOAL = help
RABBITMQ_SERVER_ROOT = ../../../../../
### TARGETS ###
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
test: ## Run tests interactively e.g. make test [TEST=landing.js]
@(RABBITMQ_URL=http://localhost:15672 RUN_LOCAL=true SCREENSHOTS_DIR=${PWD}/../../screens npm test $(PWD)/$(TEST))

View File

@ -0,0 +1,35 @@
const { By, Key, until, Builder } = require('selenium-webdriver')
require('chromedriver')
const assert = require('assert')
const { buildDriver, goToHome, captureScreensFor, teardown, delay } = require('../utils')
const LoginPage = require('../pageobjects/LoginPage')
const OverviewPage = require('../pageobjects/OverviewPage')
describe('Export definititions', function () {
let login
let overview
let captureScreen
before(async function () {
driver = buildDriver()
await goToHome(driver)
login = new LoginPage(driver)
overview = new OverviewPage(driver)
captureScreen = captureScreensFor(driver, __filename)
await login.login('guest', 'guest')
if (!await overview.isLoaded()) {
throw new Error('Failed to login')
}
})
it('is allowed to administrator users on all vhosts', async function () {
await overview.downloadBrokerDefinitions("definitions.json")
})
after(async function () {
await teardown(driver, this, captureScreen)
})
})

View File

@ -0,0 +1,5 @@
{
"users":[
{"name":"newguest","password_hash":"u54HZFjQzZZwMZV+yMgoWJKMkG9AVm/DE1iGtn5at8mFscQC","hashing_algorithm":"rabbit_password_hashing_sha256","tags":["management"]}
]
}

View File

@ -0,0 +1,36 @@
const { By, Key, until, Builder } = require('selenium-webdriver')
require('chromedriver')
const assert = require('assert')
const { buildDriver, goToHome, captureScreensFor, teardown, delay } = require('../utils')
const LoginPage = require('../pageobjects/LoginPage')
const OverviewPage = require('../pageobjects/OverviewPage')
describe('Import definititions', function () {
let login
let overview
let captureScreen
before(async function () {
driver = buildDriver()
await goToHome(driver)
login = new LoginPage(driver)
overview = new OverviewPage(driver)
captureScreen = captureScreensFor(driver, __filename)
await login.login('guest', 'guest')
if (!await overview.isLoaded()) {
throw new Error('Failed to login')
}
})
it('is allowed to administrator users', async function () {
let message = await overview.uploadBrokerDefinitions(process.cwd() + "/test/definitions/import-newguest-user.json")
assert.equal(true, message.indexOf('Your definitions were imported successfully.') !== -1)
})
after(async function () {
await teardown(driver, this, captureScreen)
})
})

View File

@ -0,0 +1,14 @@
const { By, Key, until, Builder } = require('selenium-webdriver')
const OverviewPage = require('./OverviewPage')
module.exports = class AdminTab extends OverviewPage {
async isLoaded () {
await this.waitForDisplayed(ADMIN_TAB)
}
async hasUser (user) {
}
}

View File

@ -105,6 +105,7 @@ module.exports = class BasePage {
await element.clear()
return element.sendKeys(keys)
} catch (err) {
console.log(err)
if (retries === 0) {
throw new Error(`Unable to send keys to ${locator.toString()} after maximum retries, error : ${err.message}`)
}
@ -113,6 +114,36 @@ module.exports = class BasePage {
}
}
async chooseFile (locator, file, retries = 1) {
try {
const element = await this.driver.findElement(locator)
return element.sendKeys(file)
} catch (err) {
console.log(err)
if (retries === 0) {
throw new Error(`Unable to send keys to ${locator.toString()} after maximum retries, error : ${err.message}`)
}
await this.driver.sleep(250)
return this.chooseFile(locator, file, retries - 1)
}
}
async acceptAlert (retries = 3) {
try {
await this.driver.wait(until.alertIsPresent());
await this.driver.sleep(250)
let alert = await this.driver.switchTo().alert();
await this.driver.sleep(250)
return alert.accept();
} catch (err) {
console.log(err)
if (retries === 0) {
throw new Error(`Unable to send keys to ${locator.toString()} after maximum retries, error : ${err.message}`)
}
await this.driver.sleep(250)
return this.alertAccept(retries - 1)
}
}
capture () {
this.driver.takeScreenshot().then(
function (image) {

View File

@ -11,6 +11,15 @@ const CHANNELS_TAB = By.css('div#menu ul#tabs li a[href="#/channels"]')
const QUEUES_TAB = By.css('div#menu ul#tabs li a[href="#/queues"]')
const ADMIN_TAB = By.css('div#menu ul#tabs li a[href="#/users"]')
const UPLOAD_DEFINITIONS_SECTION = By.css('div#upload-definitions')
const CHOOSE_BROKER_UPLOAD_FILE = By.css('input[name="file"]')
const UPLOAD_BROKER_FILE = By.css('input[type=submit][name="upload-definitions"]')
const POP_UP = By.css('div.form-popup-info')
const DOWNLOAD_DEFINITIONS_SECTION = By.css('div#download-definitions')
const CHOOSE_BROKER_DOWNLOAD_FILE = By.css('input#download-filename')
const DOWNLOAD_BROKER_FILE = By.css('button#upload-definitions')
module.exports = class OverviewPage extends BasePage {
async isLoaded () {
return await this.waitForDisplayed(MENU_TABS)
@ -39,4 +48,22 @@ module.exports = class OverviewPage extends BasePage {
async clickOnQueuesTab () {
return this.click(QUEUES_TAB)
}
async uploadBrokerDefinitions(file) {
await this.click(UPLOAD_DEFINITIONS_SECTION)
await this.chooseFile(CHOOSE_BROKER_UPLOAD_FILE, file)
await this.driver.sleep(1000)
await this.click(UPLOAD_BROKER_FILE)
await this.acceptAlert()
let popup = await this.waitForDisplayed(POP_UP)
await this.click(POP_UP)
return popup.getText()
}
async downloadBrokerDefinitions(filename) {
await this.click(DOWNLOAD_DEFINITIONS_SECTION)
await this.driver.sleep(1000)
await this.sendKeys(CHOOSE_BROKER_DOWNLOAD_FILE, filename)
await this.click(DOWNLOAD_BROKER_FILE)
return driver.sleep(5000);
}
}