diff --git a/pom.xml b/pom.xml index 79cc81e6f9db9d9a989dd557ace84bfaca538ec9..09fcb7eb338ba211f32358f30892e804fd8f1162 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ 1.3.0 2.3.3 5.1.45 - v0.24.0 + v0.26.0 2.4.2 diff --git a/src/main/angular/package-lock.json b/src/main/angular/package-lock.json index b0ee6c6e4e6b4ab45f785810c2e6e11da5d3662a..1d3e8aef9d8c32bcab127aea03a0aa67999a2250 100644 --- a/src/main/angular/package-lock.json +++ b/src/main/angular/package-lock.json @@ -1,6 +1,6 @@ { "name": "daa-example", - "version": "0.2.0-alpha.5", + "version": "0.2.0-alpha.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/main/angular/package.json b/src/main/angular/package.json index a9322bf0088c477147c8aaec40eaa6f7b84bacef..553c5fb4bb48ba5cc2f1e061028353e309568e66 100644 --- a/src/main/angular/package.json +++ b/src/main/angular/package.json @@ -1,6 +1,6 @@ { "name": "daa-example", - "version": "0.2.0-alpha.5", + "version": "0.2.0-alpha.6", "scripts": { "ng": "./node_modules/.bin/ng", "start": "./node_modules/.bin/ng serve", diff --git a/src/main/angular/src/app/modules/people/components/people-form/people-form.component.html b/src/main/angular/src/app/modules/people/components/people-form/people-form.component.html index de89f562dc8a15136f40359c4602e78690150b6a..fed524eb5b564d2b17694efbc4e1e5f0e1fc8828 100644 --- a/src/main/angular/src/app/modules/people/components/people-form/people-form.component.html +++ b/src/main/angular/src/app/modules/people/components/people-form/people-form.component.html @@ -17,7 +17,7 @@ ~ along with this program. If not, see . --> -
+
diff --git a/src/main/angular/src/app/modules/people/components/people-list/people-list.component.html b/src/main/angular/src/app/modules/people/components/people-list/people-list.component.html index f2c06c03f6163246a35f95f7cd5c6bed77ddd6f9..2f37f4e3dbefeac56e7eb7be9ed52954e91cfbe2 100644 --- a/src/main/angular/src/app/modules/people/components/people-list/people-list.component.html +++ b/src/main/angular/src/app/modules/people/components/people-list/people-list.component.html @@ -17,7 +17,7 @@ ~ along with this program. If not, see . --> - +
@@ -26,12 +26,12 @@ - - - + + + diff --git a/src/test/java/es/uvigo/esei/daa/util/AdditionalConditions.java b/src/test/java/es/uvigo/esei/daa/util/AdditionalConditions.java deleted file mode 100644 index 68bb9225e2f3d972c3f93428ea588d0f78ebdde2..0000000000000000000000000000000000000000 --- a/src/test/java/es/uvigo/esei/daa/util/AdditionalConditions.java +++ /dev/null @@ -1,14 +0,0 @@ -package es.uvigo.esei.daa.util; - -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.support.ui.ExpectedCondition; - -/* - * Implementation based on https://stackoverflow.com/questions/33348600/selenium-wait-for-ajax-content-to-load-universal-approach - */ -public class AdditionalConditions { - public static ExpectedCondition jQueryAjaxCallsHaveCompleted() { - return driver -> - (Boolean) ((JavascriptExecutor) driver).executeScript("return (window.jQuery !== null) && (jQuery.active === 0)"); - } -} diff --git a/src/test/java/es/uvigo/esei/daa/util/JSWaiter.java b/src/test/java/es/uvigo/esei/daa/util/JSWaiter.java new file mode 100644 index 0000000000000000000000000000000000000000..619377457239f3925d40156dfa4a5a011c1587a8 --- /dev/null +++ b/src/test/java/es/uvigo/esei/daa/util/JSWaiter.java @@ -0,0 +1,67 @@ +package es.uvigo.esei.daa.util; + +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.WebDriverWait; + +/** + * Utility class to wait for several JavaScript events to complete. + * + * Code adapted from + * https://www.swtestacademy.com/selenium-wait-javascript-angular-ajax/ + */ +public class JSWaiter { + private final WebDriverWait jsWait; + private final JavascriptExecutor jsExec; + + private JSWaiter(WebDriver driver) { + this.jsWait = new WebDriverWait(driver, 10); + this.jsExec = (JavascriptExecutor) driver; + } + + public static JSWaiter wait(WebDriver driver) { + return new JSWaiter(driver); + } + + public void untilAngular5Ready() { + try { + final Object angular5Check = jsExec.executeScript("return getAllAngularRootElements()[0].attributes['ng-version']"); + if (angular5Check != null) { + final Boolean angularPageLoaded = (Boolean) jsExec + .executeScript("return window.getAllAngularTestabilities().findIndex(x=>!x.isStable()) === -1"); + if (!angularPageLoaded) { + poll(20); + + waitForAngular5Load(); + + poll(20); + } + } + } catch (WebDriverException ignored) {} + } + + private void waitForAngular5Load() { + String angularReadyScript = "return window.getAllAngularTestabilities().findIndex(x=>!x.isStable()) === -1"; + + try { + final ExpectedCondition angularLoad = driver -> Boolean + .valueOf(((JavascriptExecutor) driver).executeScript(angularReadyScript).toString()); + + final boolean angularReady = Boolean.valueOf(jsExec.executeScript(angularReadyScript).toString()); + + if (!angularReady) { + jsWait.until(angularLoad); + } + } catch (WebDriverException ignored) {} + } + + private void poll(long milis) { + try { + Thread.sleep(milis); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/es/uvigo/esei/daa/web/PeopleWebTest.java b/src/test/java/es/uvigo/esei/daa/web/PeopleWebTest.java index 81313c8bdab5129e4a6f26e11bd69c78d520fd4f..ff4371b223497e1c55aba0719769a2e569b5352f 100644 --- a/src/test/java/es/uvigo/esei/daa/web/PeopleWebTest.java +++ b/src/test/java/es/uvigo/esei/daa/web/PeopleWebTest.java @@ -25,7 +25,6 @@ import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.html5.LocalStorage; -import org.openqa.selenium.remote.DesiredCapabilities; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -71,7 +70,7 @@ public class PeopleWebTest { final FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.privatebrowsing.autostart", true); - final FirefoxOptions options = new FirefoxOptions(DesiredCapabilities.firefox()); + final FirefoxOptions options = new FirefoxOptions(); options.setProfile(profile); final FirefoxDriver firefoxDriver; @@ -84,7 +83,8 @@ public class PeopleWebTest { // Login as "admin:adminpass" final LocalStorage localStorage = firefoxDriver.getLocalStorage(); - localStorage.setItem("authorization-token", "YWRtaW46YWRtaW5wYXNz"); + // YWRtaW46YWRtaW5wYXNz + localStorage.setItem("user", "{\"login\":\"admin\",\"password\":\"adminpass\"}"); mainPage = new MainPage(driver, baseUrl); mainPage.navigateTo(); diff --git a/src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java b/src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java index 97b6a1a230a6f8135a33e1beae89b06a0d14504d..4170948fc97778693185646e526569587a054380 100644 --- a/src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java +++ b/src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java @@ -1,6 +1,5 @@ package es.uvigo.esei.daa.web.pages; -import static es.uvigo.esei.daa.util.AdditionalConditions.jQueryAjaxCallsHaveCompleted; import static java.util.stream.Collectors.toList; import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated; import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElement; @@ -14,6 +13,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.WebDriverWait; import es.uvigo.esei.daa.entities.Person; +import es.uvigo.esei.daa.util.JSWaiter; public class MainPage { private static final String TABLE_ID = "people-list"; @@ -35,9 +35,9 @@ public class MainPage { } public void navigateTo() { - this.driver.get(this.baseUrl + "main.html"); + this.driver.get(this.baseUrl + "#/people"); - this.wait.until(presenceOfElementLocated(By.id("people-list"))); + this.wait.until(presenceOfElementLocated(By.id(TABLE_ID))); } public int countPeople() { @@ -87,7 +87,7 @@ public class MainPage { table.deletePerson(id); - wait.until(jQueryAjaxCallsHaveCompleted()); + JSWaiter.wait(driver).untilAngular5Ready(); } private final static class PeopleTable { diff --git a/tomcat/server.hsqldb.xml b/tomcat/server.hsqldb.xml index 64c6e65b145665c0d694beb459e33f253d52b0a7..80afccdbb15351ae589a15d9703d568e0b24daff 100644 --- a/tomcat/server.hsqldb.xml +++ b/tomcat/server.hsqldb.xml @@ -139,9 +139,17 @@ - + userTable="users" + userNameCol="login" + userCredCol="password" + userRoleTable="users" + roleNameCol="role" + digest="SHA-256" + > + + +
Nombre
{{person.name}}{{person.surname}}
{{person.name}}{{person.surname}} - - + +