diff --git a/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java b/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java index 77920136dd58df6ba98c420610e4c413ff9339f3..fdf62777ee62a7384e9a7c200ccdabc3ab421dbd 100644 --- a/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java +++ b/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java @@ -614,6 +614,9 @@ public class FunctionalArtefactTest { /* login for test setup */ Assert.assertTrue(functionalUtil.login(browser, user.getLogin(), user.getPassword(), true)); + /* create binder, page or structure if necessary */ + Assert.assertTrue(functionalEportfolioUtil.createElements(browser, TEXT_ARTEFACT_BINDER, TEXT_ARTEFACT_PAGE, TEXT_ARTEFACT_STRUCTURE)); + /* add text artefact */ Assert.assertTrue(functionalEportfolioUtil.addTextArtefact(browser, TEXT_ARTEFACT_BINDER, TEXT_ARTEFACT_PAGE, TEXT_ARTEFACT_STRUCTURE, TEXT_ARTEFACT_CONTENT, @@ -658,7 +661,10 @@ public class FunctionalArtefactTest { */ /* login for test setup */ Assert.assertTrue(functionalUtil.login(browser, user.getLogin(), user.getPassword(), true)); - + + /* create binder, page or structure if necessary */ + Assert.assertTrue(functionalEportfolioUtil.createElements(browser, FILE_ARTEFACT_BINDER, FILE_ARTEFACT_PAGE, FILE_ARTEFACT_STRUCTURE)); + /* upload file artefact */ Assert.assertTrue(functionalEportfolioUtil.uploadFileArtefact(browser, FILE_ARTEFACT_BINDER, FILE_ARTEFACT_PAGE, FILE_ARTEFACT_STRUCTURE, FunctionalArtefactTest.class.getResource(FILE_ARTEFACT_PATH).toURI(), @@ -704,6 +710,9 @@ public class FunctionalArtefactTest { /* login for test setup */ Assert.assertTrue(functionalUtil.login(browser, user.getLogin(), user.getPassword(), true)); + /* create binder, page or structure if necessary */ + Assert.assertTrue(functionalEportfolioUtil.createElements(browser, LEARNING_JOURNAL_BINDER, LEARNING_JOURNAL_PAGE, LEARNING_JOURNAL_STRUCTURE)); + /* create learning journal */ Assert.assertTrue(functionalEportfolioUtil.createLearningJournal(browser, LEARNING_JOURNAL_BINDER, LEARNING_JOURNAL_PAGE, LEARNING_JOURNAL_STRUCTURE, LEARNING_JOURNAL_TITLE, LEARNING_JOURNAL_DESCRIPTION, diff --git a/src/test/java/org/olat/util/FunctionalEPortfolioUtil.java b/src/test/java/org/olat/util/FunctionalEPortfolioUtil.java index 91f58681e2deb639a46b8b7514c70877c41a176f..599c88ae736866441656607103d10d9d86c99322 100644 --- a/src/test/java/org/olat/util/FunctionalEPortfolioUtil.java +++ b/src/test/java/org/olat/util/FunctionalEPortfolioUtil.java @@ -372,6 +372,7 @@ public class FunctionalEPortfolioUtil { .append(getCreateBinderCss()) .append("')]"); + functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString()); browser.click(selectorBuffer.toString()); functionalUtil.waitForPageToLoad(browser); @@ -510,7 +511,8 @@ public class FunctionalEPortfolioUtil { selectorBuffer.append("xpath=//a[contains(@class, '") .append(getAddLinkCss()) .append("')]"); - + + functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString()); browser.click(selectorBuffer.toString()); functionalUtil.waitForPageToLoad(browser); @@ -827,6 +829,7 @@ public class FunctionalEPortfolioUtil { selectorBuffer.append("xpath=//div[contains(@class, 'x-tool-close')]"); + functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString()); browser.click(selectorBuffer.toString()); functionalUtil.waitForPageToUnloadElement(browser, selectorBuffer.toString()); @@ -846,6 +849,8 @@ public class FunctionalEPortfolioUtil { .append(getHomePortalEditLinkCss()) .append("')]"); + functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString()); + browser.click(selectorBuffer.toString()); functionalUtil.waitForPageToLoad(browser); @@ -952,7 +957,6 @@ public class FunctionalEPortfolioUtil { /* open wizard */ openEditLink(browser); - //functionalUtil.waitForPageToLoad(browser); StringBuffer locatorBuffer = new StringBuffer(); @@ -987,7 +991,7 @@ public class FunctionalEPortfolioUtil { locatorBuffer = new StringBuffer(); - locatorBuffer.append("xpath=//li//div[contains(@class, 'x-tree-selected')]//a//span[contains(text(), '") + locatorBuffer.append("xpath=//li//div[contains(@class, 'x-tree-node')]//a//span[contains(text(), '") .append((structure != null) ? structure: page) .append("')]"); @@ -1026,14 +1030,14 @@ public class FunctionalEPortfolioUtil { /* open wizard */ openEditLink(browser); - functionalUtil.waitForPageToLoad(browser); StringBuffer locatorBuffer = new StringBuffer(); locatorBuffer.append("xpath=//a[contains(@class, '") .append(getUploadFileArtefactCss()) .append("')]"); - + + functionalUtil.waitForPageToLoadElement(browser, locatorBuffer.toString()); browser.click(locatorBuffer.toString()); functionalUtil.waitForPageToLoad(browser); @@ -1111,7 +1115,6 @@ public class FunctionalEPortfolioUtil { /* open wizard */ openEditLink(browser); - functionalUtil.waitForPageToLoad(browser); StringBuffer locatorBuffer = new StringBuffer(); @@ -1119,6 +1122,7 @@ public class FunctionalEPortfolioUtil { .append(getCreateLearningJournalCss()) .append("')]"); + functionalUtil.waitForPageToLoadElement(browser, locatorBuffer.toString()); browser.click(locatorBuffer.toString()); functionalUtil.waitForPageToLoad(browser); diff --git a/src/test/java/org/olat/util/FunctionalHomeSiteUtil.java b/src/test/java/org/olat/util/FunctionalHomeSiteUtil.java index f4002f3ea0898970731429be2cada52737c9345a..a856b2a181fab63374a3e62aa96fefe92c3f958a 100644 --- a/src/test/java/org/olat/util/FunctionalHomeSiteUtil.java +++ b/src/test/java/org/olat/util/FunctionalHomeSiteUtil.java @@ -497,6 +497,8 @@ public class FunctionalHomeSiteUtil { if(selectedCss == null) return(false); + functionalUtil.idle(browser); + StringBuffer selectorBuffer = new StringBuffer(); selectorBuffer.append("css=ul li.") @@ -515,7 +517,7 @@ public class FunctionalHomeSiteUtil { if(timeout != -1){ try { - Thread.sleep(1000); + Thread.sleep(FunctionalUtil.POLL_INTERVAL); } catch (InterruptedException e) { //TODO:JK: Auto-generated catch block e.printStackTrace(); @@ -554,7 +556,7 @@ public class FunctionalHomeSiteUtil { return(false); } - //FIXME:JK: this is a known bottleneck, but can't be set to -1 until notifications will be clicked away! + //FIXME:JK: this is a known bottleneck, but can't be set to -1 until info messages will be clicked away! if(!checkCurrentAction || !checkCurrentAction(browser, action, Long.parseLong(functionalUtil.getWaitLimit()))){ StringBuffer selectorBuffer = new StringBuffer(); diff --git a/src/test/java/org/olat/util/FunctionalUtil.java b/src/test/java/org/olat/util/FunctionalUtil.java index be4831dd2b42dd703580398f9f0495029611609d..e2bf859b670e98ab4e5274dceeddea999fd209fd 100644 --- a/src/test/java/org/olat/util/FunctionalUtil.java +++ b/src/test/java/org/olat/util/FunctionalUtil.java @@ -43,13 +43,15 @@ public class FunctionalUtil { public final static String DEPLOYMENT_URL = "http://localhost:8080/openolat"; public final static String DEPLOYMENT_PATH = "/openolat"; - public final static String WAIT_LIMIT = "5000"; public final static String LOGIN_PAGE = "dmz"; public final static String ACKNOWLEDGE_CHECKBOX = "acknowledge_checkbox"; public final static String INFO_DIALOG = "o_interceptionPopup"; + public final static long TIMEOUT = 60000; + public final static long POLL_INTERVAL = 100; + public enum WaitLimitAttribute { NORMAL("0"), EXTENDED("3000"), @@ -57,9 +59,11 @@ public class FunctionalUtil { VERY_SAVE("12000"); private String extend; + private long extendAsLong; WaitLimitAttribute(String extend){ setExtend(extend); + setExtendAsLong(Long.parseLong(extend)); } public String getExtend() { @@ -69,8 +73,19 @@ public class FunctionalUtil { public void setExtend(String extend) { this.extend = extend; } + + public long getExtendAsLong() { + return extendAsLong; + } + + public void setExtendAsLong(long extendAsLong) { + this.extendAsLong = extendAsLong; + } } + public final static WaitLimitAttribute DEFAULT_WAIT_LIMIT = WaitLimitAttribute.VERY_SAVE; + public final static String DEFAULT_IDLE = "-1"; + public enum OlatSite { HOME, GROUPS, @@ -80,7 +95,7 @@ public class FunctionalUtil { ADMINISTRATION, } - public final static String OLAT_TOP_NAVIGATION_LOGOUT_CSS = "o_topnav_logout"; + public final static String OLAT_TOP_NAVIGATION_LOGOUT_CSS = "b_logout"; public final static String OLAT_NAVIGATION_SITE_CSS = "b_nav_site"; public final static String OLAT_ACTIVE_NAVIGATION_SITE_CSS = "b_nav_active"; @@ -97,8 +112,6 @@ public class FunctionalUtil { public final static String CONTENT_TAB_CSS = "b_item_"; public final static String ACTIVE_CONTENT_TAB_CSS = "b_active"; - public final static String FORM_SAVE_XPATH = "//button[@type='button' and last()]"; - public final static String WIZARD_CSS = "b_wizard"; public final static String WIZARD_NEXT_CSS = "b_wizard_button_next"; public final static String WIZARD_FINISH_CSS = "b_wizard_button_finish"; @@ -112,7 +125,9 @@ public class FunctionalUtil { public final static String TREE_NODE_ANCHOR_CSS = "x-tree-node-anchor"; public final static String TREE_NODE_CSS = "x-tree-node"; - public final static String NOTIFICATION_BOX_CSS = "o_sel_info_message"; + public final static String FORM_SAVE_XPATH = "//button[@type='button' and last()]"; + + public final static String INFO_MESSAGE_BOX_CSS = "o_sel_info_message"; private String username; private String password; @@ -184,7 +199,7 @@ public class FunctionalUtil { deploymentUrl = DEPLOYMENT_URL; deploymentPath = DEPLOYMENT_PATH; - waitLimit = WAIT_LIMIT; + waitLimit = DEFAULT_IDLE; loginPage = LOGIN_PAGE; acknowledgeCheckbox = ACKNOWLEDGE_CHECKBOX; @@ -252,13 +267,35 @@ public class FunctionalUtil { } /** + * Is idle as long as link is busy. * * @param browser */ - public void waitForPageToLoad(Selenium browser){ - waitForPageToLoad(browser, WaitLimitAttribute.VERY_SAVE); + public void idle(Selenium browser){ + long startTime = Calendar.getInstance().getTimeInMillis(); + long currentTime = startTime; + long waitLimit = TIMEOUT; + + while(linkBusy(browser) && waitLimit > currentTime - startTime){ + try { + Thread.sleep(POLL_INTERVAL); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + currentTime = Calendar.getInstance().getTimeInMillis(); + } } + /** + * + * @param browser + */ + public void waitForPageToLoad(Selenium browser){ + waitForPageToLoad(browser, DEFAULT_WAIT_LIMIT); + } + /** * * @param browser @@ -268,8 +305,11 @@ public class FunctionalUtil { String waitLimit = Long.toString(Long.parseLong(getWaitLimit()) + Long.parseLong(wait.getExtend())); browser.waitForPageToLoad(waitLimit); + + idle(browser); } + /** * Waits at most (waitLimit + WaitLimitAttribute.VERY_SAVE) amount of time for element to load * specified by locator. @@ -281,7 +321,7 @@ public class FunctionalUtil { * @throws SeleniumException */ public boolean waitForPageToLoadElement(Selenium browser, String locator) throws SeleniumException{ - return(waitForPageToLoadElement(browser, locator, WaitLimitAttribute.VERY_SAVE, true)); + return(waitForPageToLoadElement(browser, locator, DEFAULT_WAIT_LIMIT, true)); } /** @@ -295,7 +335,7 @@ public class FunctionalUtil { * @throws SeleniumException */ public boolean waitForPageToLoadElement(Selenium browser, String locator, boolean throwException) throws SeleniumException{ - return(waitForPageToLoadElement(browser, locator, WaitLimitAttribute.VERY_SAVE, throwException)); + return(waitForPageToLoadElement(browser, locator, DEFAULT_WAIT_LIMIT, throwException)); } /** @@ -310,6 +350,8 @@ public class FunctionalUtil { * @throws SeleniumException */ public boolean waitForPageToLoadElement(Selenium browser, String locator, WaitLimitAttribute wait, boolean throwException) throws SeleniumException { + idle(browser); + long startTime = Calendar.getInstance().getTimeInMillis(); long currentTime = startTime; long waitLimit = Long.parseLong(getWaitLimit()) + Long.parseLong(wait.getExtend()); @@ -324,7 +366,7 @@ public class FunctionalUtil { } try { - Thread.sleep(1000); + Thread.sleep(POLL_INTERVAL); } catch (InterruptedException e) { e.printStackTrace(); } @@ -352,7 +394,7 @@ public class FunctionalUtil { * @throws SeleniumException */ public boolean waitForPageToUnloadElement(Selenium browser, String locator) throws SeleniumException { - return(waitForPageToUnloadElement(browser, locator, WaitLimitAttribute.VERY_SAVE, true)); + return(waitForPageToUnloadElement(browser, locator, DEFAULT_WAIT_LIMIT, true)); } /** @@ -366,7 +408,7 @@ public class FunctionalUtil { * @throws SeleniumException */ public boolean waitForPageToUnloadElement(Selenium browser, String locator, boolean throwException) throws SeleniumException { - return(waitForPageToUnloadElement(browser, locator, WaitLimitAttribute.VERY_SAVE, throwException)); + return(waitForPageToUnloadElement(browser, locator, DEFAULT_WAIT_LIMIT, throwException)); } /** @@ -381,6 +423,8 @@ public class FunctionalUtil { * @throws SeleniumException */ public boolean waitForPageToUnloadElement(Selenium browser, String locator, WaitLimitAttribute wait, boolean throwException) throws SeleniumException { + idle(browser); + long startTime = Calendar.getInstance().getTimeInMillis(); long currentTime = startTime; long waitLimit = Long.parseLong(getWaitLimit()) + Long.parseLong(wait.getExtend()); @@ -389,13 +433,13 @@ public class FunctionalUtil { do{ if(!browser.isElementPresent(locator)){ - log.info("found element after " + (currentTime - startTime) + "ms"); + log.info("didn't find element after " + (currentTime - startTime) + "ms"); return(true); } try { - Thread.sleep(1000); + Thread.sleep(POLL_INTERVAL); } catch (InterruptedException e) { e.printStackTrace(); } @@ -423,6 +467,30 @@ public class FunctionalUtil { return(browser.getEval("window.o_info.businessPath")); } + /** + * Retrieves the linkbusy JavaScript variable. + * + * @param browser + * @return + */ + public boolean linkBusy(Selenium browser){ + String val = null; + + try{ + val = browser.getEval("window.o_info.linkbusy"); + }catch(Exception e){ + log.warn("caught exception while retrieving o_info.linkbusy: assuming not busy", e); + + return(false); + } + + if(val == null || val.isEmpty()){ + return(false); + }else{ + return(Boolean.parseBoolean(val)); + } + } + /** * Find CSS mapping for specific olat site. * @@ -489,6 +557,8 @@ public class FunctionalUtil { * @return */ public boolean checkCurrentSite(Selenium browser, OlatSite site, long timeout){ + idle(browser); + String selectedCss = findCssClassOfSite(site); if(selectedCss == null){ @@ -514,7 +584,7 @@ public class FunctionalUtil { if(timeout != -1){ try { - Thread.sleep(1000); + Thread.sleep(POLL_INTERVAL); } catch (InterruptedException e) { //TODO:JK: Auto-generated catch block e.printStackTrace(); @@ -589,7 +659,7 @@ public class FunctionalUtil { return(false); } - //FIXME:JK: this is a known bottleneck, but can't be set to -1 until notifications will be clicked away! + //FIXME:JK: this is a known bottleneck, but can't be set to -1 until info messages will be clicked away! if(checkCurrentSite(browser, site, Long.parseLong(getWaitLimit()))){ if(resetSite(browser, site)){ return(true); @@ -661,7 +731,7 @@ public class FunctionalUtil { browser.type("id=o_fiooolat_login_name", username); browser.type("id=o_fiooolat_login_pass", password); browser.click("id=o_fiooolat_login_button"); - waitForPageToLoad(browser); + waitForPageToLoad(browser, DEFAULT_WAIT_LIMIT); if(closeDialogs){ /* check if it's our first login */ @@ -703,8 +773,6 @@ public class FunctionalUtil { waitForPageToLoadElement(browser, selectorBuffer.toString()); browser.click(selectorBuffer.toString()); - waitForPageToUnloadElement(browser, selectorBuffer.toString()); - return(true); } @@ -771,8 +839,9 @@ public class FunctionalUtil { .append("]") .append(getFormSaveXPath()); + waitForPageToLoadElement(browser, selectorBuffer.toString()); browser.click(selectorBuffer.toString()); - browser.waitForPageToLoad(waitLimit); + waitForPageToLoad(browser); return(true); }