more test fixing

This commit is contained in:
Girish Ramakrishnan
2024-10-15 16:56:23 +02:00
parent 540e8b955a
commit 564422747a

View File

@@ -33,7 +33,6 @@ describe('Application life cycle test', function () {
const MSG_TEXT = 'Test message ';
let browser, app;
let athenticated_by_oidc = false;
before(function () {
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
@@ -59,6 +58,16 @@ describe('Application life cycle test', function () {
fs.writeFileSync(`./screenshots/${new Date().getTime()}-${this.currentTest.title.replaceAll(' ', '_')}.png`, screenshotData, 'base64');
});
async function clearCache() {
await browser.manage().deleteAllCookies();
await browser.quit();
browser = null;
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
if (process.env.CI) chromeOptions.addArguments('no-sandbox', 'disable-dev-shm-usage', 'headless');
chromeOptions.addArguments(`--user-data-dir=${await fs.promises.mkdtemp('/tmp/test-')}`); // --profile-directory=Default
browser = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
}
async function waitForElement(elem) {
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
@@ -111,7 +120,7 @@ describe('Application life cycle test', function () {
await waitForElement(By.xpath(`//h1[contains(., "Welcome")]`));
}
async function loginOIDC(username, password) {
async function loginOIDC(username, password, hasSession) {
browser.manage().deleteAllCookies();
await browser.get(`https://${app.fqdn}/#/login`);
await browser.sleep(6000);
@@ -120,22 +129,20 @@ describe('Application life cycle test', function () {
await browser.findElement(By.xpath('//div[@role="button" and contains(., "Continue with Cloudron")]')).click();
await browser.sleep(2000);
if (!athenticated_by_oidc) {
if (!hasSession) {
await waitForElement(By.xpath('//input[@name="username"]'));
await browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
await browser.sleep(2000);
await browser.findElement(By.id('loginSubmitButton')).click();
await browser.sleep(2000);
athenticated_by_oidc = true;
}
await waitForElement(By.xpath('//p[@class="confirm-trust" and contains(., "Continuing will grant ")]'));
await browser.findElement(By.xpath('//a[contains(., "Continue")]')).click();
await browser.sleep(2000);
if (await browser.findElements(By.xpath('//div[text()="Proceed with reset"]')).then(found => !!found.length)) {
if (!hasSession) {
await browser.findElement(By.xpath('//div[text()="Proceed with reset"]')).click();
await waitForElement(By.xpath('//button[text()="Continue"]'));
@@ -167,11 +174,7 @@ describe('Application life cycle test', function () {
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(PASSWORD);
await browser.findElement(By.xpath('//input[@value="Sign in"]')).click();
await browser.sleep(5000);
if (await browser.findElements(By.xpath('//div[@aria-label="Skip verification for now"]')).then(found => !!found.length)) {
await skipVerification();
}
await skipVerification();
await browser.wait(until.elementLocated(By.xpath('//span[text()="Rooms"]')), TEST_TIMEOUT);
}
@@ -263,14 +266,9 @@ describe('Application life cycle test', function () {
it('create room', createRoom);
it('can send message', sendMessage);
it('can logout', logout);
it('can login', login);
it('check room', checkRoom);
it('can logout', logout);
it('can get app info', getAppInfo);
it('uninstall element-web app', async function () {
await browser.get('about:blank');
execSync(`cloudron uninstall --app ${ELEMENT_LOCATION}`, EXEC_ARGS);
@@ -285,7 +283,7 @@ describe('Application life cycle test', function () {
it('update element-app config', updateSynapseConfig);
it('can get Element app info', getElementAppInfo);
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, false));
it('create room', createRoom);
it('can send message', sendMessage);
it('can get app info', getAppInfo);
@@ -297,7 +295,6 @@ describe('Application life cycle test', function () {
it('can get Element app info', getElementAppInfo);
it('is logged in', isLoggedIn);
it('check room', checkRoom);
it('can get app info', getAppInfo);
it('restore app', async function () {
const backups = JSON.parse(execSync(`cloudron backup list --raw --app ${app.id}`));
@@ -330,19 +327,17 @@ describe('Application life cycle test', function () {
it('update element-app config', updateSynapseConfig);
it('can get Element app info', getElementAppInfo);
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, true));
it('check room', checkRoom);
it('can send message', sendMessage);
it('can logout', logout);
it('can get app info', getAppInfo);
it('uninstall app', async function () {
await browser.get('about:blank');
execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS);
});
// test update
it('clear cache', clearCache);
it('can install app for update', function () { execSync('cloudron install --appstore-id org.matrix.synapse --location ' + LOCATION, EXEC_ARGS); });
it('can install element-web app (update)', function () { execSync('cloudron install --appstore-id im.riot.cloudronapp --location ' + ELEMENT_LOCATION, EXEC_ARGS); });
@@ -351,12 +346,11 @@ describe('Application life cycle test', function () {
it('can get Element app info', getElementAppInfo);
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, false));
it('is logged in', isLoggedIn);
it('create room', createRoom);
it('can send message', sendMessage);
it('can logout', logout);
it('can get app info', getAppInfo);
it('can update', async function () {
await browser.get('about:blank');
@@ -365,7 +359,7 @@ describe('Application life cycle test', function () {
});
it('can get Element app info', getElementAppInfo);
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, true));
it('is logged in', isLoggedIn);
it('check room', checkRoom);
it('can send message', sendMessage);