diff --git a/test/test.js b/test/test.js index 6c9c010..37d274e 100644 --- a/test/test.js +++ b/test/test.js @@ -119,7 +119,7 @@ describe('Application life cycle test', function () { await waitForElement(By.xpath(`//h1[contains(., "Welcome")]`)); } - async function loginOIDC(username, password, alreadyAuthenticated, proceedWithReset) { + async function loginOIDCOld(username, password, alreadyAuthenticated, proceedWithReset) { await browser.get(`https://${elementApp.fqdn}/#/login`); await browser.sleep(2000); @@ -191,6 +191,72 @@ describe('Application life cycle test', function () { await waitForElement(By.xpath(`//h1[contains(., "Welcome")]`)); } + async function loginOIDC(username, password, alreadyAuthenticated, proceedWithReset) { + await browser.get(`https://${elementApp.fqdn}/#/login`); + await browser.sleep(2000); + + await waitForElement(By.css('.mx_Dropdown_arrow')); + await browser.findElement(By.css('.mx_Dropdown_arrow')).click(); + await waitForElement(By.id('mx_LanguageDropdown__en')); + await browser.findElement(By.id('mx_LanguageDropdown__en')).click(); + await browser.sleep(3000); + + await waitForElement(By.xpath('//div[@role="button" and contains(., "Continue with")]')); + await browser.findElement(By.xpath('//div[@role="button" and contains(., "Continue with")]')).click(); + if (!alreadyAuthenticated) { + await waitForElement(By.id('inputUsername')); + await browser.findElement(By.id('inputUsername')).sendKeys(username); + await browser.findElement(By.id('inputPassword')).sendKeys(password); + await browser.findElement(By.id('loginSubmitButton')).click(); + } + + await waitForElement(By.xpath('//p[@class="confirm-trust" and contains(., "Continuing will grant ")]')); + await browser.findElement(By.xpath('//a[contains(., "Continue")]')).click(); + + if (proceedWithReset) { + await waitForElement(By.xpath('//h2[text()="Confirm your identity"]')); + + await waitForElement(By.xpath('//button[text()="Can\'t confirm?"]')); + await browser.findElement(By.xpath('//button[text()="Can\'t confirm?"]')).click(); + + await waitForElement(By.xpath('//button[text()="Continue"]')); + await browser.findElement(By.xpath('//button[text()="Continue"]')).click(); + + await waitForElement(By.xpath('//button[text()="Done"] | //div[text()="Single Sign On"]')); + + if (await browser.findElements(By.xpath('//div[text()="Single Sign On"]')).then(found => !!found.length)) { + + await browser.findElement(By.xpath('//div[text()="Single Sign On"]')).click(); + + const originalWindowHandle = await browser.getWindowHandle(); + await browser.wait(async () => (await browser.getAllWindowHandles()).length === 2, 10000); + //Loop through until we find a new window handle + const windows = await browser.getAllWindowHandles(); + windows.forEach(async handle => { + if (handle !== originalWindowHandle) { + await browser.switchTo().window(handle); + } + }); + await waitForElement(By.xpath('//a[contains(., "Continue with")]')); + await browser.findElement(By.xpath('//a[contains(., "Continue with")]')).click(); + + // switch back to the main window + await browser.switchTo().window(originalWindowHandle); + + await waitForElement(By.xpath('//div[text()="Confirm"]')); + await browser.findElement(By.xpath('//div[text()="Confirm"]')).click(); + } + + await waitForElement(By.xpath('//div[text()="Cancel"] | //h1[contains(., "Welcome")]')); + if (await browser.findElements(By.xpath('//div[text()="Cancel"]')).then(found => !!found.length)) { + await browser.findElement(By.xpath('//div[text()="Cancel"]')).click(); + } + } + + await browser.sleep(3000); + await waitForElement(By.xpath(`//h1[contains(., "Welcome")]`)); + } + async function login() { await browser.get(`https://${elementApp.fqdn}/#/login`); await browser.wait(until.elementLocated(By.xpath('//input[@value="Sign in"]')), TEST_TIMEOUT); @@ -199,7 +265,7 @@ describe('Application life cycle test', function () { await browser.findElement(By.xpath('//input[@value="Sign in"]')).click(); await browser.sleep(5000); await skipVerification(); - await browser.wait(until.elementLocated(By.xpath('//span[text()="Rooms"]')), TEST_TIMEOUT); + await browser.wait(until.elementLocated(By.xpath('//h1[contains(., "Welcome")] | //span[text()="Rooms"]')), TEST_TIMEOUT); } async function skipVerification() { @@ -233,7 +299,7 @@ describe('Application life cycle test', function () { async function isLoggedIn() { await browser.get(`https://${elementApp.fqdn}/#/home`); - await browser.wait(until.elementLocated(By.xpath('//span[text()="Rooms"]')), TEST_TIMEOUT); + await browser.wait(until.elementLocated(By.xpath('//h1[contains(., "Welcome")] | //span[text()="Rooms"]')), TEST_TIMEOUT); } xit('build app', function () { execSync('cloudron build', EXEC_ARGS); }); @@ -323,7 +389,8 @@ describe('Application life cycle test', function () { it('can get Element app info', getElementAppInfo); it('update element-app config', updateSynapseConfig); - it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, false, false)); + it('can login via OIDC', loginOIDCOld.bind(null, USERNAME, PASSWORD, false, false)); + it('is logged in', isLoggedIn); it('can logout', logout); it('clear cache', clearCache);