Asyncify tests

This commit is contained in:
Johannes Zellner 2021-12-16 16:56:07 +01:00
parent 9e4ea1cf4d
commit 0ce7dbe52b

View file

@ -49,107 +49,80 @@ describe('Application life cycle test', function () {
expect(app).to.be.an('object'); expect(app).to.be.an('object');
} }
function login(username, password, done) { async function waitForElement(elem) {
browser.get('https://' + app.fqdn + '/login').then(function () { await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
return browser.wait(until.elementLocated(By.id('username')), TEST_TIMEOUT); await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
}).then(function () {
return browser.findElement(By.id('username')).sendKeys(username);
}).then(function () {
return browser.findElement(By.id('password')).sendKeys(password);
}).then(function () {
return browser.findElement(By.xpath('//input[@value="Login"]')).click();
}).then(function () {
return browser.wait(until.elementLocated(By.xpath('//a[contains(@href, "/my-library")]')), TEST_TIMEOUT);
}).then(function () {
done();
});
} }
function closeAccountSetupDialog(done) { function sleep(millis) {
browser.get('https://' + app.fqdn).then(function () { return new Promise(resolve => setTimeout(resolve, millis));
return browser.wait(until.elementLocated(By.id('stopDisplayModal')), TEST_TIMEOUT);
}).then(function () {
return browser.findElement(By.xpath('//span[contains(text(), "show me this anymore")]')).click();
}).then(function () {
return browser.findElement(By.xpath('//a[contains(text(), "Set up")]')).click();
}).then(function () {
return browser.sleep(3000);
}).then(function () {
done();
});
} }
function logout(done) { async function login(username, password) {
browser.get('https://' + app.fqdn + '/my-account/videos').then(function () { await browser.get('https://' + app.fqdn + '/login');
return browser.wait(until.elementLocated(By.xpath('//div[@class="logged-in-display-name"]')), TEST_TIMEOUT);
}).then(function () { await waitForElement(By.id('username'));
return browser.sleep(2000); await browser.findElement(By.id('username')).sendKeys(username);
}).then(function () { await browser.findElement(By.id('password')).sendKeys(password);
return browser.findElement(By.xpath('//div[@class="logged-in-display-name"]')).click(); await browser.findElement(By.xpath('//input[@value="Login"]')).click();
}).then(function () { await waitForElement(By.xpath('//a[contains(@href, "/my-library")]'));
return browser.sleep(2000);
}).then(function () {
return browser.findElement(By.xpath('//a[contains(text(), "Log out")]')).click();
}).then(function () {
return browser.sleep(2000);
}).then(function () {
done();
});
} }
function completeSetup(done) { async function closeAccountSetupDialog() {
await browser.get('https://' + app.fqdn);
await waitForElement(By.id('stopDisplayModal'));
await browser.findElement(By.xpath('//span[contains(text(), "show me this anymore")]')).click();
await browser.findElement(By.xpath('//a[contains(text(), "Set up")]')).click();
await browser.sleep(3000);
}
async function logout() {
await browser.get('https://' + app.fqdn + '/my-account/videos');
await waitForElement(By.xpath('//div[@class="logged-in-display-name"]'));
await browser.sleep(2000);
await browser.findElement(By.xpath('//div[@class="logged-in-display-name"]')).click();
await browser.sleep(2000);
await browser.findElement(By.xpath('//a[contains(text(), "Log out")]')).click();
await browser.sleep(2000);
}
async function completeSetup() {
var button; var button;
browser.get('https://' + app.fqdn + '/admin/config/edit-custom').then(function () { await browser.get('https://' + app.fqdn + '/admin/config/edit-custom');
return browser.wait(until.elementLocated(By.xpath('//a[contains(text(), "Configure my instance")]')), TEST_TIMEOUT); await waitForElement(By.xpath('//a[contains(text(), "Configure my instance")]'));
}).then(function () { await browser.findElement(By.xpath('//a[contains(text(), "Configure my instance")]')).click(); // this opens a new window
return browser.findElement(By.xpath('//a[contains(text(), "Configure my instance")]')).click(); // this opens a new window
}).then(function () { await browser.get('https://' + app.fqdn + '/admin/config/edit-custom');
return browser.get('https://' + app.fqdn + '/admin/config/edit-custom'); await waitForElement(By.xpath('//input[contains(@value, "Update configuration")]'));
}).then(function () { button = await browser.findElement(By.xpath('//input[contains(@value, "Update configuration")]'));
return browser.wait(until.elementLocated(By.xpath('//input[contains(@value, "Update configuration")]')), TEST_TIMEOUT); await browser.executeScript('arguments[0].scrollIntoView(true)', button);
}).then(function () { await button.click();
button = browser.findElement(By.xpath('//input[contains(@value, "Update configuration")]')); await waitForElement(By.xpath('//h3[contains(text(), "Success")]'));
return browser.executeScript('arguments[0].scrollIntoView(true)', button);
}).then(function () { console.log('Close the newly opened tab. Will wait for 20 seconds');
return button.click(); await browser.sleep(20000);
}).then(function () {
return browser.wait(until.elementLocated(By.xpath('//h3[contains(text(), "Success")]')), TEST_TIMEOUT);
}).then(function () {
console.log('Close the newly opened tab. Will wait for 20 seconds');
return browser.sleep(20000);
}).then(function () {
done();
});
} }
function uploadVideo(done) { async function uploadVideo() {
browser.get('https://' + app.fqdn + '/videos/upload').then(function () { browser.get('https://' + app.fqdn + '/videos/upload');
return browser.findElement(By.xpath('//input[@id="videofile" and @type="file"]')).sendKeys(path.resolve(__dirname, './Cloudron Test Video.mp4')); await waitForElement(By.xpath('//input[@id="videofile" and @type="file"]'));
}).then(function () { await browser.findElement(By.xpath('//input[@id="videofile" and @type="file"]')).sendKeys(path.resolve(__dirname, './Cloudron Test Video.mp4'));
return browser.sleep(20000); // wait for upload await browser.sleep(20000); // wait for upload
}).then(function () { await browser.findElement(By.xpath('//span[text()="Publish"]')).click();
return browser.findElement(By.xpath('//span[text()="Publish"]')).click(); await browser.sleep(2000);
}).then(function () {
return browser.sleep(2000);
}).then(function () {
done();
});
} }
function videoExists(done) { async function videoExists() {
browser.get('https://' + app.fqdn + '/my-account/videos').then(function () { await browser.get('https://' + app.fqdn + '/my-account/videos');
return browser.wait(until.elementLocated(By.xpath('//a[contains(@title, "Cloudron Test Video")]')), TEST_TIMEOUT); await waitForElement(By.xpath('//a[contains(@title, "Cloudron Test Video")]'));
}).then(function () {
return done();
});
} }
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); }); xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
it('install app', async function () {
it('install app', function (done) {
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
setTimeout(done, 20000); // takes a bit to create root user in background await sleep(10000); // takes a bit to create root user in background
}); });
it('can get app information', getAppInfo); it('can get app information', getAppInfo);
@ -204,9 +177,9 @@ describe('Application life cycle test', function () {
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); }); it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
// No SSO // No SSO
it('install app (no sso)', function (done) { it('install app (no sso)', async function () {
execSync('cloudron install --no-sso --location ' + LOCATION, EXEC_ARGS); execSync('cloudron install --no-sso --location ' + LOCATION, EXEC_ARGS);
setTimeout(done, 20000); // takes a bit to create root user in background await sleep(10000); // takes a bit to create root user in background
}); });
it('can get app information', getAppInfo); it('can get app information', getAppInfo);
@ -218,9 +191,9 @@ describe('Application life cycle test', function () {
it('uninstall app (no sso)', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); }); it('uninstall app (no sso)', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
// test update // test update
it('can install app', function (done) { it('can install app', async function () {
execSync('cloudron install --appstore-id org.joinpeertube.cloudronapp --location ' + LOCATION, EXEC_ARGS); execSync('cloudron install --appstore-id org.joinpeertube.cloudronapp --location ' + LOCATION, EXEC_ARGS);
setTimeout(done, 20000); // takes a bit to create root user in background await sleep(10000); // takes a bit to create root user in background
}); });
it('can get app information', getAppInfo); it('can get app information', getAppInfo);