fix tests

This commit is contained in:
Girish Ramakrishnan 2022-01-21 13:40:04 -08:00
parent 6162ff540b
commit 7d38995613
3 changed files with 1645 additions and 180 deletions

1739
test/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,9 +9,9 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"chromedriver": "^93.0.1", "chromedriver": "^97.0.0",
"expect.js": "^0.3.1", "expect.js": "^0.3.1",
"mocha": "^9.1.1", "mocha": "^9.1.4",
"selenium-webdriver": "^3.6.0" "selenium-webdriver": "^4.1.1"
} }
} }

View File

@ -11,10 +11,11 @@
require('chromedriver'); require('chromedriver');
var execSync = require('child_process').execSync, const execSync = require('child_process').execSync,
expect = require('expect.js'), expect = require('expect.js'),
fs = require('fs'),
path = require('path'), path = require('path'),
{ Builder, By, Key, until } = require('selenium-webdriver'), { Builder, By, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome'); { Options } = require('selenium-webdriver/chrome');
describe('Application life cycle test', function () { describe('Application life cycle test', function () {
@ -22,29 +23,19 @@ describe('Application life cycle test', function () {
const LOCATION = 'test'; const LOCATION = 'test';
const TEST_TIMEOUT = 10000; const TEST_TIMEOUT = 10000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
const BUCKET = 'cloudrontestbucket'; const BUCKET = 'cloudrontestbucket';
const username = process.env.USERNAME; const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
const password = process.env.PASSWORD;
let browser, app; let browser, app;
before(function (done) { before(function () {
if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build(); browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
done();
}); });
after(function () { after(function () {
browser.quit(); browser.quit();
}); });
function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
}
async function waitForElement(elem) { async function waitForElement(elem) {
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT); await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT); await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
@ -61,8 +52,8 @@ describe('Application life cycle test', function () {
await waitForElement(By.id('accessKey')); await waitForElement(By.id('accessKey'));
await browser.findElement(By.id('accessKey')).sendKeys(accessKey); await browser.findElement(By.id('accessKey')).sendKeys(accessKey);
await browser.findElement(By.id('secretKey')).sendKeys(secretKey); await browser.findElement(By.id('secretKey')).sendKeys(secretKey);
await browser.findElement(By.xpath('//button[@type="submit"]/span[text()="Login"]')).click(); await browser.findElement(By.xpath('//button[contains(text(), "Login")]')).click();
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`)); await waitForElement(By.xpath('//h4[contains(text(), "Dashboard")]'));
} }
async function old_login(accessKey='minioadmin', secretKey='minioadmin') { async function old_login(accessKey='minioadmin', secretKey='minioadmin') {
@ -71,19 +62,19 @@ describe('Application life cycle test', function () {
await browser.findElement(By.id('accessKey')).sendKeys(accessKey); await browser.findElement(By.id('accessKey')).sendKeys(accessKey);
await browser.findElement(By.id('secretKey')).sendKeys(secretKey); await browser.findElement(By.id('secretKey')).sendKeys(secretKey);
await browser.findElement(By.xpath('//button[@type="submit"]')).click(); await browser.findElement(By.xpath('//button[@type="submit"]')).click();
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`)); await waitForElement(By.xpath('//input[@placeholder="Search Buckets..."]'));
} }
async function logout() { async function logout() {
await browser.get(`https://${app.fqdn}/`); await browser.get(`https://${app.fqdn}/`);
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`)); await waitForElement(By.xpath('//div/span[contains(text(), "Dashboard")]'));
await browser.findElement(By.xpath('//div/span[contains(text(), "Logout")]')).click(); await browser.findElement(By.xpath('//div/span[contains(text(), "Logout")]')).click();
await waitForElement(By.id('accessKey')); await waitForElement(By.id('accessKey'));
} }
async function old_logout() { async function old_logout() {
await browser.get(`https://${app.fqdn}/`); await browser.get(`https://${app.fqdn}/`);
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`)); await waitForElement(By.xpath('//input[@placeholder="Search Buckets..."]'));
await browser.findElement(By.xpath('//div/button[@id="top-right-menu"]')).click(); await browser.findElement(By.xpath('//div/button[@id="top-right-menu"]')).click();
await browser.findElement(By.xpath('//ul/li/a[@id="logout"]')).click(); await browser.findElement(By.xpath('//ul/li/a[@id="logout"]')).click();
await waitForElement(By.id('accessKey')); await waitForElement(By.id('accessKey'));
@ -93,17 +84,17 @@ describe('Application life cycle test', function () {
await browser.get(`https://${app.fqdn}/`); await browser.get(`https://${app.fqdn}/`);
await waitForElement(By.xpath('//div/span[contains(text(), "Bucket")]')); await waitForElement(By.xpath('//div/span[contains(text(), "Bucket")]'));
await browser.findElement(By.xpath('//div/span[contains(text(), "Bucket")]')).click(); await browser.findElement(By.xpath('//div/span[contains(text(), "Bucket")]')).click();
await waitForElement(By.xpath('//span[text()="Create Bucket"]')); await waitForElement(By.xpath('//button[text()="Create Bucket"]'));
await browser.findElement(By.xpath('//span[text()="Create Bucket"]')).click(); await browser.findElement(By.xpath('//button[text()="Create Bucket"]')).click();
await browser.sleep(2000);
await browser.findElement(By.xpath('//input[@id="bucket-name"]')).sendKeys(BUCKET); await browser.findElement(By.xpath('//input[@id="bucket-name"]')).sendKeys(BUCKET);
await browser.findElement(By.xpath('//button[@type="submit"]/span[text()="Save"]')).click(); await browser.findElement(By.xpath('//button[text()="Create Bucket"]')).click();
await waitForElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`)); await waitForElement(By.xpath(`//a[contains(text(), "${BUCKET}")]`));
await browser.findElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
} }
async function old_addBucket() { async function old_addBucket() {
await browser.get(`https://${app.fqdn}/`); await browser.get(`https://${app.fqdn}/`);
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`)); await waitForElement(By.xpath('//input[@placeholder="Search Buckets..."]'));
await browser.findElement(By.xpath('//div/button[@id="fe-action-toggle"]')).click(); await browser.findElement(By.xpath('//div/button[@id="fe-action-toggle"]')).click();
await browser.findElement(By.xpath('//ul/a[@id="show-make-bucket"]')).click(); await browser.findElement(By.xpath('//ul/a[@id="show-make-bucket"]')).click();
await browser.findElement(By.xpath('//input[@placeholder="Bucket Name"]')).sendKeys(BUCKET); await browser.findElement(By.xpath('//input[@placeholder="Bucket Name"]')).sendKeys(BUCKET);
@ -112,33 +103,8 @@ describe('Application life cycle test', function () {
} }
async function checkBucket() { async function checkBucket() {
await browser.get(`https://${app.fqdn}/`); await browser.get(`https://${app.fqdn}/buckets`);
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`)); await waitForElement(By.xpath(`//h1[contains(text(), "${BUCKET}")]`));
await browser.findElement(By.xpath('//div/span[contains(text(), "Bucket")]')).click();
await waitForElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
await browser.findElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
}
async function old_checkBucket() {
await browser.get(`https://${app.fqdn}/`);
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
await waitForElement(By.xpath(`//*[@class="main"]/a[text()="${BUCKET}"]`));
}
async function openSettings() {
await browser.get(`https://${app.fqdn}/`);
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
await browser.findElement(By.xpath('//div/span[contains(text(), "Account")]')).click();
await waitForElement(By.xpath(`//button/span[text()="Change Password"]`));
await browser.findElement(By.xpath('//button/span[text()="Change Password"]'));
}
async function old_openSettings() {
await browser.get(`https://${app.fqdn}/`);
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
await browser.findElement(By.xpath('//div/button[@id="top-right-menu"]')).click();
await waitForElement(By.xpath('//ul/li/a[contains(text(), "Change Password")]'));
await browser.findElement(By.xpath('//ul/li/a[contains(text(), "Change Password")]'));
} }
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); }); xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
@ -148,11 +114,16 @@ describe('Application life cycle test', function () {
it('can login', login.bind(null, 'minioadmin', 'minioadmin')); it('can login', login.bind(null, 'minioadmin', 'minioadmin'));
it('can add bucket', addBucket); it('can add bucket', addBucket);
it('can open settings', openSettings);
it('can logout', logout); it('can logout', logout);
it('can change credentials', function () { it('can change credentials', function () {
execSync(`cloudron exec --app ${app.id} -- /app/code/minio-credentials set minioakey minioskey`, EXEC_ARGS); let data = fs.readFileSync(path.join(__dirname, '../env.sh'), 'utf8');
data = data
.replace(/MINIO_ROOT_USER=.*/, 'MINIO_ROOT_USER=minioakey')
.replace(/MINIO_ROOT_PASSWORD=.*/, 'MINIO_ROOT_PASSWORD=minioskey');
fs.writeFileSync('/tmp/env.sh', data);
execSync(`cloudron push --app ${app.id} /tmp/env.sh /app/data/env.sh`, EXEC_ARGS);
execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS);
}); });
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); }); it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
@ -172,7 +143,6 @@ describe('Application life cycle test', function () {
it('can login', login.bind(null, 'minioakey', 'minioskey')); it('can login', login.bind(null, 'minioakey', 'minioskey'));
it('has bucket', checkBucket); it('has bucket', checkBucket);
it('can open settings', openSettings);
it('can logout', logout); it('can logout', logout);
it('move to different location', function () { it('move to different location', function () {