From c8dc770aca80d3fcb6cb2fae89e2d2df85484f70 Mon Sep 17 00:00:00 2001
From: jkraehemann <none@none>
Date: Mon, 3 Sep 2012 16:09:52 +0200
Subject: [PATCH] OO-296: Site access timeouts sooner to speed up test case.
 Enhanced waiting for AJAX content.

---
 .../org/olat/login/FunctionalLoginTest.java   |  2 +-
 .../org/olat/login/FunctionalResumeTest.java  |  2 +-
 .../olat/portal/FunctionalSettingsTest.java   |  8 +-
 .../portfolio/FunctionalArtefactTest.java     | 65 +++++++++------
 .../util/EPortfolioTOCStructurePosition.vm    |  6 +-
 .../org/olat/util/FunctionalCourseUtil.java   | 29 ++++---
 .../olat/util/FunctionalEPortfolioUtil.java   | 68 ++++++++--------
 .../org/olat/util/FunctionalHomeSiteUtil.java | 20 ++---
 .../util/FunctionalRepositorySiteUtil.java    | 13 +--
 .../java/org/olat/util/FunctionalUtil.java    | 70 +++++++++++++---
 .../java/org/olat/util/FunctionalVOUtil.java  | 79 ++++++++++++++++---
 11 files changed, 249 insertions(+), 113 deletions(-)

diff --git a/src/test/java/org/olat/login/FunctionalLoginTest.java b/src/test/java/org/olat/login/FunctionalLoginTest.java
index edb043dfb36..320d966b066 100644
--- a/src/test/java/org/olat/login/FunctionalLoginTest.java
+++ b/src/test/java/org/olat/login/FunctionalLoginTest.java
@@ -105,7 +105,7 @@ public class FunctionalLoginTest {
 		browser.type("id=o_fiooolat_login_name", "administrator");
 		browser.type("id=o_fiooolat_login_pass", "openolat");
 		browser.click("id=o_fiooolat_login_button");
-		browser.waitForPageToLoad("15000");
+		functionalUtil.waitForPageToLoad(browser);
 
 		//check if administrator appears in the footer
 		boolean loginAs = browser.isElementPresent("xpath=//div[@id='b_footer_user']//i[contains(text(), 'administrator')]");
diff --git a/src/test/java/org/olat/login/FunctionalResumeTest.java b/src/test/java/org/olat/login/FunctionalResumeTest.java
index 74c4545c125..8830bc0503c 100644
--- a/src/test/java/org/olat/login/FunctionalResumeTest.java
+++ b/src/test/java/org/olat/login/FunctionalResumeTest.java
@@ -142,7 +142,7 @@ public class FunctionalResumeTest {
 		
 		/* Yes to resume last session */
 		browser.click("xpath=//form//button");
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* check if we are on open course tab */
 		Assert.assertTrue(browser.isElementPresent(courseXPath));
diff --git a/src/test/java/org/olat/portal/FunctionalSettingsTest.java b/src/test/java/org/olat/portal/FunctionalSettingsTest.java
index 14454412372..22ec1f69a2f 100644
--- a/src/test/java/org/olat/portal/FunctionalSettingsTest.java
+++ b/src/test/java/org/olat/portal/FunctionalSettingsTest.java
@@ -200,7 +200,7 @@ public class FunctionalSettingsTest {
 		for(i = 0; i < pages.size(); i++){
 			browser.click(keys[i]);
 			
-			browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+			functionalUtil.waitForPageToLoad(browser);
 			functionalUtil.waitForPageToLoadElement(browser, values[i]);
 		}
 		
@@ -214,7 +214,7 @@ public class FunctionalSettingsTest {
 		for(; i >= 0; i--){
 			browser.goBack();
 
-			browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+			functionalUtil.waitForPageToLoad(browser);
 			functionalUtil.waitForPageToLoadElement(browser, values[i]);
 			
 			Assert.assertTrue(browser.isElementPresent(values[i]));
@@ -345,7 +345,7 @@ public class FunctionalSettingsTest {
 		for(i = 0; i < pages.size(); i++){
 			browser.click(keys[i]);
 			
-			browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+			functionalUtil.waitForPageToLoad(browser);
 			functionalUtil.waitForPageToLoadElement(browser, values[i]);
 		}
 		
@@ -359,7 +359,7 @@ public class FunctionalSettingsTest {
 		for(; i >= 0; i--){
 			browser.goBack();
 
-			browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+			functionalUtil.waitForPageToLoad(browser);
 			functionalUtil.waitForPageToLoadElement(browser, values[i]);
 			
 			Assert.assertTrue(browser.isElementPresent(values[i]));
diff --git a/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java b/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java
index 0d2d7b44f12..e15b60ee8ec 100644
--- a/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java
+++ b/src/test/java/org/olat/portfolio/FunctionalArtefactTest.java
@@ -33,7 +33,6 @@ import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.olat.restapi.support.vo.CourseVO;
@@ -122,44 +121,58 @@ public class FunctionalArtefactTest {
 	@ArquillianResource
 	URL deploymentUrl;
 
-	FunctionalUtil functionalUtil;
-	FunctionalHomeSiteUtil functionalHomeSiteUtil;
-	FunctionalRepositorySiteUtil functionalRepositorySiteUtil;
-	FunctionalCourseUtil functionalCourseUtil;
-	FunctionalEPortfolioUtil functionalEportfolioUtil;
-	FunctionalVOUtil functionalVOUtil;
+	static FunctionalUtil functionalUtil;
+	static FunctionalHomeSiteUtil functionalHomeSiteUtil;
+	static FunctionalRepositorySiteUtil functionalRepositorySiteUtil;
+	static FunctionalCourseUtil functionalCourseUtil;
+	static FunctionalEPortfolioUtil functionalEportfolioUtil;
+	static FunctionalVOUtil functionalVOUtil;
 	
-	UserVO user;
+	static UserVO user;
+	
+	static boolean initialized = false;
 	
 	@Before
 	public void setup() throws IOException, URISyntaxException{
-		functionalUtil = new FunctionalUtil();
-		functionalUtil.setDeploymentUrl(deploymentUrl.toString());
-		functionalHomeSiteUtil = new FunctionalHomeSiteUtil(functionalUtil);
+		if(!initialized){
+			functionalUtil = new FunctionalUtil();
+			functionalUtil.setDeploymentUrl(deploymentUrl.toString());
+			functionalHomeSiteUtil = new FunctionalHomeSiteUtil(functionalUtil);
 
-		functionalRepositorySiteUtil = new FunctionalRepositorySiteUtil(functionalUtil);
-		functionalCourseUtil = new FunctionalCourseUtil(functionalUtil, functionalRepositorySiteUtil);
-		functionalEportfolioUtil = new FunctionalEPortfolioUtil(functionalUtil, functionalHomeSiteUtil);
-		
-		functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword());
-		
-		/* create test user with REST */
-		List<UserVO> userVO = functionalVOUtil.createTestUsers(deploymentUrl, 1);
-		
-		user = userVO.get(0);
+			functionalRepositorySiteUtil = new FunctionalRepositorySiteUtil(functionalUtil);
+			functionalCourseUtil = new FunctionalCourseUtil(functionalUtil, functionalRepositorySiteUtil);
+			functionalEportfolioUtil = new FunctionalEPortfolioUtil(functionalUtil, functionalHomeSiteUtil);
+
+			functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword());
+
+			/* create test user with REST */
+			List<UserVO> userVO = functionalVOUtil.createTestUsers(deploymentUrl, 1);
+
+			user = userVO.get(0);
+			
+			initialized = true;
+		}
 	}
 	
 	@Test
 	@RunAsClient
 	public void checkCollectForumPost() throws IOException, URISyntaxException{
 		/* deploy course with REST */
-		CourseVO course = functionalVOUtil.importAllElementsCourse(deploymentUrl);
+		CourseVO course = functionalVOUtil.importCourseIncludingForum(deploymentUrl);
 		
 		/* 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, FORUM_BINDER, FORUM_PAGE, FORUM_STRUCTURE));
+
+		//FIXME:JK: really ugly
+		try {
+			Thread.sleep(500);
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 		
 		/* post message to forum */
 		Assert.assertTrue(functionalCourseUtil.postForumMessage(browser, course.getRepoEntryKey(), 0, FORUM_POST_TITLE, FORUM_POST_MESSAGE));
@@ -182,6 +195,14 @@ public class FunctionalArtefactTest {
 		/* create binder, page or structure if necessary */
 		Assert.assertTrue(functionalEportfolioUtil.createElements(browser, WIKI_BINDER, WIKI_PAGE, WIKI_STRUCTURE));
 		
+		//FIXME:JK: really ugly
+		try {
+			Thread.sleep(500);
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
 		/* create an article for the wiki */
 		Assert.assertTrue(functionalCourseUtil.createWikiArticle(browser, vo.getKey(), WIKI_ARTICLE_PAGENAME, WIKI_ARTICLE_CONTENT));
 		
diff --git a/src/test/java/org/olat/util/EPortfolioTOCStructurePosition.vm b/src/test/java/org/olat/util/EPortfolioTOCStructurePosition.vm
index 536c9a8dbc0..ae980887f2a 100644
--- a/src/test/java/org/olat/util/EPortfolioTOCStructurePosition.vm
+++ b/src/test/java/org/olat/util/EPortfolioTOCStructurePosition.vm
@@ -7,13 +7,13 @@ if(document.querySelector){
     var page = "${page}";
     var structure = "${structure}";
     
-    var selection = window.document.querySelectorAll(selector);
+    var selection = window.document.evaluate(selector, window.document.body, null, XPathResult.ANY_TYPE, null);
     
     for(i = 0; i < selection.length; i++){
         var current = selection.item(i);
         
         if(current.className.indexOf(level1) >= 0){
-            var currentPage = window.document.evaluate('//a//span[contains(text(), \'' + page + '\')]', current, null, XPathResult.ANY_TYPE, null);
+            var currentPage = window.document.evaluate("//a//span[text()=\'" + page + "\']", current, null, XPathResult.ANY_TYPE, null);
             
             if(currentPage != null){
                 current = selection.item(i + 1);
@@ -21,7 +21,7 @@ if(document.querySelector){
                 for(j = 0; current.className.indexOf(level2) >= 0; j++){
                     current = selection.item(i + 1 + j);
                     
-                    var currentStructure = window.document.evaluate('//a//span[contains(text(), \'' + structure + '\')]', current, null, XPathResult.ANY_TYPE, null);
+                    var currentStructure = window.document.evaluate("//a//span[text()=\'" + structure + "\']", current, null, XPathResult.ANY_TYPE, null);
                     
                     if(currentStructure != null){
                         position = i + 1 + j;
diff --git a/src/test/java/org/olat/util/FunctionalCourseUtil.java b/src/test/java/org/olat/util/FunctionalCourseUtil.java
index 96eb29d0ba7..d2220f4c7d6 100644
--- a/src/test/java/org/olat/util/FunctionalCourseUtil.java
+++ b/src/test/java/org/olat/util/FunctionalCourseUtil.java
@@ -19,6 +19,8 @@
  */
 package org.olat.util;
 
+import org.olat.util.FunctionalUtil.WaitLimitAttribute;
+
 import com.thoughtworks.selenium.Selenium;
 
 /**
@@ -153,7 +155,7 @@ public class FunctionalCourseUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		if(binder != null){
 			/* fill in wizard - title & description */
@@ -171,6 +173,8 @@ public class FunctionalCourseUtil {
 			
 			/* click finish */
 			functionalUtil.clickWizardFinish(browser);
+			
+			functionalUtil.waitForPageToLoad(browser);
 		}
 
 		return(true);
@@ -191,16 +195,17 @@ public class FunctionalCourseUtil {
 		
 		StringBuffer selectorBuffer = new StringBuffer();
 
-		selectorBuffer.append("xpath=//ul//li//a[contains(@class, '")
+		selectorBuffer.append("xpath=(//ul//li//a[contains(@class, '")
 		.append(getForumIconCss())
-		.append("')][")
+		.append("')])[")
 		.append(nth + 1)
 		.append("]")
 		.append("");
 		
+		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -229,7 +234,7 @@ public class FunctionalCourseUtil {
 		.append("')]");
 		
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in form - title */
 		selectorBuffer = new StringBuffer();
@@ -240,7 +245,7 @@ public class FunctionalCourseUtil {
 		
 		browser.type(selectorBuffer.toString(), title);
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+//		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in form - post */
 		functionalUtil.typeMCE(browser, message);
@@ -254,7 +259,7 @@ public class FunctionalCourseUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -268,7 +273,7 @@ public class FunctionalCourseUtil {
 	 */
 	public boolean openWiki(Selenium browser, long id){
 		browser.open(functionalUtil.getDeploymentUrl() + "url/RepositoryEntry/" + id);
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -306,7 +311,7 @@ public class FunctionalCourseUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* edit content */
 		selectorBuffer = new StringBuffer();
@@ -317,7 +322,7 @@ public class FunctionalCourseUtil {
 		
 		browser.click(selectorBuffer.toString());
 
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		
 		/* fill in text area */
@@ -338,7 +343,7 @@ public class FunctionalCourseUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -352,7 +357,7 @@ public class FunctionalCourseUtil {
 	 */
 	public boolean openBlog(Selenium browser, long id){
 		browser.open(functionalUtil.getDeploymentUrl() + "url/RepositoryEntry/" + id);
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
diff --git a/src/test/java/org/olat/util/FunctionalEPortfolioUtil.java b/src/test/java/org/olat/util/FunctionalEPortfolioUtil.java
index 11ddf70a435..7f4a07f6753 100644
--- a/src/test/java/org/olat/util/FunctionalEPortfolioUtil.java
+++ b/src/test/java/org/olat/util/FunctionalEPortfolioUtil.java
@@ -250,7 +250,7 @@ public class FunctionalEPortfolioUtil {
 		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -270,7 +270,7 @@ public class FunctionalEPortfolioUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -299,7 +299,7 @@ public class FunctionalEPortfolioUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		selectorBuffer = new StringBuffer();
 		
@@ -309,7 +309,7 @@ public class FunctionalEPortfolioUtil {
 
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 	
 		/* fill in dialog - title */
 		selectorBuffer = new StringBuffer();
@@ -333,7 +333,7 @@ public class FunctionalEPortfolioUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -382,7 +382,7 @@ public class FunctionalEPortfolioUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in wizard - title */
 		selectorBuffer = new StringBuffer();
@@ -434,7 +434,7 @@ public class FunctionalEPortfolioUtil {
 		
 		StringBuffer selectorBuffer = new StringBuffer();
 
-		selectorBuffer.append("xpath=//div[contains(@class, '")
+		selectorBuffer.append("//div[contains(@class, '")
 		.append(getEPortfolioTableOfContentsCss())
 		.append("')]//ul//li");
 		
@@ -511,7 +511,7 @@ public class FunctionalEPortfolioUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		selectorBuffer = new StringBuffer();
 		
@@ -521,9 +521,10 @@ public class FunctionalEPortfolioUtil {
 		.append(getStructIconCss())
 		.append("')]");
 		
+		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in wizard - title */
 		selectorBuffer = new StringBuffer();
@@ -532,8 +533,9 @@ public class FunctionalEPortfolioUtil {
 		.append(getEPortfolioMapCss())
 		.append("')]//form//input[@type='text']");
 		
+		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 		browser.type(selectorBuffer.toString(), title);
-		
+				
 		/* fill in wizard - description */
 		functionalUtil.typeMCE(browser, description);
 		
@@ -544,8 +546,10 @@ public class FunctionalEPortfolioUtil {
 		.append(getEPortfolioMapCss())
 		.append("')]//form//button[last()]");
 		
+		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 		browser.click(selectorBuffer.toString());
 		
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -565,7 +569,7 @@ public class FunctionalEPortfolioUtil {
 		
 		browser.click(selectorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -593,7 +597,7 @@ public class FunctionalEPortfolioUtil {
 		
 		functionalUtil.clickWizardNext(browser);
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -618,20 +622,14 @@ public class FunctionalEPortfolioUtil {
 			functionalUtil.waitForPageToLoadElement(browser, locatorBuffer.toString());
 			
 			browser.focus(locatorBuffer.toString());
-//			for(char c: (tag + ",").toCharArray()){
-//				browser.focus(locatorBuffer.toString());
-//				browser.keyDown(locatorBuffer.toString(), String.valueOf(c));
-//				browser.focus(locatorBuffer.toString());
-//				browser.keyPress(locatorBuffer.toString(), String.valueOf(c));
-//				browser.focus(locatorBuffer.toString());
-//				browser.keyUp(locatorBuffer.toString(), String.valueOf(c));
-//			}
 			browser.type(locatorBuffer.toString(), tag);
+			
 			browser.focus(locatorBuffer.toString());
 			browser.fireEvent(locatorBuffer.toString(), "changed");
-			browser.keyDown(locatorBuffer.toString(), ","); //TODO:JK: "13" is really ugly way to press enter
-			browser.keyPress(locatorBuffer.toString(), ","); //TODO:JK: "13" is really ugly way to press enter
-			browser.keyUp(locatorBuffer.toString(), ","); //TODO:JK: "13" is really ugly way to press enter
+			
+			browser.keyDown(locatorBuffer.toString(), ",");
+			browser.keyPress(locatorBuffer.toString(), ",");
+			browser.keyUp(locatorBuffer.toString(), ",");
 			browser.fireEvent(locatorBuffer.toString(), "changed");
 			browser.fireEvent(locatorBuffer.toString(), "blur");
 			
@@ -668,7 +666,7 @@ public class FunctionalEPortfolioUtil {
 		
 		/* open wizard */
 		openEditLink(browser);
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		StringBuffer locatorBuffer = new StringBuffer();
 		
@@ -677,14 +675,14 @@ public class FunctionalEPortfolioUtil {
 		.append("')]");
 		
 		browser.click(locatorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in wizard - content */
 		functionalUtil.typeMCE(browser, content);
 		
 		functionalUtil.clickWizardNext(browser);
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in wizard - title & description */
 		fillInTitleAndDescription(browser, title, description);
@@ -701,6 +699,8 @@ public class FunctionalEPortfolioUtil {
 		
 		/* click finish */
 		functionalUtil.clickWizardFinish(browser);
+
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -730,7 +730,7 @@ public class FunctionalEPortfolioUtil {
 		
 		/* open wizard */
 		openEditLink(browser);
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		StringBuffer locatorBuffer = new StringBuffer();
 		
@@ -739,7 +739,7 @@ public class FunctionalEPortfolioUtil {
 		.append("')]");
 		
 		browser.click(locatorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in wizard - file */
 		locatorBuffer = new StringBuffer();
@@ -756,11 +756,11 @@ public class FunctionalEPortfolioUtil {
 		/* IE may don't like the following script */
 		//browser.runScript("$(\"form ." + functionalUtil.getWizardCss() + " input[type='file']\").trigger(\"change\")");
 
-//		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+//		functionalUtil.waitForPageToLoad(browser);
 		
 		functionalUtil.clickWizardNext(browser);
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in wizard - title & description */
 		fillInTitleAndDescription(browser, title, description);
@@ -778,6 +778,8 @@ public class FunctionalEPortfolioUtil {
 		/* click finish */
 		functionalUtil.clickWizardFinish(browser);
 		
+		functionalUtil.waitForPageToLoad(browser);
+		
 		return(true);
 	}
 	
@@ -805,7 +807,7 @@ public class FunctionalEPortfolioUtil {
 		
 		/* open wizard */
 		openEditLink(browser);
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		StringBuffer locatorBuffer = new StringBuffer();
 		
@@ -815,7 +817,7 @@ public class FunctionalEPortfolioUtil {
 		
 		browser.click(locatorBuffer.toString());
 		
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		/* fill in wizard - title & description */
 		fillInTitleAndDescription(browser, title, description);
@@ -832,6 +834,8 @@ public class FunctionalEPortfolioUtil {
 		
 		/* click finish */
 		functionalUtil.clickWizardFinish(browser);
+
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
diff --git a/src/test/java/org/olat/util/FunctionalHomeSiteUtil.java b/src/test/java/org/olat/util/FunctionalHomeSiteUtil.java
index d980501032e..115c2a1bbd9 100644
--- a/src/test/java/org/olat/util/FunctionalHomeSiteUtil.java
+++ b/src/test/java/org/olat/util/FunctionalHomeSiteUtil.java
@@ -547,7 +547,7 @@ public class FunctionalHomeSiteUtil {
 			return(false);
 		}
 
-		if(!checkCurrentAction || !checkCurrentAction(browser, action, 15000)){
+		if(!checkCurrentAction || !checkCurrentAction(browser, action, Long.parseLong(functionalUtil.getWaitLimit()))){
 			StringBuffer selectorBuffer = new StringBuffer();
 
 			selectorBuffer.append("xpath=//ul//li[contains(@class, '")
@@ -562,11 +562,11 @@ public class FunctionalHomeSiteUtil {
 				.append("']//a");
 
 				browser.click(actionSelectorBuffer.toString());
-				browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+				functionalUtil.waitForPageToLoad(browser);
 			}
 
 			browser.click(selectorBuffer.toString());
-			browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+			functionalUtil.waitForPageToLoad(browser);
 			functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 		}
 
@@ -898,7 +898,7 @@ public class FunctionalHomeSiteUtil {
 		selectorBuffer.append("button[@type='button']");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 	}
 
@@ -930,7 +930,7 @@ public class FunctionalHomeSiteUtil {
 		selectorBuffer.append("button[@type='button']");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 	}
 
@@ -962,7 +962,7 @@ public class FunctionalHomeSiteUtil {
 		selectorBuffer.append("button[@type='button']");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 	}
 
@@ -994,7 +994,7 @@ public class FunctionalHomeSiteUtil {
 		selectorBuffer.append("button[@type='button']");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 
 		return(true);
@@ -1023,7 +1023,7 @@ public class FunctionalHomeSiteUtil {
 		selectorBuffer.append("button[@type='button']");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 
 		return(true);
@@ -1052,7 +1052,7 @@ public class FunctionalHomeSiteUtil {
 		selectorBuffer.append("button[@type='button']");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 
 		return(true);
@@ -1097,7 +1097,7 @@ public class FunctionalHomeSiteUtil {
 
 		log.info("submitting changes");
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		//functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
 		
 		return(true);
diff --git a/src/test/java/org/olat/util/FunctionalRepositorySiteUtil.java b/src/test/java/org/olat/util/FunctionalRepositorySiteUtil.java
index 895cdfcdda7..886204a4627 100644
--- a/src/test/java/org/olat/util/FunctionalRepositorySiteUtil.java
+++ b/src/test/java/org/olat/util/FunctionalRepositorySiteUtil.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.junit.Assert;
 import org.olat.util.FunctionalUtil.OlatSite;
+import org.olat.util.FunctionalUtil.WaitLimitAttribute;
 
 import com.thoughtworks.selenium.Selenium;
 
@@ -359,7 +360,7 @@ public class FunctionalRepositorySiteUtil {
 		.append(" * a");
 		
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -373,7 +374,7 @@ public class FunctionalRepositorySiteUtil {
 	 */
 	public boolean openCourse(Selenium browser, long key){
 		browser.open(functionalUtil.getDeploymentUrl() + "url/RepositoryEntry/" + key);
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -408,7 +409,7 @@ public class FunctionalRepositorySiteUtil {
 		.append("//a[@class='b_button']");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 
 		/* click course */
 		selectorBuffer = new StringBuffer();
@@ -419,7 +420,7 @@ public class FunctionalRepositorySiteUtil {
 		.append("//a");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -486,7 +487,7 @@ public class FunctionalRepositorySiteUtil {
 		.append("//a[@class='b_button']");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 
 		/* click course */
 		selectorBuffer = new StringBuffer();
@@ -499,7 +500,7 @@ public class FunctionalRepositorySiteUtil {
 		.append("//a");
 
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(functionalUtil.getWaitLimit());
+		functionalUtil.waitForPageToLoad(browser);
 		
 		return(true);
 	}
diff --git a/src/test/java/org/olat/util/FunctionalUtil.java b/src/test/java/org/olat/util/FunctionalUtil.java
index 0c325cf9cd5..8e84818f57b 100644
--- a/src/test/java/org/olat/util/FunctionalUtil.java
+++ b/src/test/java/org/olat/util/FunctionalUtil.java
@@ -24,6 +24,7 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.Properties;
 
+import org.apache.commons.httpclient.HttpClient;
 import org.olat.core.logging.OLog;
 import org.olat.core.logging.Tracing;
 import org.olat.util.FunctionalAdministrationSiteUtil.AdministrationSiteAction;
@@ -43,13 +44,34 @@ public class FunctionalUtil {
 	private final static OLog log = Tracing.createLoggerFor(FunctionalUtil.class);
 	
 	public final static String DEPLOYMENT_URL = "http://localhost:8080/olat";
-	public final static String WAIT_LIMIT = "15000";
+	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 enum WaitLimitAttribute {
+		NORMAL("0"),
+		EXTENDED("3000"),
+		SAVE("7000"),
+		VERY_SAVE("12000");
+		
+		private String extend;
+		
+		WaitLimitAttribute(String extend){
+			setExtend(extend);
+		}
+
+		public String getExtend() {
+			return extend;
+		}
+
+		public void setExtend(String extend) {
+			this.extend = extend;
+		}
+	}
+	
 	public enum OlatSite {
 		HOME,
 		GROUPS,
@@ -124,7 +146,6 @@ public class FunctionalUtil {
 	private FunctionalUserManagementSiteUtil functionalUserManagementSiteUtil;
 	private FunctionalAdministrationSiteUtil functionalAdministrationSiteUtil;
 	
-	
 	public FunctionalUtil(){
 		Properties properties = new Properties();
 		
@@ -200,7 +221,17 @@ public class FunctionalUtil {
 		
 		/* open url and wait specified time */
 		browser.open(url);
-		browser.waitForPageToLoad(getWaitLimit());
+		waitForPageToLoad(browser);
+	}
+	
+	public void waitForPageToLoad(Selenium browser){
+		waitForPageToLoad(browser, WaitLimitAttribute.VERY_SAVE);
+	}
+	
+	public void waitForPageToLoad(Selenium browser, WaitLimitAttribute wait){
+		String waitLimit = Long.toString(Long.parseLong(getWaitLimit()) + Long.parseLong(wait.getExtend()));
+		
+		browser.waitForPageToLoad(waitLimit);
 	}
 
 	/**
@@ -208,13 +239,26 @@ public class FunctionalUtil {
 	 * @param locator
 	 * @return true on success otherwise false
 	 * 
-	 * Waits at most waitLimit amount of time for element to load
+	 * Waits at most (waitLimit + WaitLimitAttribute.VERY_SAVE) amount of time for element to load
 	 * specified by locator.
 	 */
 	public boolean waitForPageToLoadElement(Selenium browser, String locator){
+		return(waitForPageToLoadElement(browser, locator, WaitLimitAttribute.VERY_SAVE));
+	}
+	
+	/**
+	 * @param browser
+	 * @param locator
+	 * @param wait
+	 * @return true on success otherwise false
+	 * 
+	 * Waits at most (waitLimit + wait) amount of time for element to load
+	 * specified by locator.
+	 */
+	public boolean waitForPageToLoadElement(Selenium browser, String locator, WaitLimitAttribute wait){
 		long startTime = Calendar.getInstance().getTimeInMillis();
 		long currentTime = startTime;
-		long waitLimit = Long.parseLong(getWaitLimit());
+		long waitLimit = Long.parseLong(getWaitLimit()) + Long.parseLong(wait.getExtend());
 
 		log.info("waiting for page to load element");
 		
@@ -399,7 +443,7 @@ public class FunctionalUtil {
 			return(false);
 		}
 		
-		if(checkCurrentSite(browser, site, 15000)){
+		if(checkCurrentSite(browser, site, Long.parseLong(getWaitLimit()))){
 			if(resetSite(browser, site)){
 				return(true);
 			}else{
@@ -417,8 +461,8 @@ public class FunctionalUtil {
 		.append(" a");
 		
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(getWaitLimit());
-		waitForPageToLoadElement(browser, selectorBuffer.toString());
+		waitForPageToLoad(browser);
+		waitForPageToLoadElement(browser, selectorBuffer.toString(), WaitLimitAttribute.NORMAL);
 		
 		/* set it to it's initial state */
 		resetSite(browser, site);
@@ -447,7 +491,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");
-	    browser.waitForPageToLoad(getWaitLimit());
+	    waitForPageToLoad(browser);
 	    
 	    if(closeDialogs){
 	    	/* check if it's our first login */
@@ -456,7 +500,7 @@ public class FunctionalUtil {
 
 	    		/* click accept button */
 	    		browser.click("xpath=//div[contains(@class, 'b_window')]//button[last()]");
-	    		browser.waitForPageToLoad(getWaitLimit());
+	    		waitForPageToLoad(browser);
 	    	}
 
 	    	/* click away info dialogs eg. restore session */
@@ -465,7 +509,7 @@ public class FunctionalUtil {
 	    		/* click last button */
 	    	if(browser.isElementPresent("id="+ getInfoDialog())){
 	    		browser.click("xpath=//form//div//button[@type='button']/../../span/a[@class='b_button']");
-	    		browser.waitForPageToLoad(getWaitLimit());
+	    		waitForPageToLoad(browser);
 	    	}
 	    	//}
 	    }
@@ -488,7 +532,7 @@ public class FunctionalUtil {
 		.append(" a");
 		
 		browser.click(selectorBuffer.toString());
-		browser.waitForPageToLoad(getWaitLimit());
+		waitForPageToLoad(browser);
 		
 		return(true);
 	}
@@ -522,7 +566,7 @@ public class FunctionalUtil {
 			.append(" * a");
 			
 			browser.click(selectorBuffer.toString());
-			browser.waitForPageToLoad(getWaitLimit());
+			waitForPageToLoad(browser);
 		}
 		
 		return(true);
diff --git a/src/test/java/org/olat/util/FunctionalVOUtil.java b/src/test/java/org/olat/util/FunctionalVOUtil.java
index 2cdaf1dc278..82140b106e3 100644
--- a/src/test/java/org/olat/util/FunctionalVOUtil.java
+++ b/src/test/java/org/olat/util/FunctionalVOUtil.java
@@ -29,12 +29,17 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.List;
 import java.util.UUID;
 
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriBuilder;
 
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
@@ -43,13 +48,19 @@ import org.apache.http.entity.mime.MultipartEntity;
 import org.apache.http.entity.mime.content.FileBody;
 import org.apache.http.entity.mime.content.StringBody;
 import org.junit.Assert;
-import org.olat.restapi.CoursesTest;
+import org.olat.core.logging.OLog;
+import org.olat.core.logging.Tracing;
 import org.olat.restapi.RestConnection;
 import org.olat.restapi.support.vo.CourseVO;
 import org.olat.restapi.support.vo.RepositoryEntryVO;
 import org.olat.user.restapi.UserVO;
 
 public class FunctionalVOUtil {
+
+	private final static OLog log = Tracing.createLoggerFor(FunctionalVOUtil.class);
+	
+	public final static String WAIT_LIMIT = "15000";
+	
 	public final static String ALL_ELEMENTS_COURSE_DISPLAYNAME = "All Elements Course";
 	public final static String ALL_ELEMENTS_COURSE_FILENAME = "All_Elements_Course.zip";
 
@@ -68,6 +79,9 @@ public class FunctionalVOUtil {
 	
 	private String allElementsCourseDisplayname;
 	private String allElementsCourseFilename;
+
+	private HttpClient client;
+	private String waitLimit;
 	
 	public FunctionalVOUtil(String username, String password){
 		setUsername(username);
@@ -75,6 +89,9 @@ public class FunctionalVOUtil {
 		
 		setAllElementsCourseDisplayname(ALL_ELEMENTS_COURSE_DISPLAYNAME);
 		setAllElementsCourseFilename(ALL_ELEMENTS_COURSE_FILENAME);
+		
+		client = new HttpClient();
+		waitLimit = WAIT_LIMIT;
 	}
 	
 	/**
@@ -134,14 +151,18 @@ public class FunctionalVOUtil {
 	
 	/**
 	 * @param deploymentUrl
-	 * @return
+	 * @param path
+	 * @param filename
+	 * @param resourcename
+	 * @param displayname
+	 * @return CourseVO
 	 * @throws URISyntaxException
 	 * @throws IOException
 	 * 
-	 * Imports the "All Elements Course" via REST.
+	 * Imports the specified course via REST.
 	 */
-	public CourseVO importAllElementsCourse(URL deploymentUrl) throws URISyntaxException, IOException{
-		URL cpUrl = FunctionalVOUtil.class.getResource("/org/olat/course/All_Elements_Course.zip");
+	public CourseVO importCourse(URL deploymentUrl, String path, String filename, String resourcename, String displayname) throws URISyntaxException, IOException{
+		URL cpUrl = FunctionalVOUtil.class.getResource(path);
 		assertNotNull(cpUrl);
 		File cp = new File(cpUrl.toURI());
 
@@ -152,9 +173,9 @@ public class FunctionalVOUtil {
 		HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON, true);
 		MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
 		entity.addPart("file", new FileBody(cp));
-		entity.addPart("filename", new StringBody("All_Elements_Course.zip"));
-		entity.addPart("resourcename", new StringBody("All Elements Course"));
-		entity.addPart("displayname", new StringBody("All Elements Course"));
+		entity.addPart("filename", new StringBody(filename));
+		entity.addPart("resourcename", new StringBody(resourcename));
+		entity.addPart("displayname", new StringBody(displayname));
 		entity.addPart("access", new StringBody("3"));
 		String softKey = UUID.randomUUID().toString().replace("-", "").substring(0, 30);
 		entity.addPart("softkey", new StringBody(softKey));
@@ -167,10 +188,34 @@ public class FunctionalVOUtil {
 		assertNotNull(vo);
 		assertNotNull(vo.getRepoEntryKey());
 		assertNotNull(vo.getKey());
-
+		
 		return(vo);
 	}
+	
+	/**
+	 * @param deploymentUrl
+	 * @return
+	 * @throws URISyntaxException
+	 * @throws IOException
+	 * 
+	 * Imports the "All Elements Course" via REST.
+	 */
+	public CourseVO importAllElementsCourse(URL deploymentUrl) throws URISyntaxException, IOException{
+		return(importCourse(deploymentUrl, "/org/olat/course/All_Elements_Course.zip", "All_Elements_Course.zip", "All Elements Course", "All Elements Course"));
+	}
 
+	/**
+	 * @param deploymentUrl
+	 * @return
+	 * @throws URISyntaxException
+	 * @throws IOException
+	 * 
+	 * Imports the "Course including Forum" via REST.
+	 */
+	public CourseVO importCourseIncludingForum(URL deploymentUrl) throws URISyntaxException, IOException{
+		return(importCourse(deploymentUrl, "/org/olat/portfolio/Course_including_Forum.zip", "Course_including_Forum.zip", "Course including Forum", "Course including Forum"));
+	}
+	
 	/**
 	 * @param deploymentUrl
 	 * @return
@@ -282,4 +327,20 @@ public class FunctionalVOUtil {
 	public void setAllElementsCourseFilename(String allElementsCourseFilename) {
 		this.allElementsCourseFilename = allElementsCourseFilename;
 	}
+
+	public HttpClient getClient() {
+		return client;
+	}
+
+	public void setClient(HttpClient client) {
+		this.client = client;
+	}
+
+	public String getWaitLimit() {
+		return waitLimit;
+	}
+
+	public void setWaitLimit(String waitLimit) {
+		this.waitLimit = waitLimit;
+	}
 }
-- 
GitLab