From f85349e502c1106c31c5752328f91befa7cfee3c Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Wed, 16 Dec 2015 21:32:27 +0100
Subject: [PATCH] no-jira: add a JUnit rule to take screenshot of the browser
 which make an error during a selenium test, hardened the popup to create
 feeds

---
 .../webFeed/ui/FeedFormController.java        |   4 +-
 .../org/olat/selenium/AssessmentTest.java     |  19 +++-
 .../org/olat/selenium/BusinessGroupTest.java  |  19 +++-
 .../java/org/olat/selenium/CourseTest.java    |  42 ++++++-
 .../java/org/olat/selenium/LoginTest.java     |   9 ++
 .../java/org/olat/selenium/PortfolioTest.java |  29 ++++-
 src/test/java/org/olat/selenium/UserTest.java |  25 ++++
 .../selenium/page/ScreenshotTestRule.java     | 107 ++++++++++++++++++
 .../selenium/page/repository/FeedPage.java    |   9 +-
 9 files changed, 250 insertions(+), 13 deletions(-)
 create mode 100644 src/test/java/org/olat/selenium/page/ScreenshotTestRule.java

diff --git a/src/main/java/org/olat/modules/webFeed/ui/FeedFormController.java b/src/main/java/org/olat/modules/webFeed/ui/FeedFormController.java
index 42d6354fccc..330dda30917 100644
--- a/src/main/java/org/olat/modules/webFeed/ui/FeedFormController.java
+++ b/src/main/java/org/olat/modules/webFeed/ui/FeedFormController.java
@@ -224,6 +224,7 @@ class FeedFormController extends FormBasicController {
 		// title might be longer from external source
 		String saveTitle = PersistenceHelper.truncateStringDbSave(feed.getTitle(), 256, true);
 		title = uifactory.addTextElement("title", "feed.title.label", 256, saveTitle, formLayout);
+		title.setElementCssClass("o_sel_feed_title");
 		title.setMandatory(true);
 		title.setNotEmptyCheck("feed.form.field.is_mandatory");
 
@@ -265,7 +266,8 @@ class FeedFormController extends FormBasicController {
 
 		// if external feed, display feed-url text-element:
 		if(feed.isExternal()){
-			feedUrl = uifactory.addTextElement("feedUrl", "feed.form.feedurl", 5000, feed.getExternalFeedUrl(), this.flc);
+			feedUrl = uifactory.addTextElement("feedUrl", "feed.form.feedurl", 5000, feed.getExternalFeedUrl(), flc);
+			feedUrl.setElementCssClass("o_sel_feed_url");
 			feedUrl.setDisplaySize(70);
 
 			String type = feed.getResourceableTypeName();
diff --git a/src/test/java/org/olat/selenium/AssessmentTest.java b/src/test/java/org/olat/selenium/AssessmentTest.java
index eaefe5fb26e..316aa8fca15 100644
--- a/src/test/java/org/olat/selenium/AssessmentTest.java
+++ b/src/test/java/org/olat/selenium/AssessmentTest.java
@@ -37,11 +37,13 @@ import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.junit.Assert;
 import org.junit.Assume;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.olat.selenium.page.LoginPage;
 import org.olat.selenium.page.NavigationPage;
 import org.olat.selenium.page.Participant;
+import org.olat.selenium.page.ScreenshotTestRule;
 import org.olat.selenium.page.Student;
 import org.olat.selenium.page.User;
 import org.olat.selenium.page.course.AssessmentCEConfigurationPage;
@@ -89,6 +91,8 @@ public class AssessmentTest {
 	private WebDriver browser;
 	@ArquillianResource
 	private URL deploymentUrl;
+	@Rule
+    public ScreenshotTestRule screenshotTestRule = new ScreenshotTestRule();
 	
 	@Page
 	private NavigationPage navBar;
@@ -105,6 +109,8 @@ public class AssessmentTest {
 	@RunAsClient
 	public void qti12Test(@InitialPage LoginPage authorLoginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		//File upload only work with Firefox
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 				
@@ -200,6 +206,7 @@ public class AssessmentTest {
 	public void qti12CourseWithAssessment(@InitialPage LoginPage authorLoginPage,
 			@Drone @User WebDriver ryomouBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
 		//File upload only work with Firefox
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 		
@@ -342,6 +349,7 @@ public class AssessmentTest {
 	public void scormCourseWithAssessment(@InitialPage LoginPage authorLoginPage,
 			@Drone @User WebDriver ryomouBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser);
 		//File upload only work with Firefox
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 				
@@ -462,6 +470,7 @@ public class AssessmentTest {
 	public void assessmentMode_manual(@InitialPage LoginPage authorLoginPage,
 			@Drone @Student WebDriver ryomouBrowser, @Drone @Participant WebDriver kanuBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser, kanuBrowser);
 		//File upload only work with Firefox
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 		
@@ -607,6 +616,7 @@ public class AssessmentTest {
 	public void certificatesManuallyGenerated(@InitialPage LoginPage authorLoginPage,
 			@Drone @User WebDriver reiBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, reiBrowser);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		authorLoginPage.loginAs(author.getLogin(), author.getPassword());
@@ -681,6 +691,8 @@ public class AssessmentTest {
 	public void certificatesGeneratedByTest(@InitialPage LoginPage authorLoginPage,
 			@Drone @User WebDriver reiBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, reiBrowser);
+		
 		//create an author and a participant
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO rei = new UserRestClient(deploymentUrl).createRandomUser("Rei");
@@ -779,7 +791,8 @@ public class AssessmentTest {
 	public void assessmentCourseElement(@InitialPage LoginPage authorLoginPage,
 			@Drone @User WebDriver ryomouBrowser)
 	throws IOException, URISyntaxException {
-
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO ryomou = new UserRestClient(deploymentUrl).createRandomUser("Ryomou");
 		
@@ -876,6 +889,7 @@ public class AssessmentTest {
 			@Drone @User WebDriver ryomouBrowser,
 			@Drone @Participant WebDriver kanuBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser, kanuBrowser);
 		//File upload only work with Firefox
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 						
@@ -1064,6 +1078,7 @@ public class AssessmentTest {
 	public void taskWithIndividuScoreAndRevision(@InitialPage LoginPage authorLoginPage,
 			@Drone @User WebDriver ryomouBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser);
 		//File upload only work with Firefox
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 						
@@ -1228,6 +1243,8 @@ public class AssessmentTest {
 			@Drone @User WebDriver ryomouBrowser,
 			@Drone @Participant WebDriver kanuBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser,kanuBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO ryomou = new UserRestClient(deploymentUrl).createRandomUser("Ryomou");
 		UserVO kanu = new UserRestClient(deploymentUrl).createRandomUser("Kanu");
diff --git a/src/test/java/org/olat/selenium/BusinessGroupTest.java b/src/test/java/org/olat/selenium/BusinessGroupTest.java
index c5a65f7f182..9e8abd60894 100644
--- a/src/test/java/org/olat/selenium/BusinessGroupTest.java
+++ b/src/test/java/org/olat/selenium/BusinessGroupTest.java
@@ -35,11 +35,13 @@ import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.olat.selenium.page.LoginPage;
 import org.olat.selenium.page.NavigationPage;
 import org.olat.selenium.page.Participant;
+import org.olat.selenium.page.ScreenshotTestRule;
 import org.olat.selenium.page.Student;
 import org.olat.selenium.page.User;
 import org.olat.selenium.page.core.IMPage;
@@ -76,11 +78,12 @@ public class BusinessGroupTest {
 	@Drone
 	private WebDriver browser;
 	@ArquillianResource
-	private URL deploymentUrl;	
-
+	private URL deploymentUrl;
 	@Page
 	private NavigationPage navBar;
-	
+	@Rule
+    public ScreenshotTestRule screenshotTestRule = new ScreenshotTestRule();
+
 	/**
 	 * Create a group, search it and delete it.
 	 * 
@@ -92,6 +95,8 @@ public class BusinessGroupTest {
 	@RunAsClient
 	public void createDeleteBusinessGroup(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
@@ -126,6 +131,7 @@ public class BusinessGroupTest {
 	public void groupMembersVisibility(@InitialPage LoginPage loginPage,
 			@Drone @Participant WebDriver participantBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, participantBrowser);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createRandomUser("Selena");
 		UserVO participant = new UserRestClient(deploymentUrl).createRandomUser("Aoi");
@@ -184,6 +190,7 @@ public class BusinessGroupTest {
 	@RunAsClient
 	public void collaborativeTools(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createRandomUser("Selena");
 		
@@ -285,6 +292,7 @@ public class BusinessGroupTest {
 			@Drone @Participant WebDriver participantBrowser,
 			@Drone @Student WebDriver studentBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, participantBrowser, studentBrowser);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createRandomUser("Selena");
 		UserVO participant = new UserRestClient(deploymentUrl).createRandomUser("Ryomou");
@@ -382,6 +390,7 @@ public class BusinessGroupTest {
 			@Drone @Participant WebDriver kanuBrowser,
 			@Drone @User WebDriver ryomouBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, kanuBrowser, ryomouBrowser);
 
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO kanu = new UserRestClient(deploymentUrl).createRandomUser("Kanu");
@@ -491,6 +500,7 @@ public class BusinessGroupTest {
 			@Drone @Participant WebDriver reiBrowser,
 			@Drone @Student WebDriver kanuBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser, reiBrowser, kanuBrowser);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		authorLoginPage.loginAs(author.getLogin(), author.getPassword());
@@ -604,6 +614,7 @@ public class BusinessGroupTest {
 	public void enrollmentWithMultiEnrollment(@InitialPage LoginPage authorLoginPage,
 			@Drone @User WebDriver ryomouBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		authorLoginPage.loginAs(author.getLogin(), author.getPassword());
@@ -707,6 +718,7 @@ public class BusinessGroupTest {
 			@Drone @Participant WebDriver reiBrowser,
 			@Drone @Student WebDriver kanuBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser, reiBrowser, kanuBrowser);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO rei = new UserRestClient(deploymentUrl).createRandomUser("Rei");
@@ -839,6 +851,7 @@ public class BusinessGroupTest {
 			@Drone @Participant WebDriver reiBrowser,
 			@Drone @Student WebDriver kanuBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser, reiBrowser, kanuBrowser);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO rei = new UserRestClient(deploymentUrl).createRandomUser("Rei");
diff --git a/src/test/java/org/olat/selenium/CourseTest.java b/src/test/java/org/olat/selenium/CourseTest.java
index a61441ea488..1aaf15f41d6 100644
--- a/src/test/java/org/olat/selenium/CourseTest.java
+++ b/src/test/java/org/olat/selenium/CourseTest.java
@@ -38,12 +38,14 @@ import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.olat.selenium.page.Administrator;
 import org.olat.selenium.page.LoginPage;
 import org.olat.selenium.page.NavigationPage;
 import org.olat.selenium.page.Participant;
+import org.olat.selenium.page.ScreenshotTestRule;
 import org.olat.selenium.page.Student;
 import org.olat.selenium.page.User;
 import org.olat.selenium.page.core.BookingPage;
@@ -93,9 +95,10 @@ public class CourseTest {
 	private WebDriver browser;
 	@ArquillianResource
 	private URL deploymentUrl;
-	
 	@Page
 	private NavigationPage navBar;
+	@Rule
+    public ScreenshotTestRule screenshotTestRule = new ScreenshotTestRule();
 	
 	/**
 	 * An author create a course, jump to it, open the editor
@@ -110,6 +113,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourse(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -180,6 +185,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourse_withWizard(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -239,6 +246,8 @@ public class CourseTest {
 	public void concurrentEditCourse(@InitialPage LoginPage loginPage,
 			@Drone @Participant WebDriver coAuthorBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, coAuthorBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO coAuthor = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
@@ -341,6 +350,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourseWithCP(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -403,6 +414,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourseWithWiki(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -464,6 +477,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourseWithWiki_createInCourseEditor(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -509,6 +524,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourseWithQTITest(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -562,6 +579,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourseWithPodcast_externalFeed(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -612,6 +631,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourseWithBlog_externalFeed(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -674,6 +695,7 @@ public class CourseTest {
 			@Drone @Participant WebDriver participantDrone,
 			@Drone @Administrator WebDriver administratorDrone)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, participantDrone, administratorDrone);
 		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO participant = new UserRestClient(deploymentUrl).createRandomUser("Ryomou");
@@ -777,6 +799,8 @@ public class CourseTest {
 	public void catalogRoundTrip(@Drone @Administrator WebDriver adminBrowser,
 			@Drone @User WebDriver userBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, adminBrowser, userBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO user = new UserRestClient(deploymentUrl).createRandomUser();
 		
@@ -856,6 +880,8 @@ public class CourseTest {
 	@RunAsClient
 	public void createCourseWithInfoMessages(@InitialPage LoginPage authorLoginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		authorLoginPage.loginAs(author.getLogin(), author.getPassword());
 		
@@ -960,6 +986,8 @@ public class CourseTest {
 	public void courseBooking(@InitialPage LoginPage loginPage,
 			@Drone @User WebDriver ryomouBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		UserVO ryomou = new UserRestClient(deploymentUrl).createRandomUser("Ryomou");
@@ -1043,6 +1071,8 @@ public class CourseTest {
 	@RunAsClient
 	public void courseReminders(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage.loginAs(author.getLogin(), author.getPassword());
 		UserVO kanu = new UserRestClient(deploymentUrl).createRandomUser("Kanu");
@@ -1138,6 +1168,8 @@ public class CourseTest {
 			@Drone @Participant WebDriver kanuBrowser,
 			@Drone @User WebDriver ryomouBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, kanuBrowser, ryomouBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO kanu = new UserRestClient(deploymentUrl).createRandomUser("Kanu");
 		UserVO ryomou = new UserRestClient(deploymentUrl).createRandomUser("Ryomou");
@@ -1259,6 +1291,8 @@ public class CourseTest {
 			@Drone @Participant WebDriver kanuBrowser,
 			@Drone @Student WebDriver reiBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, kanuBrowser, reiBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO kanu = new UserRestClient(deploymentUrl).createRandomUser("Kanu");
 		UserVO rei = new UserRestClient(deploymentUrl).createRandomUser("Rei");
@@ -1389,6 +1423,8 @@ public class CourseTest {
 	public void forumWithGuest(@InitialPage LoginPage loginPage,
 			@Drone @User WebDriver guestBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, guestBrowser);
+		
 		loginPage
 			.loginAs("administrator", "openolat")
 			.resume();
@@ -1507,6 +1543,8 @@ public class CourseTest {
 	public void courseAccessRules(@InitialPage LoginPage loginPage,
 			@Drone @Student WebDriver reiBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, reiBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO rei = new UserRestClient(deploymentUrl).createRandomUser("rei");
 		loginPage.loginAs(author.getLogin(), author.getPassword());
@@ -1641,6 +1679,8 @@ public class CourseTest {
 	public void createContentPackage(@InitialPage LoginPage loginPage,
 			@Drone @User WebDriver ryomouBrowser)
 			throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, ryomouBrowser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		UserVO ryomou = new UserRestClient(deploymentUrl).createRandomUser("Ryomou");
 		loginPage.loginAs(author.getLogin(), author.getPassword());
diff --git a/src/test/java/org/olat/selenium/LoginTest.java b/src/test/java/org/olat/selenium/LoginTest.java
index bf5ce3e7de1..2257d5bbab6 100644
--- a/src/test/java/org/olat/selenium/LoginTest.java
+++ b/src/test/java/org/olat/selenium/LoginTest.java
@@ -31,11 +31,13 @@ import org.jboss.arquillian.graphene.page.InitialPage;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.olat.selenium.page.LoginPage;
 import org.olat.selenium.page.NavigationPage;
 import org.olat.selenium.page.Participant;
+import org.olat.selenium.page.ScreenshotTestRule;
 import org.olat.selenium.page.Student;
 import org.olat.selenium.page.core.AdministrationMessagesPage;
 import org.olat.test.ArquillianDeployments;
@@ -61,6 +63,8 @@ public class LoginTest {
 	private WebDriver browser;
 	@ArquillianResource
 	private URL deploymentUrl;
+	@Rule
+    public ScreenshotTestRule screenshotTestRule = new ScreenshotTestRule();
 
 	/**
 	 * Test if the dmz can be loaded.
@@ -69,6 +73,7 @@ public class LoginTest {
 	@Test
 	@RunAsClient
 	public void loadIndex(@InitialPage LoginPage loginPage) {
+		screenshotTestRule.setBrowsers(browser);
 		//check that the login page, or dmz is loaded
 		loginPage.assertOnLoginPage();
 	}
@@ -81,6 +86,7 @@ public class LoginTest {
 	@Test
 	@RunAsClient
 	public void loginAsAdministrator(@InitialPage LoginPage loginPage) {
+		screenshotTestRule.setBrowsers(browser);
 		//load dmz
 		loginPage.assertOnLoginPage();
 		//login as administrator
@@ -101,6 +107,7 @@ public class LoginTest {
 	@RunAsClient
 	public void loginAsNewUser(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
 		//create a random user
 		UserRestClient userClient = new UserRestClient(deploymentUrl);
 		UserVO user = userClient.createRandomUser();
@@ -130,6 +137,8 @@ public class LoginTest {
 			@Drone @Participant WebDriver reiBrowser,
 			@Drone @Student WebDriver kanuBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, reiBrowser, kanuBrowser);
+		
 		UserVO rei = new UserRestClient(deploymentUrl).createRandomUser("Rei");
 		UserVO kanu = new UserRestClient(deploymentUrl).createRandomUser("Kanu");
 		
diff --git a/src/test/java/org/olat/selenium/PortfolioTest.java b/src/test/java/org/olat/selenium/PortfolioTest.java
index 769e530ada0..a8115752937 100644
--- a/src/test/java/org/olat/selenium/PortfolioTest.java
+++ b/src/test/java/org/olat/selenium/PortfolioTest.java
@@ -35,10 +35,12 @@ import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.junit.Assert;
 import org.junit.Assume;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.olat.selenium.page.LoginPage;
 import org.olat.selenium.page.NavigationPage;
+import org.olat.selenium.page.ScreenshotTestRule;
 import org.olat.selenium.page.course.CourseEditorPageFragment;
 import org.olat.selenium.page.course.CoursePageFragment;
 import org.olat.selenium.page.forum.ForumPage;
@@ -72,11 +74,12 @@ public class PortfolioTest {
 	private WebDriver browser;
 	@ArquillianResource
 	private URL deploymentUrl;
-
-	@Page
-	private UserToolsPage userTools;
 	@Page
 	private NavigationPage navBar;
+	@Page
+	private UserToolsPage userTools;
+	@Rule
+    public ScreenshotTestRule screenshotTestRule = new ScreenshotTestRule();
 
 	/**
 	 * Create a course with a forum, publish it.
@@ -92,6 +95,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void collectForumArtefactInCourse(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
@@ -179,6 +184,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void collectWikiArtefactInWikiResource(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
@@ -259,6 +266,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void collectBlogPostInCourse(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
@@ -355,6 +364,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void addTextArtefact(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
@@ -420,6 +431,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void addTextArtefact_withinMap(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
@@ -484,6 +497,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void addLearningJournal(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
@@ -562,6 +577,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void addLearningJournal_withinMap(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
@@ -638,6 +655,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void addFileArtefact(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		//File upload only work with Firefox
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 		
@@ -712,6 +731,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void addFileArtefact_withinMap(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		//File upload only work with Firefox
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 		
@@ -787,6 +808,8 @@ public class PortfolioTest {
 	@RunAsClient
 	public void createPortfolioTemplate_inCourse(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
 		loginPage
 			.loginAs(author.getLogin(), author.getPassword())
diff --git a/src/test/java/org/olat/selenium/UserTest.java b/src/test/java/org/olat/selenium/UserTest.java
index 56bf94aed2e..2bcd701231a 100644
--- a/src/test/java/org/olat/selenium/UserTest.java
+++ b/src/test/java/org/olat/selenium/UserTest.java
@@ -35,11 +35,13 @@ import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.junit.Assert;
 import org.junit.Assume;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.olat.restapi.support.vo.CourseVO;
 import org.olat.selenium.page.LoginPage;
 import org.olat.selenium.page.NavigationPage;
+import org.olat.selenium.page.ScreenshotTestRule;
 import org.olat.selenium.page.Student;
 import org.olat.selenium.page.User;
 import org.olat.selenium.page.course.CoursePageFragment;
@@ -83,6 +85,8 @@ public class UserTest {
 	private UserToolsPage userTools;
 	@Page
 	private NavigationPage navBar;
+	@Rule
+    public ScreenshotTestRule screenshotTestRule = new ScreenshotTestRule();
 	
 	/**
 	 * Set the resume preferences to automatically resume the session,
@@ -194,6 +198,8 @@ public class UserTest {
 	@RunAsClient
 	public void resumeDisabled(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO user = new UserRestClient(deploymentUrl).createRandomUser();
 		loginPage
 			.loginAs(user.getLogin(), user.getPassword())
@@ -234,6 +240,8 @@ public class UserTest {
 	@RunAsClient
 	public void userSwitchLanguageSwitchToEnglish(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO user = new UserRestClient(deploymentUrl).createRandomUser();
 		loginPage
 			.loginAs(user.getLogin(), user.getPassword())
@@ -292,6 +300,8 @@ public class UserTest {
 	@RunAsClient
 	public void userChangeItsPassword(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO user = new UserRestClient(deploymentUrl).createRandomUser();
 		loginPage
 			.loginAs(user.getLogin(), user.getPassword())
@@ -324,6 +334,8 @@ public class UserTest {
 	@RunAsClient
 	public void userResetItsPreferences(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO user = new UserRestClient(deploymentUrl).createRandomUser();
 		loginPage
 			.loginAs(user.getLogin(), user.getPassword())
@@ -352,6 +364,8 @@ public class UserTest {
 	@RunAsClient
 	public void portletDeactivateActivate(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO user = new UserRestClient(deploymentUrl).createRandomUser();
 		loginPage
 			.loginAs(user.getLogin(), user.getPassword());
@@ -386,6 +400,8 @@ public class UserTest {
 	@RunAsClient
 	public void movePortletToTheTop(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		UserVO user = new UserRestClient(deploymentUrl).createRandomUser();
 		loginPage
 			.loginAs(user.getLogin(), user.getPassword());
@@ -426,6 +442,8 @@ public class UserTest {
 	@RunAsClient
 	public void browserBack(@InitialPage LoginPage loginPage)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser);
+		
 		Assume.assumeTrue(browser instanceof FirefoxDriver);
 		
 		loginPage
@@ -461,6 +479,8 @@ public class UserTest {
 	public void createUser(@InitialPage LoginPage loginPage,
 			@Drone @User WebDriver userBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, userBrowser);
+		
 		//login
 		loginPage
 			.assertOnLoginPage()
@@ -506,6 +526,8 @@ public class UserTest {
 	@RunAsClient
 	public void deleteUser(@InitialPage LoginPage loginPage,
 			@Drone @User WebDriver userBrowser) {
+		screenshotTestRule.setBrowsers(browser, userBrowser);
+		
 		//login
 		loginPage
 			.assertOnLoginPage()
@@ -566,6 +588,8 @@ public class UserTest {
 	public void importUsers(@InitialPage LoginPage loginPage,
 			@Drone @User WebDriver userBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, userBrowser);
+		
 		//login
 		loginPage
 			.assertOnLoginPage()
@@ -619,6 +643,7 @@ public class UserTest {
 			@Drone @User WebDriver existingUserBrowser,
 			@Drone @Student WebDriver newUserBrowser)
 	throws IOException, URISyntaxException {
+		screenshotTestRule.setBrowsers(browser, existingUserBrowser, newUserBrowser);
 
 		UserVO user1 = new UserRestClient(deploymentUrl)
 			.createRandomUser("tsukune");
diff --git a/src/test/java/org/olat/selenium/page/ScreenshotTestRule.java b/src/test/java/org/olat/selenium/page/ScreenshotTestRule.java
new file mode 100644
index 00000000000..cb102ee5c00
--- /dev/null
+++ b/src/test/java/org/olat/selenium/page/ScreenshotTestRule.java
@@ -0,0 +1,107 @@
+/**
+ * <a href="http://www.openolat.org">
+ * OpenOLAT - Online Learning and Training</a><br>
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); <br>
+ * you may not use this file except in compliance with the License.<br>
+ * You may obtain a copy of the License at the
+ * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
+ * <p>
+ * Unless required by applicable law or agreed to in writing,<br>
+ * software distributed under the License is distributed on an "AS IS" BASIS, <br>
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
+ * See the License for the specific language governing permissions and <br>
+ * limitations under the License.
+ * <p>
+ * Initial code contributed and copyrighted by<br>
+ * frentix GmbH, http://www.frentix.com
+ * <p>
+ */
+package org.olat.selenium.page;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.rules.MethodRule;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+import org.openqa.selenium.OutputType;
+import org.openqa.selenium.TakesScreenshot;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebDriverException;
+import org.openqa.selenium.remote.RemoteWebDriver;
+
+/**
+ * 
+ * 
+ * 
+ * Initial date: 15.12.2015<br>
+ * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
+ *
+ */
+public class  ScreenshotTestRule implements MethodRule {
+	
+	private List<WebDriver> browserList;
+	
+	public void setBrowsers(WebDriver... browsers) {
+		browserList = new ArrayList<>();
+		if(browsers != null && browsers.length > 0 && browsers[0] != null) {
+			for(WebDriver browser:browsers) {
+				if(browser != null) {
+					browserList.add(browser);
+				}
+			}
+		}
+	}
+	
+	
+	@Override
+    public Statement apply(final Statement statement, final FrameworkMethod frameworkMethod, final Object o) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                try {
+                    statement.evaluate();
+                } catch (Throwable t) {
+                    captureScreenshot(frameworkMethod.getName(), t);
+                    throw t; // rethrow to allow the failure to be reported to JUnit
+                }
+            }
+
+            public void captureScreenshot(String fileName, Throwable t) {
+            	List<WebDriver> toShootList = new ArrayList<>();
+            	if(t instanceof WebDriverException) {
+            		WebDriverException driverException = (WebDriverException)t;
+            		String infos = driverException.getAdditionalInformation();
+            		for(WebDriver browser:browserList) {
+            			if(browser instanceof RemoteWebDriver) {
+            				String sessionId = ((RemoteWebDriver)browser).getSessionId().toString();
+            				if(infos.contains(sessionId)) {
+            					toShootList.add(browser);
+            				}
+            			}
+            		}
+            	} 
+            	if(toShootList.isEmpty()) {
+            		toShootList.addAll(browserList);
+            	}
+            	
+                try {
+                	int count = 0;
+                	for(WebDriver browser:toShootList) {
+	                	if(browser instanceof TakesScreenshot) {
+		                    new File("target/surefire-reports/").mkdirs(); // Insure directory is there
+		                    FileOutputStream out = new FileOutputStream("target/surefire-reports/screenshot-" + fileName + "_" + (count++)+ ".png");
+		                    out.write(((TakesScreenshot) browser).getScreenshotAs(OutputType.BYTES));
+		                    out.close();
+                		}
+                	}
+                } catch (Exception e) {
+                    // No need to crash the tests if the screenshot fails
+                }
+            }
+        };
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/org/olat/selenium/page/repository/FeedPage.java b/src/test/java/org/olat/selenium/page/repository/FeedPage.java
index d65d20ea087..49f9e9b47ec 100644
--- a/src/test/java/org/olat/selenium/page/repository/FeedPage.java
+++ b/src/test/java/org/olat/selenium/page/repository/FeedPage.java
@@ -41,14 +41,12 @@ public class FeedPage {
 
 	public static final By newExternalFeedBy = By.className("o_feed");
 	
-
-	private WebDriver browser;
+	private final WebDriver browser;
 	
 	public FeedPage(WebDriver browser) {
 		this.browser = browser;
 	}
 	
-	
 	public static FeedPage getFeedPage(WebDriver browser) {
 		OOGraphene.waitElement(feedBy, browser);
 		return new FeedPage(browser);
@@ -98,8 +96,11 @@ public class FeedPage {
 	private FeedPage newExternalFeed(By configureExternalButton, String url) {
 		browser.findElement(configureExternalButton).click();
 		OOGraphene.waitBusy(browser);
+		By popupBy = By.cssSelector("div.modal-dialog");
+		OOGraphene.waitElement(popupBy, 5, browser);
+		
 		//fill the URL input field
-		By urlField = By.xpath("(//div[contains(@class,'modal-body')]//form//input[@type='text'])[2]");
+		By urlField = By.cssSelector("div.modal-dialog div.o_sel_feed_url input[type='text']");
 		WebElement urlEl = browser.findElement(urlField);
 		urlEl.sendKeys(url);
 		
-- 
GitLab