Improve how to look for elements and wait for them
This commit is contained in:
parent
fe1b7cb17a
commit
89ee77e5ec
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
|
||||
<form action="<%= url %>" method="POST">
|
||||
<form action="<%= url %>" id="login_form" method="POST">
|
||||
<input type="hidden" name="access_token" value="<%= access_token %>">
|
||||
<input type="submit" value="<%= name %>">
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -52,12 +52,17 @@ kill_container_if_exist() {
|
|||
docker stop $1 &> /dev/null || true && docker rm $1 &> /dev/null || true
|
||||
}
|
||||
wait_for_message() {
|
||||
attemps_left=10
|
||||
while ! docker logs $1 | grep -q "$2";
|
||||
do
|
||||
sleep 5
|
||||
echo "Waiting 5sec for $1 to start ..."
|
||||
echo "Waiting 5sec for $1 to start ($attemps_left attempts left )..."
|
||||
((attemps_left--))
|
||||
if [[ "$attemps_left" -lt 1 ]]; then
|
||||
echo "Timed out waiting"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
init_rabbitmq() {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,8 @@ describe('An internal user with administrator tag', function () {
|
|||
})
|
||||
|
||||
it('can log in into the management ui', async function () {
|
||||
await login.login('guest', 'guest')
|
||||
if (!await overview.isLoaded()) {
|
||||
throw new Error('Failed to login')
|
||||
}
|
||||
await login.login('guest', 'guest')
|
||||
await overview.isLoaded()
|
||||
assert.equal(await overview.getUser(), 'User guest')
|
||||
})
|
||||
|
||||
|
|
|
|||
30
deps/rabbitmq_management/selenium/test/oauth/rabbitmq-idp-initiated-localhost.config
vendored
Normal file
30
deps/rabbitmq_management/selenium/test/oauth/rabbitmq-idp-initiated-localhost.config
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
[
|
||||
{rabbit, [
|
||||
{auth_backends, [rabbit_auth_backend_oauth2]}
|
||||
]},
|
||||
{rabbitmq_management, [
|
||||
{login_session_timeout, 1}, %% in minutes
|
||||
{oauth_enabled, true},
|
||||
{oauth_initiated_logon_type, idp_initiated},
|
||||
{oauth_provider_url, "http://localhost:3000"}
|
||||
]},
|
||||
{rabbitmq_auth_backend_oauth2, [
|
||||
{resource_server_id, <<"rabbitmq">>},
|
||||
{preferred_username_claims, [<<"user_name">>]},
|
||||
{key_config, [
|
||||
{default_key, <<"legacy-token-key">>},
|
||||
{signing_keys,
|
||||
#{<<"legacy-token-key">> => {pem, <<"-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2dP+vRn+Kj+S/oGd49kq
|
||||
6+CKNAduCC1raLfTH7B3qjmZYm45yDl+XmgK9CNmHXkho9qvmhdksdzDVsdeDlhK
|
||||
IdcIWadhqDzdtn1hj/22iUwrhH0bd475hlKcsiZ+oy/sdgGgAzvmmTQmdMqEXqV2
|
||||
B9q9KFBmo4Ahh/6+d4wM1rH9kxl0RvMAKLe+daoIHIjok8hCO4cKQQEw/ErBe4SF
|
||||
2cr3wQwCfF1qVu4eAVNVfxfy/uEvG3Q7x005P3TcK+QcYgJxav3lictSi5dyWLgG
|
||||
QAvkknWitpRK8KVLypEj5WKej6CF8nq30utn15FQg0JkHoqzwiCqqeen8GIPteI7
|
||||
VwIDAQAB
|
||||
-----END PUBLIC KEY-----">>}
|
||||
}
|
||||
}]
|
||||
}
|
||||
]}
|
||||
].
|
||||
|
|
@ -2,148 +2,67 @@ const { By, Key, until, Builder } = require('selenium-webdriver')
|
|||
|
||||
module.exports = class BasePage {
|
||||
driver
|
||||
timeout
|
||||
polling
|
||||
|
||||
constructor (webdriver) {
|
||||
this.driver = webdriver
|
||||
// this is another timeout (--timeout 10000) which is the maximum test execution time
|
||||
this.timeout = parseInt(process.env.TIMEOUT) || 5000 // max time waiting to locate an element. Should be less that test timeout
|
||||
this.polling = parseInt(process.env.POLLING) || 1000 // how frequent selenium searches for an element
|
||||
}
|
||||
|
||||
async waitForLocated (locator, retries = 3) {
|
||||
try {
|
||||
await this.driver.wait(until.elementLocated(locator), 2000)
|
||||
} catch (err) {
|
||||
if (retries === 0) {
|
||||
throw new Error(`Still not able to locate element ${locator.toString()} after maximum retries, Error message: ${err.message.toString()}`)
|
||||
}
|
||||
await this.driver.sleep(250)
|
||||
return this.waitForLocated(driver, locator, retries - 1)
|
||||
}
|
||||
async waitForLocated (locator) {
|
||||
return this.driver.wait(until.elementLocated(locator), this.timeout, 'Timed out after 30 seconds', this.polling);
|
||||
}
|
||||
|
||||
async waitForVisible (locator, retries = 3) {
|
||||
try {
|
||||
const element = await this.driver.findElement(locator)
|
||||
await this.driver.wait(until.elementIsVisible(element), 2000)
|
||||
} catch (err) {
|
||||
if (retries === 0) {
|
||||
throw new Error(`Element ${locator.toString()} still not visible after maximum retries, Error message: ${err.message.toString()}`)
|
||||
}
|
||||
await this.driver.sleep(250)
|
||||
return this.waitForVisible(driver, locator, retries - 1)
|
||||
}
|
||||
async waitForVisible (element) {
|
||||
return this.driver.wait(until.elementIsVisible(element), this.timeout, 'Timed out after 30 seconds', this.polling);
|
||||
}
|
||||
|
||||
async waitForDisplayed (locator, retries = 3) {
|
||||
await this.waitForLocated(locator, retries)
|
||||
await this.waitForVisible(locator, retries)
|
||||
return this.driver.findElement(locator)
|
||||
async waitForDisplayed (locator) {
|
||||
return this.waitForVisible(await this.waitForLocated(locator))
|
||||
}
|
||||
|
||||
async hasElement (locator) {
|
||||
const count = await this.driver.findElements(locator).size()
|
||||
throw new Error('there are ' + count + ' warnings')
|
||||
return count > 0
|
||||
async getText (locator) {
|
||||
const element = await this.waitForDisplayed(locator)
|
||||
return element.getText()
|
||||
}
|
||||
|
||||
async getText (locator, retries = 1) {
|
||||
try {
|
||||
const element = await this.driver.findElement(locator)
|
||||
const text = element.getText()
|
||||
return text
|
||||
} catch (err) {
|
||||
if (retries === 0) {
|
||||
throw new Error(`Unable to get ${locator.toString()} text after maximum retries, error : ${err.message}`)
|
||||
}
|
||||
await this.driver.sleep(250)
|
||||
return this.getText(locator, retries - 1)
|
||||
}
|
||||
async getValue (locator) {
|
||||
const element = await this.waitForDisplayed(locator)
|
||||
return element.getAttribute('value')
|
||||
}
|
||||
|
||||
async getValue (locator, retries = 1) {
|
||||
try {
|
||||
const element = await this.driver.findElement(locator)
|
||||
const value = element.getAttribute('value')
|
||||
return value
|
||||
} catch (err) {
|
||||
if (retries === 0) {
|
||||
throw new Error(`Unable to get ${locator.toString()} text after maximum retries, error : ${err.message}`)
|
||||
}
|
||||
await this.driver.sleep(250)
|
||||
return this.getValue(locator, retries - 1)
|
||||
}
|
||||
async click (locator) {
|
||||
const element = await this.waitForDisplayed(locator)
|
||||
return element.click()
|
||||
}
|
||||
|
||||
async click (locator, retries = 1) {
|
||||
try {
|
||||
const element = await this.driver.findElement(locator)
|
||||
return element.click()
|
||||
} catch (err) {
|
||||
if (retries === 0) {
|
||||
throw new Error(`Still not able to click ${locator.toString()} after maximum retries, Error message: ${err.message.toString()}`)
|
||||
}
|
||||
await this.driver.sleep(250)
|
||||
return this.click(locator, retries - 1)
|
||||
}
|
||||
async submit (locator) {
|
||||
const element = await this.waitForDisplayed(locator)
|
||||
return element.submit()
|
||||
}
|
||||
|
||||
async submit (locator, retries = 1) {
|
||||
try {
|
||||
const element = await this.driver.findElement(locator)
|
||||
return element.submit()
|
||||
} catch (err) {
|
||||
if (retries === 0) {
|
||||
throw new Error(`Still not able to submit ${locator.toString()} after maximum retries, Error message: ${err.message.toString()}`)
|
||||
}
|
||||
await this.driver.sleep(250)
|
||||
return this.submit(locator, retries - 1)
|
||||
}
|
||||
async sendKeys (locator, keys) {
|
||||
const element = await this.waitForDisplayed(locator)
|
||||
await element.click()
|
||||
await element.clear()
|
||||
return element.sendKeys(keys)
|
||||
}
|
||||
|
||||
async sendKeys (locator, keys, retries = 1) {
|
||||
try {
|
||||
const element = await this.driver.findElement(locator)
|
||||
await element.click()
|
||||
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}`)
|
||||
}
|
||||
await this.driver.sleep(250)
|
||||
return this.sendKeys(locator, keys, retries - 1)
|
||||
}
|
||||
async chooseFile (locator, file) {
|
||||
const element = await this.waitForDisplayed(locator)
|
||||
var remote = require('selenium-webdriver/remote');
|
||||
driver.setFileDetector(new remote.FileDetector);
|
||||
return element.sendKeys(file)
|
||||
}
|
||||
|
||||
async chooseFile (locator, file, retries = 1) {
|
||||
try {
|
||||
const element = await this.driver.findElement(locator)
|
||||
var remote = require('selenium-webdriver/remote');
|
||||
driver.setFileDetector(new remote.FileDetector);
|
||||
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)
|
||||
}
|
||||
async acceptAlert () {
|
||||
await this.driver.wait(until.alertIsPresent(), this.timeout);
|
||||
await this.driver.sleep(250)
|
||||
let alert = await this.driver.switchTo().alert();
|
||||
await this.driver.sleep(250)
|
||||
return alert.accept();
|
||||
}
|
||||
|
||||
capture () {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const { By, Key, until, Builder } = require('selenium-webdriver')
|
|||
|
||||
const BasePage = require('./BasePage')
|
||||
|
||||
const FORM = By.css('form')
|
||||
const FORM = By.css('form#login_form')
|
||||
const FAKE_PORTAL_URL = process.env.FAKE_PORTAL_URL || 'http://localhost:3000'
|
||||
|
||||
module.exports = class FakePortalPage extends BasePage {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const { By, Key, until, Builder } = require('selenium-webdriver')
|
|||
|
||||
const BasePage = require('./BasePage')
|
||||
|
||||
const FORM = By.css('form')
|
||||
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]')
|
||||
|
|
@ -14,7 +14,6 @@ module.exports = class LoginPage extends BasePage {
|
|||
|
||||
async login (username, password) {
|
||||
await this.isLoaded()
|
||||
|
||||
await this.sendKeys(USERNAME, username)
|
||||
await this.sendKeys(PASSWORD, password)
|
||||
return this.submit(FORM)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const DOWNLOAD_BROKER_FILE = By.css('button#upload-definitions')
|
|||
|
||||
module.exports = class OverviewPage extends BasePage {
|
||||
async isLoaded () {
|
||||
return await this.waitForDisplayed(MENU_TABS)
|
||||
return this.waitForDisplayed(MENU_TABS)
|
||||
}
|
||||
|
||||
async logout () {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ module.exports = class SSOHomePage extends BasePage {
|
|||
return this.waitForDisplayed(LOGIN_BUTTON)
|
||||
}
|
||||
|
||||
async clickToLogin (username, password) {
|
||||
async clickToLogin () {
|
||||
await this.isLoaded()
|
||||
if (!await this.isWarningVisible()) {
|
||||
return this.click(LOGIN_BUTTON)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ module.exports = class VhostAdminTab extends AdminTab {
|
|||
await this.waitForDisplayed(VHOST_NAME)
|
||||
await this.waitForDisplayed(OVERVIEW_SECTION)
|
||||
await this.waitForDisplayed(PERMISSIONS_SECTION)
|
||||
return await this.waitForDisplayed(TOPIC_PERMISSIONS_SECTION)
|
||||
return this.waitForDisplayed(TOPIC_PERMISSIONS_SECTION)
|
||||
}
|
||||
|
||||
async getName() {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ module.exports = class VhostsAdminTab extends AdminTab {
|
|||
await this.click(CHECKBOX_REGEX)
|
||||
}
|
||||
await this.driver.sleep(250)
|
||||
await this.waitForDisplayed(VHOSTS_TABLE_ROWS)
|
||||
return this.driver.findElement(VHOSTS_TABLE_ROWS)
|
||||
return this.waitForDisplayed(VHOSTS_TABLE_ROWS)
|
||||
}
|
||||
async hasVhosts(vhost, regex = false) {
|
||||
return await this.searchForVhosts(vhost, regex) != undefined
|
||||
|
|
|
|||
Loading…
Reference in New Issue