From fec6568d0c603b59bb0c448313a51f9c8c4179b6 Mon Sep 17 00:00:00 2001
From: srosse <stephane.rosse@frentix.com>
Date: Fri, 10 Jan 2020 08:24:22 +0100
Subject: [PATCH] no-jira: update selenium tests for the new switch roles in
 course

---
 .../ui/RepositoryEntryRuntimeController.java  |  2 +-
 .../org/olat/selenium/AssessmentTest.java     |  2 ++
 .../java/org/olat/selenium/CourseTest.java    |  7 +++++
 .../java/org/olat/selenium/ImsQTI21Test.java  | 12 +++++++--
 .../page/course/CoursePageFragment.java       | 26 +++++++++++++++++++
 5 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/olat/repository/ui/RepositoryEntryRuntimeController.java b/src/main/java/org/olat/repository/ui/RepositoryEntryRuntimeController.java
index 2bdbbb4c140..75d0a24bda6 100644
--- a/src/main/java/org/olat/repository/ui/RepositoryEntryRuntimeController.java
+++ b/src/main/java/org/olat/repository/ui/RepositoryEntryRuntimeController.java
@@ -383,7 +383,7 @@ public class RepositoryEntryRuntimeController extends MainLayoutBasicController
 	
 	private void initRole() {
 		rolesDropdown = new Dropdown("toolbox.roles", "role.switch", false, getTranslator());
-		rolesDropdown.setElementCssClass("o_with_labeled");
+		rolesDropdown.setElementCssClass("o_sel_switch_role o_with_labeled");
 		rolesDropdown.setIconCSS("o_icon " + getCurrentRoleIcon());
 		rolesDropdown.setInnerText(translate("role." + reSecurity.getCurrentRole()));
 		rolesDropdown.setInnerCSS("o_labeled");
diff --git a/src/test/java/org/olat/selenium/AssessmentTest.java b/src/test/java/org/olat/selenium/AssessmentTest.java
index 7c2c403bc2b..25440e41db1 100644
--- a/src/test/java/org/olat/selenium/AssessmentTest.java
+++ b/src/test/java/org/olat/selenium/AssessmentTest.java
@@ -34,6 +34,7 @@ import org.jboss.arquillian.test.api.ArquillianResource;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.olat.repository.model.SingleRoleRepositoryEntrySecurity.Role;
 import org.olat.selenium.page.LoginPage;
 import org.olat.selenium.page.NavigationPage;
 import org.olat.selenium.page.Participant;
@@ -148,6 +149,7 @@ public class AssessmentTest extends Deployments {
 			.selectResource(courseTitle);
 		
 		course
+			.switchRole(Role.participant)
 			.clickTree()
 			.selectWithTitle(testNodeTitle);
 		
diff --git a/src/test/java/org/olat/selenium/CourseTest.java b/src/test/java/org/olat/selenium/CourseTest.java
index d2254ee4651..44073963487 100644
--- a/src/test/java/org/olat/selenium/CourseTest.java
+++ b/src/test/java/org/olat/selenium/CourseTest.java
@@ -247,6 +247,13 @@ public class CourseTest extends Deployments {
 			.nextCatalog()
 			.finish();
 		OOGraphene.closeBlueMessageWindow(browser);
+		
+		RepositorySettingsPage settings = new RepositorySettingsPage(browser);
+		//from description editor, back to details and launch the course
+		settings
+			.assertOnInfos();
+		settings	
+			.back();
 
 		//open course editor
 		CoursePageFragment course = CoursePageFragment.getCourse(browser);
diff --git a/src/test/java/org/olat/selenium/ImsQTI21Test.java b/src/test/java/org/olat/selenium/ImsQTI21Test.java
index 7c87f92ca21..aac8c62a4cc 100644
--- a/src/test/java/org/olat/selenium/ImsQTI21Test.java
+++ b/src/test/java/org/olat/selenium/ImsQTI21Test.java
@@ -33,6 +33,7 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.olat.ims.qti21.QTI21AssessmentResultsOptions;
+import org.olat.repository.model.SingleRoleRepositoryEntrySecurity.Role;
 import org.olat.selenium.page.LoginPage;
 import org.olat.selenium.page.NavigationPage;
 import org.olat.selenium.page.User;
@@ -610,6 +611,7 @@ public class ImsQTI21Test extends Deployments {
 			.selectResource(courseTitle);
 		
 		course
+			.switchRole(Role.participant)
 			.clickTree()
 			.selectWithTitle(testNodeTitle);
 		
@@ -716,6 +718,7 @@ public class ImsQTI21Test extends Deployments {
 			.selectResource(courseTitle);
 		
 		course
+			.switchRole(Role.participant)
 			.clickTree()
 			.selectWithTitle(testNodeTitle);
 		
@@ -831,15 +834,16 @@ public class ImsQTI21Test extends Deployments {
 			.selectResource(courseTitle);
 		
 		course
+			.switchRole(Role.participant)
 			.clickTree()
 			.selectWithTitle(testNodeTitle);
 		
 		//check that the title of the start page of test is correct
 		WebElement testH2 = browser.findElement(By.cssSelector("div.o_course_run h2"));
 		Assert.assertEquals(testNodeTitle, testH2.getText().trim());
-		
+
 		QTI21Page qtiPage = QTI21Page
-				.getQTI21Page(browser);
+			.getQTI21Page(browser);
 		qtiPage
 			.assertOnStart()
 			.start()
@@ -856,6 +860,10 @@ public class ImsQTI21Test extends Deployments {
 		authorLoginPage
 			.loginAs(author.getLogin(), author.getPassword())
 			.resume();
+		
+		course
+			.switchRole(Role.participant);
+	
 		//resume the course, resume the test
 		qtiPage = QTI21Page
 				.getQTI21Page(browser);
diff --git a/src/test/java/org/olat/selenium/page/course/CoursePageFragment.java b/src/test/java/org/olat/selenium/page/course/CoursePageFragment.java
index 3589a5ec017..a45dcb328a4 100644
--- a/src/test/java/org/olat/selenium/page/course/CoursePageFragment.java
+++ b/src/test/java/org/olat/selenium/page/course/CoursePageFragment.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.junit.Assert;
 import org.olat.repository.RepositoryEntryStatusEnum;
+import org.olat.repository.model.SingleRoleRepositoryEntrySecurity.Role;
 import org.olat.restapi.support.vo.CourseVO;
 import org.olat.selenium.page.core.BookingPage;
 import org.olat.selenium.page.core.MenuTreePageFragment;
@@ -297,6 +298,31 @@ public class CoursePageFragment {
 		return this;
 	}
 	
+	public CoursePageFragment switchRole(Role role) {
+		String cssRole;
+		switch(role) {
+			case participant: cssRole = "o_icon_user"; break;
+			case coach: cssRole = "o_icon_coach"; break;
+			case owner: cssRole = "o_icon_owner"; break;
+			default: cssRole = "o_icon_unkown"; break;
+		}
+		
+		By statusMenuBy = By.cssSelector("ul.o_sel_switch_role");
+		if(!browser.findElement(statusMenuBy).isDisplayed()) {
+			By statusMenuCaret = By.cssSelector("a.o_sel_switch_role");
+			browser.findElement(statusMenuCaret).click();
+			OOGraphene.waitElement(statusMenuBy, browser);
+		}
+		
+		By statusBy = By.cssSelector("ul.o_sel_switch_role>li>a>i." + cssRole);
+		browser.findElement(statusBy).click();
+		OOGraphene.waitBusy(browser);
+		
+		By statusViewBy = By.xpath("//li[contains(@class,'o_tool_dropdown')]/a[contains(@class,'o_sel_switch_role')]/span/i[contains(@class,'" + cssRole + "')]");
+		OOGraphene.waitElement(statusViewBy, browser);
+		return this;
+	}
+	
 	
 	/**
 	 * Close the course
-- 
GitLab