diff --git a/pom.xml b/pom.xml index 785c27df22e4e3dce8ae469c103d6a7762eb6f72..1c69667038c009bcede49ade938f58792b91d415 100644 --- a/pom.xml +++ b/pom.xml @@ -1115,12 +1115,7 @@ <arquillian.launch>tomcat-7-managed</arquillian.launch> </systemProperties> <testNGArtifactName>none:none</testNGArtifactName> - <!-- commented out because surefire plugin doesn't understand @Suite annotation of JUnit and openolat won't undeploy. - <includes> - <include>org/olat/test/Selenium2TestsJunit4.java</include> - </includes> - --> - <test>**/Functional*Test.java</test> + <test>org/olat/selenium/*Test.java</test> </configuration> </plugin> </plugins> @@ -2248,6 +2243,20 @@ <artifactId>arquillian-drone-selenium-server</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.jboss.arquillian.extension</groupId> + <artifactId>arquillian-drone-webdriver-depchain</artifactId> + <version>1.3.0.Final</version> + <type>pom</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.graphene</groupId> + <artifactId>graphene-webdriver</artifactId> + <version>2.0.3.Final</version> + <type>pom</type> + <scope>test</scope> + </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> diff --git a/src/main/java/org/olat/core/commons/contextHelp/ContextHelpComponent.java b/src/main/java/org/olat/core/commons/contextHelp/ContextHelpComponent.java index 07989533974b9d22a43119d09323c2e8e3196168..b4124915f14760dbcb5cbd4e38c71c0cc47cd6c3 100644 --- a/src/main/java/org/olat/core/commons/contextHelp/ContextHelpComponent.java +++ b/src/main/java/org/olat/core/commons/contextHelp/ContextHelpComponent.java @@ -1,6 +1,25 @@ -package org.olat.core.commons.contextHelp; /** * <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.core.commons.contextHelp; +/** + * OpenOLAT - Online Learning and Training</a><br> * <p> * Licensed under the Apache License, Version 2.0 (the "License"); <br> diff --git a/src/main/java/org/olat/core/commons/controllers/resume/ResumeController.java b/src/main/java/org/olat/core/commons/controllers/resume/ResumeController.java index 0b5773f9518c26cbcb634aeb822d0cdb16e70eed..ea513975a25d1a09fbc5200a2c9020dc5ef54e31 100644 --- a/src/main/java/org/olat/core/commons/controllers/resume/ResumeController.java +++ b/src/main/java/org/olat/core/commons/controllers/resume/ResumeController.java @@ -32,6 +32,7 @@ import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElem import org.olat.core.gui.components.form.flexible.impl.FormBasicController; import org.olat.core.gui.components.form.flexible.impl.FormEvent; import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; +import org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit; import org.olat.core.gui.components.link.Link; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; @@ -84,9 +85,12 @@ public class ResumeController extends FormBasicController implements SupportsAft // Button layout FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator()); formLayout.add(buttonLayout); - uifactory.addFormSubmitButton("submit", "resume.button", buttonLayout); + FormSubmit okButton = uifactory.addFormSubmitButton("submit", "resume.button", buttonLayout); + okButton.setElementCssClass("o_sel_resume_yes"); landingButton = uifactory.addFormLink("landing", "resume.button.landing", null, buttonLayout, Link.BUTTON); + landingButton.setElementCssClass("o_sel_resume_landing"); noButton = uifactory.addFormLink("cancel", "resume.button.cancel", null, buttonLayout, Link.BUTTON); + noButton.setElementCssClass("o_sel_resume_cancel"); } @Override diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/FormButtonRenderer.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/FormButtonRenderer.java index e6cd084488bdb08fd976ffee998f9691b8809cf2..cc43fa6793922779e90d0e7ac16e9e5b242359ce 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/FormButtonRenderer.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/FormButtonRenderer.java @@ -35,6 +35,7 @@ import org.olat.core.gui.render.RenderingState; import org.olat.core.gui.render.StringOutput; import org.olat.core.gui.render.URLBuilder; import org.olat.core.gui.translator.Translator; +import org.olat.core.util.StringHelper; /** * Description:<br> @@ -76,7 +77,11 @@ class FormButtonRenderer implements ComponentRenderer { } if(!source.isEnabled()){ sb.append(" o_disabled "); - } + } + if(StringHelper.containsNonWhitespace(fs.getElementCssClass())) { + sb.append(" ").append(fs.getElementCssClass()); + } + sb.append("\"><span>"); sb.append(fs.getTranslated()); sb.append("</span></button>"); diff --git a/src/main/java/org/olat/gui/control/OlatTopNavController.java b/src/main/java/org/olat/gui/control/OlatTopNavController.java index 7596bb5e01b9b4f6fe2baa1f87a3f1e8b3a7ba26..6208c97dee62cbefaf51fe5deb4dc0bb6e9fc926 100644 --- a/src/main/java/org/olat/gui/control/OlatTopNavController.java +++ b/src/main/java/org/olat/gui/control/OlatTopNavController.java @@ -240,6 +240,7 @@ public class OlatTopNavController extends BasicController implements GenericEven link.setCustomDisplayText(label); String iconCssClass = node.getIconCssClass(); link.setIconLeftCSS(iconCssClass); + link.setElementCssClass("o_sel_user_tools-" + gAe.getNavigationKey()); if(!StringHelper.containsNonWhitespace(gAe.getParentTreeNodeIdentifier())) { linksName.add(linkName); diff --git a/src/main/java/org/olat/gui/control/_content/topnav.html b/src/main/java/org/olat/gui/control/_content/topnav.html index d3dad9266d0a0ebcddf4b9d6f19d44570ca129ac..f3df184bcc52d5a93719863fc91e1cc79d81f6f3 100644 --- a/src/main/java/org/olat/gui/control/_content/topnav.html +++ b/src/main/java/org/olat/gui/control/_content/topnav.html @@ -5,8 +5,8 @@ #end #if (!$isGuest) <li id="o_navbar_my_menu" class="dropdown o_portrait"> - <a href="#" class="dropdown-toggle" data-toggle="dropdown"> - $r.render("portrait") + <a id="o_sel_navbar_my_menu_caret" href="#" class="dropdown-toggle" data-toggle="dropdown"> + $r.render("portrait") $myMenuLabel <b class="caret"></b> </a> diff --git a/src/main/java/org/olat/user/UserSettingsController.java b/src/main/java/org/olat/user/UserSettingsController.java index 2c5b6b0c065a2717e29151dab8aff0e9424b85ee..d4ed5343b02b8cb1535b453470212b96e3a3df85 100644 --- a/src/main/java/org/olat/user/UserSettingsController.java +++ b/src/main/java/org/olat/user/UserSettingsController.java @@ -74,17 +74,21 @@ public class UserSettingsController extends BasicController implements Activatea segmentView = SegmentViewFactory.createSegmentView("segments", mainVC, this); preferencesLink = LinkFactory.createLink("tab.prefs", mainVC, this); + preferencesLink.setElementCssClass("o_sel_user_settings_prefs"); segmentView.addSegment(preferencesLink, true); if(CoreSpringFactory.getImpl(WebDAVModule.class).isEnabled()) { webdavLink = LinkFactory.createLink("tab.pwdav", mainVC, this); + webdavLink.setElementCssClass("o_sel_user_settings_webdav"); segmentView.addSegment(webdavLink, false); } if(CoreSpringFactory.getImpl(InstantMessagingModule.class).isEnabled()){ imLink = LinkFactory.createLink("tab.im", mainVC, this); + imLink.setElementCssClass("o_sel_user_settings_im"); segmentView.addSegment(imLink, false); } if (CoreSpringFactory.getImpl(RegistrationModule.class).isDisclaimerEnabled()) { disclaimerLink = LinkFactory.createLink("tab.disclaimer", mainVC, this); + disclaimerLink.setElementCssClass("o_sel_user_settings_disclaimer"); segmentView.addSegment(disclaimerLink, false); } mainVC.put("segments", segmentView); diff --git a/src/test/java/org/olat/course/FunctionalBackTest.java b/src/test/java/org/olat/course/FunctionalBackTest.java deleted file mode 100644 index ddd0b925d1e1caaa7e3343e0c02257fa4c3cfeef..0000000000000000000000000000000000000000 --- a/src/test/java/org/olat/course/FunctionalBackTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * <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.course; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.List; - -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.drone.api.annotation.Drone; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.olat.restapi.support.vo.CourseVO; -import org.olat.test.ArquillianDeployments; -import org.olat.user.restapi.UserVO; -import org.olat.util.FunctionalCourseUtil; -import org.olat.util.FunctionalHomeSiteUtil; -import org.olat.util.FunctionalRepositorySiteUtil; -import org.olat.util.FunctionalUtil; -import org.olat.util.FunctionalUtil.OlatSite; -import org.olat.util.FunctionalVOUtil; - -import com.thoughtworks.selenium.DefaultSelenium; - -/** - * - * @author jkraehemann, joel.kraehemann@frentix.com, frentix.com - */ -@Ignore("no tests to run within this class, yet.") -@RunWith(Arquillian.class) -public class FunctionalBackTest { - @Deployment(testable = false) - public static WebArchive createDeployment() { - return ArquillianDeployments.createDeployment(); - } - - @Drone - DefaultSelenium browser; - - @ArquillianResource - URL deploymentUrl; - - FunctionalUtil functionalUtil; - FunctionalVOUtil functionalVOUtil; - FunctionalHomeSiteUtil functionalHomeSiteUtil; - FunctionalRepositorySiteUtil functionalRepositorySiteUtil; - FunctionalCourseUtil functionalCourseUtil; - - UserVO user; - - @Before - public void setup() throws IOException, URISyntaxException{ - functionalUtil = new FunctionalUtil(); - functionalUtil.setDeploymentUrl(deploymentUrl.toString()); - - functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword()); - functionalHomeSiteUtil = functionalUtil.getFunctionalHomeSiteUtil(); - functionalRepositorySiteUtil = functionalUtil.getFunctionalRepositorySiteUtil(); - functionalCourseUtil = functionalRepositorySiteUtil.getFunctionalCourseUtil(); - - /* create test user with REST */ - List<UserVO> userVO = functionalVOUtil.createTestUsers(deploymentUrl, 1); - - user = userVO.get(0); - } - - @Ignore - @Test - @RunAsClient - public void checkBack() throws URISyntaxException, IOException{ - /* deploy course with rest */ - CourseVO course0 = functionalVOUtil.importAllElementsCourse(deploymentUrl); - CourseVO course1 = functionalVOUtil.importAllElementsCourse(deploymentUrl); - - functionalUtil.login(browser, user.getLogin(), user.getPassword(), true); - - /* start - home site */ - functionalUtil.openSite(browser, OlatSite.HOME); - - //functionalUtil.openSite(browser,) - - //TODO:JK: implement me - } -} diff --git a/src/test/java/org/olat/course/nodes/feed/FunctionalBlogTest.java b/src/test/java/org/olat/course/nodes/feed/FunctionalBlogTest.java index 0c37585e44cfc38eaf4b657a7b313acfea131220..ec079464873689ec155aea16157605d23746d12d 100644 --- a/src/test/java/org/olat/course/nodes/feed/FunctionalBlogTest.java +++ b/src/test/java/org/olat/course/nodes/feed/FunctionalBlogTest.java @@ -168,13 +168,6 @@ public class FunctionalBlogTest { Assert.assertTrue(functionalUtil.logout(browser)); } - @Ignore - @Test - @RunAsClient - public void checkDelete(){ - //TODO:JK: implement me - } - @Test @RunAsClient public void checkConcurrentClearCache(@Drone @Tutor1 DefaultSelenium tutor0, @Drone @Student1 DefaultSelenium student0) throws IOException, URISyntaxException{ diff --git a/src/test/java/org/olat/login/FunctionalLoginTest.java b/src/test/java/org/olat/login/FunctionalLoginTest.java deleted file mode 100644 index 77d2b9527c19e4dde35ba4085e1bd1ecb90f1b67..0000000000000000000000000000000000000000 --- a/src/test/java/org/olat/login/FunctionalLoginTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * <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.login; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.UUID; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriBuilder; - -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.util.EntityUtils; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.drone.api.annotation.Drone; -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.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.olat.restapi.RestConnection; -import org.olat.test.ArquillianDeployments; -import org.olat.user.restapi.UserVO; -import org.olat.util.FunctionalUtil; -import org.olat.util.FunctionalVOUtil; - -import com.thoughtworks.selenium.DefaultSelenium; - -/** - * - * - * - * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com - */ -@RunWith(Arquillian.class) -public class FunctionalLoginTest { - - @Deployment(testable = false) - public static WebArchive createDeployment() { - return ArquillianDeployments.createDeployment(); - } - - @Drone - DefaultSelenium browser; - - @ArquillianResource - URL deploymentUrl; - - static FunctionalUtil functionalUtil; - static FunctionalVOUtil functionalVOUtil; - - static boolean initialized = false; - - @Before - public void setup() { - /*try { - deploymentUrl = new URL("http", "localhost", 8080, "/olat/"); - browser = new DefaultSelenium("127.0.0.1", 4444, "*googlechrome", "http://localhost:8080/olat/"); - browser.start(); - } catch (MalformedURLException e) { - e.printStackTrace(); - }*/ - - if(!initialized) { - functionalUtil = new FunctionalUtil(); - functionalUtil.setDeploymentUrl(deploymentUrl.toString()); - functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword()); - - initialized = true; - } - } - - @Test - @RunAsClient - public void loadIndex() { - browser.open(deploymentUrl + "dmz"); - browser.waitForPageToLoad("5000"); - boolean isLoginFormPresent = browser.isElementPresent("xpath=//div[@class='o_login_form']"); - Assert.assertTrue(isLoginFormPresent); - } - - @Test - @RunAsClient - public void loadLogin() throws IOException, URISyntaxException { - /* create user */ - int userCount = 1; - - final UserVO[] users = new UserVO[userCount]; - functionalVOUtil.createTestUsers(deploymentUrl, userCount).toArray(users); - - /* login */ - Assert.assertTrue(functionalUtil.login(browser, users[0].getLogin(), users[0].getPassword(), true)); - - //check if administrator appears in the footer - boolean loginAs = functionalUtil.waitForPageToLoadElement(browser, "xpath=//div[@id='b_footer_user']//i[contains(text(), '" + users[0].getLastName() + ", " + users[0].getFirstName() + "')]"); - if(!loginAs) { - boolean acknowledge = browser.isElementPresent("xpath=//input[@name='acknowledge_checkbox']"); - Assert.assertTrue("Acknowledge first!", acknowledge); - browser.click("name=acknowledge_checkbox"); - } - } - - @Test - @RunAsClient - public void loginWithRandomUser() throws IOException, URISyntaxException{ - RestConnection restConnection = new RestConnection(deploymentUrl); - - Assert.assertTrue(restConnection.login(functionalUtil.getUsername(), functionalUtil.getPassword())); - - UserVO vo = new UserVO(); - String username = UUID.randomUUID().toString(); - vo.setLogin(username); - String password = UUID.randomUUID().toString(); - vo.setPassword(password); - vo.setFirstName("John"); - vo.setLastName("Smith"); - vo.setEmail(username + "@frentix.com"); - vo.putProperty("telOffice", "39847592"); - vo.putProperty("telPrivate", "39847592"); - vo.putProperty("telMobile", "39847592"); - vo.putProperty("gender", "Female");//male or female - vo.putProperty("birthDay", "12/12/2009"); - - URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("users").build(); - HttpPut method = restConnection.createPut(request, MediaType.APPLICATION_JSON, true); - restConnection.addJsonEntity(method, vo); - method.addHeader("Accept-Language", "en"); - - HttpResponse response = restConnection.execute(method); - assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201); - EntityUtils.consume(response.getEntity()); - - functionalUtil.setDeploymentUrl(deploymentUrl.toString()); - Assert.assertTrue(functionalUtil.login(browser, username, password, true)); - - restConnection.shutdown(); - } -} diff --git a/src/test/java/org/olat/login/FunctionalResumeTest.java b/src/test/java/org/olat/login/FunctionalResumeTest.java deleted file mode 100644 index 2647dcc5c4b513311231543bbe4fb15970a7d214..0000000000000000000000000000000000000000 --- a/src/test/java/org/olat/login/FunctionalResumeTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * <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.login; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; - -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.drone.api.annotation.Drone; -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.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.olat.restapi.support.vo.CourseVO; -import org.olat.test.ArquillianDeployments; -import org.olat.util.FunctionalCourseUtil; -import org.olat.util.FunctionalHomeSiteUtil; -import org.olat.util.FunctionalRepositorySiteUtil; -import org.olat.util.FunctionalUtil; -import org.olat.util.FunctionalUtil.OlatSite; -import org.olat.util.FunctionalVOUtil; - -import com.thoughtworks.selenium.DefaultSelenium; - -/** - * - * @author jkraehemann, joel.kraehemann@frentix.com, frentix.com - */ -@RunWith(Arquillian.class) -public class FunctionalResumeTest { - - - - @Deployment(testable = false) - public static WebArchive createDeployment() { - return ArquillianDeployments.createDeployment(); - } - - @Drone - DefaultSelenium browser; - - @ArquillianResource - URL deploymentUrl; - - FunctionalUtil functionalUtil; - FunctionalVOUtil functionalVOUtil; - FunctionalHomeSiteUtil functionalHomeSiteUtil; - FunctionalRepositorySiteUtil functionalRepositorySiteUtil; - FunctionalCourseUtil functionalCourseUtil; - - @Before - public void setup(){ - functionalUtil = new FunctionalUtil(); - functionalUtil.setDeploymentUrl(deploymentUrl.toString()); - - functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword()); - functionalHomeSiteUtil = functionalUtil.getFunctionalHomeSiteUtil(); - functionalRepositorySiteUtil = functionalUtil.getFunctionalRepositorySiteUtil(); - functionalCourseUtil = functionalRepositorySiteUtil.getFunctionalCourseUtil(); - } - - @Test - @RunAsClient - public void checkResume() throws IOException, URISyntaxException{ - /* deploy course with rest */ - CourseVO course = functionalVOUtil.importAllElementsCourse(deploymentUrl); - - /* create xpath to check if course is open */ - StringBuffer selectorBuffer = new StringBuffer(); - - selectorBuffer.append("xpath=//li[contains(@class, 'b_resource_CourseModule')]") - .append("//a[@title='") - .append(functionalVOUtil.getAllElementsCourseDisplayname()) - .append("']"); - - String courseXPath = selectorBuffer.toString(); - - /* login */ - Assert.assertTrue(functionalUtil.login(browser)); - - /* enable resume */ - functionalHomeSiteUtil.enableResume(browser); - - /* open course and check if it's open */ - Assert.assertTrue(functionalUtil.openSite(browser, OlatSite.LEARNING_RESOURCES)); - Assert.assertTrue(functionalRepositorySiteUtil.openCourse(browser, course.getRepoEntryKey())); - - /* - * There's a need to click something in the course because - * else it won't open up again after resume. - */ - functionalCourseUtil.openWithoutBusinessPath(browser, course.getRepoEntryKey(), 0); - - Assert.assertTrue(browser.isElementPresent(courseXPath)); - - /* logout */ - Assert.assertTrue(functionalUtil.logout(browser)); - - /* login */ - Assert.assertTrue(functionalUtil.login(browser, false)); - - /* check if we are on open course tab */ - Assert.assertTrue(browser.isElementPresent(courseXPath)); - - /* enable resume on request */ - functionalHomeSiteUtil.enableResumeOnRequest(browser); - - /* - * There's a need to click something in the course because - * else it won't open up again after resume. - */ - functionalCourseUtil.openWithoutBusinessPath(browser, course.getRepoEntryKey(), 4); - - Assert.assertTrue(functionalUtil.logout(browser)); - - /* login without clicking away dialogs */ - Assert.assertTrue(functionalUtil.login(browser, false)); - - /* Yes to resume last session */ - browser.click("xpath=//form//button"); - functionalUtil.waitForPageToLoad(browser); - - /* check if we are on open course tab */ - Assert.assertTrue(browser.isElementPresent(courseXPath)); - } -} diff --git a/src/test/java/org/olat/restapi/RestConnection.java b/src/test/java/org/olat/restapi/RestConnection.java index 2e15fb5bce5d7174285838c58887557ca98f92e5..f2ca86bb170d097823974f12b6500c12dbed64a2 100644 --- a/src/test/java/org/olat/restapi/RestConnection.java +++ b/src/test/java/org/olat/restapi/RestConnection.java @@ -152,7 +152,7 @@ public class RestConnection { public void shutdown() { IOUtils.closeQuietly(httpclient); } - + public boolean login(String username, String password) throws IOException, URISyntaxException { URI uri = getContextURI().path("auth").path(username).queryParam("password", password).build(); diff --git a/src/test/java/org/olat/selenium/LoginTest.java b/src/test/java/org/olat/selenium/LoginTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5a567e3f52e94ce5b5c49df5a258bdb4ac707e16 --- /dev/null +++ b/src/test/java/org/olat/selenium/LoginTest.java @@ -0,0 +1,106 @@ +/** + * <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; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.drone.api.annotation.Drone; +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.Test; +import org.junit.runner.RunWith; +import org.olat.selenium.page.LoginPage; +import org.olat.test.ArquillianDeployments; +import org.olat.test.rest.UserRestClient; +import org.olat.user.restapi.UserVO; +import org.openqa.selenium.WebDriver; + +/** + * + * Initial date: 19.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +@RunWith(Arquillian.class) +public class LoginTest { + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return ArquillianDeployments.createDeployment(); + } + + @Drone + private WebDriver browser; + @ArquillianResource + private URL deploymentUrl; + + /** + * Test if the dmz can be loaded. + * @param loginPage + */ + @Test + @RunAsClient + public void loadIndex(@InitialPage LoginPage loginPage) { + //check that the login page, or dmz is loaded + loginPage.assertOnLoginPage(); + } + + /** + * Test login as administrator. + * + * @param loginPage + */ + @Test + @RunAsClient + public void loginAsAdministrator(@InitialPage LoginPage loginPage) { + //load dmz + loginPage.assertOnLoginPage(); + //login as administrator + loginPage.loginAs("administrator", "openolat"); + } + + /** + * + * Create a new user and try to login with its credentials. + * + * @param loginPage + * @throws IOException + * @throws URISyntaxException + */ + @Test + @RunAsClient + public void loginAsNewUser(@InitialPage LoginPage loginPage) + throws IOException, URISyntaxException { + //create a random user + UserRestClient userClient = new UserRestClient(deploymentUrl); + UserVO user = userClient.createTestUser(); + + //load dmz + loginPage.assertOnLoginPage(); + //login + loginPage.loginAs(user.getLogin(), user.getPassword()); + } +} diff --git a/src/test/java/org/olat/selenium/ResumeTest.java b/src/test/java/org/olat/selenium/ResumeTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e4cc7721cb3514728de5d0e7d55195028ea86fd1 --- /dev/null +++ b/src/test/java/org/olat/selenium/ResumeTest.java @@ -0,0 +1,169 @@ +/** + * <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; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.graphene.page.InitialPage; +import org.jboss.arquillian.graphene.page.Page; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jcodec.common.Assert; +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.course.CoursePageFragment; +import org.olat.selenium.page.user.UserPreferencesPageFragment.ResumeOption; +import org.olat.selenium.page.user.UserToolsPage; +import org.olat.test.ArquillianDeployments; +import org.olat.test.rest.RepositoryRestClient; +import org.olat.test.rest.UserRestClient; +import org.olat.user.restapi.UserVO; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +/** + * + * Initial date: 19.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +@RunWith(Arquillian.class) +public class ResumeTest { + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return ArquillianDeployments.createDeployment(); + } + + @Drone + private WebDriver browser; + @ArquillianResource + private URL deploymentUrl; + + @Page + private UserToolsPage userTools; + + /** + * Set the resume preferences to automatically resume the session, + * open a course, log out, log in and check if the course is resumed. + * + * @param loginPage + * @throws IOException + * @throws URISyntaxException + */ + @Test + public void resumeCourseAutomatically(@InitialPage LoginPage loginPage) + throws IOException, URISyntaxException { + //create a random user + UserVO user = new UserRestClient(deploymentUrl).createTestUser(); + //deploy a course + CourseVO course = new RepositoryRestClient(deploymentUrl).deployDemoCourse(); + + //login + loginPage + .assertOnLoginPage() + .loginAs(user.getLogin(), user.getPassword()); + + //set the preferences to resume automatically + userTools + .assertOnUserTools() + .openUserToolsMenu() + .openMySettings() + .assertOnUserSettings() + .openPreferences() + .assertOnUserPreferences() + .setResume(ResumeOption.auto); + + //open a course via REST url + CoursePageFragment coursePage = CoursePageFragment.getCourse(browser, deploymentUrl, course); + coursePage + .assertOnCoursePage() + .clickTree(); + + //logout + userTools.logout(); + + //login again + loginPage + .assertOnLoginPage() + .loginAs(user.getLogin(), user.getPassword()); + + //check the title of the course if any + WebElement courseTitle = browser.findElement(By.tagName("h2")); + Assert.assertNotNull(courseTitle); + Assert.assertTrue(courseTitle.isDisplayed()); + Assert.assertTrue(courseTitle.getText().contains(course.getTitle())); + } + + /** + * Set the resume preferences to resume the session on request, + * open a course, log out, log in, resume the session and check + * if the course is resumed. + * + * @param loginPage + * @throws IOException + * @throws URISyntaxException + */ + @Test + public void resumeCourseOnDemand(@InitialPage LoginPage loginPage) + throws IOException, URISyntaxException { + //create a random user + UserVO user = new UserRestClient(deploymentUrl).createTestUser(); + //deploy a course + CourseVO course = new RepositoryRestClient(deploymentUrl).deployDemoCourse(); + + //login + loginPage.loginAs(user.getLogin(), user.getPassword()); + + //set the preferences to resume automatically + userTools + .openUserToolsMenu() + .openMySettings() + .openPreferences() + .setResume(ResumeOption.ondemand); + + //open a course via REST url and click it + CoursePageFragment.getCourse(browser, deploymentUrl, course).clickTree(); + + //logout + userTools.logout(); + + //login again + loginPage + .assertOnLoginPage() + .loginAs(user.getLogin(), user.getPassword()); + //resume + loginPage.resumeWithAssert(); + + //check the title of the course if any + WebElement courseTitle = browser.findElement(By.tagName("h2")); + Assert.assertNotNull(courseTitle); + Assert.assertTrue(courseTitle.isDisplayed()); + Assert.assertTrue(courseTitle.getText().contains(course.getTitle())); + } +} diff --git a/src/test/java/org/olat/util/browser/Browser2.java b/src/test/java/org/olat/selenium/page/BusyPredicate.java similarity index 56% rename from src/test/java/org/olat/util/browser/Browser2.java rename to src/test/java/org/olat/selenium/page/BusyPredicate.java index 0599cd2df903477d224b2780188721b089abfc0a..bce4862b95e962f05e27781472ec5990d835068b 100644 --- a/src/test/java/org/olat/util/browser/Browser2.java +++ b/src/test/java/org/olat/selenium/page/BusyPredicate.java @@ -17,22 +17,28 @@ * frentix GmbH, http://www.frentix.com * <p> */ -package org.olat.util.browser; +package org.olat.selenium.page; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.jboss.arquillian.drone.api.annotation.Qualifier; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; + +import com.google.common.base.Predicate; /** * - * @author jkraehemann, joel.kraehemann@frentix.com, frentix.com + * Predicate which test the busy flag used to lock the + * OpenOLAT GUI after a link is clicked. + * + * Initial date: 20.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.FIELD, ElementType.PARAMETER }) -@Qualifier -public @interface Browser2 { - +public class BusyPredicate implements Predicate<WebDriver> { + + @Override + public boolean apply(WebDriver driver) { + Object busy = ((JavascriptExecutor)driver) + .executeScript("return window.o_info.linkbusy"); + return Boolean.FALSE.equals(busy); + } } diff --git a/src/test/java/org/olat/selenium/page/LoginPage.java b/src/test/java/org/olat/selenium/page/LoginPage.java new file mode 100644 index 0000000000000000000000000000000000000000..6fdd1646d8d85edaac1e37a804f10633ffef8589 --- /dev/null +++ b/src/test/java/org/olat/selenium/page/LoginPage.java @@ -0,0 +1,121 @@ +/** + * <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.util.List; + +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.graphene.Graphene; +import org.jboss.arquillian.graphene.page.Location; +import org.jcodec.common.Assert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * The login page, annoted to be used as @InitialPage + * + * + * Initial date: 19.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +@Location("dmz") +public class LoginPage { + + public static final String loginFormClassName = "o_login_form"; + public static final String loginFormXPath = "//div[contains(@class,'o_login_form')]"; + + public static final String usernameId = "o_fiooolat_login_name"; + public static final String passwordId = "o_fiooolat_login_pass"; + public static final String loginButtonId = "o_fiooolat_login_button"; + public static final String footerUserDivXPath = "//div[@id='o_footer_user']"; + public static final String acknowledgeCheckboxXPath = "//input[@name='acknowledge_checkbox']"; + + public static final By authXPath = By.xpath(footerUserDivXPath); + public static final By loginFormBy = By.xpath(loginFormXPath); + public static final By authOrDisclaimerXPath = By.xpath(footerUserDivXPath + "|" + acknowledgeCheckboxXPath); + public static final By disclaimerXPath = By.xpath(acknowledgeCheckboxXPath); + public static final By disclaimerButtonXPath = By.xpath("//div[contains(@class,'o_sel_disclaimer_buttons')]/button"); + + public static final By resumeButton = By.className("o_sel_resume_yes"); + + @FindBy(className = loginFormClassName) + private WebElement loginDiv; + @FindBy(xpath = loginFormXPath) + private WebElement loginDivXPath; + + @FindBy(id = usernameId) + private WebElement usernameInput; + @FindBy(id = passwordId) + private WebElement passwordInput; + @FindBy(id = loginButtonId) + private WebElement loginButton; + + @Drone + private WebDriver browser; + + public LoginPage assertOnLoginPage() { + Assert.assertNotNull(loginDiv); + Assert.assertNotNull(loginDivXPath); + + Assert.assertTrue(loginDiv.isDisplayed()); + Assert.assertTrue(loginDivXPath.isDisplayed()); + return this; + } + + /** + * Login and accept the disclaimer if there is one. + * + * @param username + * @param password + */ + public void loginAs(String username, String password) { + usernameInput.sendKeys(username); + passwordInput.sendKeys(password); + + Graphene.guardHttp(loginButton).click(); + Graphene.waitModel().until().element(authOrDisclaimerXPath).is().present(); + + List<WebElement> disclaimer = browser.findElements(disclaimerXPath); + if(disclaimer.size() > 0) { + //click the disclaimer + disclaimer.get(0).click(); + + WebElement acknowledgeButton = browser.findElement(disclaimerButtonXPath); + Graphene.guardHttp(acknowledgeButton).click(); + Graphene.waitModel().until().element(authXPath).is().present(); + } + } + + /** + * Resume the session, and assert that the resume panel has popped + */ + public void resumeWithAssert() { + WebElement resume = browser.findElement(resumeButton); + Assert.assertNotNull(resume); + Assert.assertTrue(resume.isDisplayed()); + + resume.click(); + Graphene.waitModel().until(new BusyPredicate()); + } +} diff --git a/src/test/java/org/olat/selenium/page/core/MenuTreePageFragment.java b/src/test/java/org/olat/selenium/page/core/MenuTreePageFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..4a13c476413dc2575aebe9c9885b2781180076cb --- /dev/null +++ b/src/test/java/org/olat/selenium/page/core/MenuTreePageFragment.java @@ -0,0 +1,59 @@ +/** + * <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.core; + +import java.util.List; + +import org.jboss.arquillian.graphene.Graphene; +import org.junit.Assert; +import org.olat.selenium.page.BusyPredicate; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * Fragment which contains the menu tree. The WebElement to create + * this fragment must be a parent of the div.o_tree + * + * Initial date: 20.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class MenuTreePageFragment { + + @FindBy(className="o_tree") + private WebElement tree; + + /** + * Click the root link in the tree. + * + * @return The menu page fragment + */ + public MenuTreePageFragment selectRoot() { + List<WebElement> rootLinks = tree.findElements(By.cssSelector("a.o_tree_link")); + Assert.assertNotNull(rootLinks); + Assert.assertFalse(rootLinks.isEmpty()); + + rootLinks.get(0).click(); + Graphene.waitModel().until(new BusyPredicate()); + return this; + } + +} diff --git a/src/test/java/org/olat/selenium/page/course/CoursePageFragment.java b/src/test/java/org/olat/selenium/page/course/CoursePageFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..e98d7c47923f9baf1fa73c09e2f81ee96a4f08cd --- /dev/null +++ b/src/test/java/org/olat/selenium/page/course/CoursePageFragment.java @@ -0,0 +1,68 @@ +/** + * <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.course; + +import java.net.URL; + +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.graphene.Graphene; +import org.junit.Assert; +import org.olat.restapi.support.vo.CourseVO; +import org.olat.selenium.page.core.MenuTreePageFragment; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * + * Initial date: 20.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class CoursePageFragment { + + public static final By courseRun = By.className("o_course_run"); + + @Drone + private WebDriver browser; + + @FindBy(id="o_main_left_content") + private WebElement treeContainer; + + public static CoursePageFragment getCourse(WebDriver browser, URL deploymentUrl, CourseVO course) { + browser.navigate().to(deploymentUrl.toExternalForm() + "url/RepositoryEntry/" + course.getRepoEntryKey()); + Graphene.waitModel().until().element(courseRun).is().visible(); + WebElement main = browser.findElement(By.id("o_main")); + return Graphene.createPageFragment(CoursePageFragment.class, main); + } + + public CoursePageFragment assertOnCoursePage() { + Assert.assertTrue(treeContainer.isDisplayed()); + return this; + } + + public CoursePageFragment clickTree() { + MenuTreePageFragment menuTree = Graphene.createPageFragment(MenuTreePageFragment.class, treeContainer); + menuTree.selectRoot(); + return this; + } + +} diff --git a/src/test/java/org/olat/selenium/page/user/UserPreferencesPageFragment.java b/src/test/java/org/olat/selenium/page/user/UserPreferencesPageFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..5b21194e5906cad5c4cc745d3abf97f0a1b5d5c9 --- /dev/null +++ b/src/test/java/org/olat/selenium/page/user/UserPreferencesPageFragment.java @@ -0,0 +1,98 @@ +/** + * <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.user; + +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.graphene.Graphene; +import org.jcodec.common.Assert; +import org.olat.selenium.page.BusyPredicate; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * The user system preferences. + * + * + * Initial date: 20.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class UserPreferencesPageFragment { + + public static final By noneRadio = By.xpath("//div[contains(@class,'o_sel_home_settings_resume')]//input[@type='radio' and @value='none']"); + public static final By autoRadio = By.xpath("//div[contains(@class,'o_sel_home_settings_resume')]//input[@type='radio' and @value='auto']"); + public static final By ondemandRadio = By.xpath("//div[contains(@class,'o_sel_home_settings_resume')]//input[@type='radio' and @value='ondemand']"); + + public static final By saveSystemSettingsButton = By.xpath("//div[contains(@class,'o_sel_home_settings_gui_buttons')]//button[@type='button']"); + + @Drone + private WebDriver browser; + + @FindBy(className = "o_sel_home_settings_resume") + private WebElement resumeFieldset; + + /** + * @return True if the user's preference panel is displayed. + */ + public boolean isDisplayed() { + return resumeFieldset.isDisplayed(); + } + + /** + * Check that the user preferences page is displayed. + * + * @return The user preferences page fragment + */ + public UserPreferencesPageFragment assertOnUserPreferences() { + Assert.assertTrue(resumeFieldset.isDisplayed()); + return this; + } + + /** + * Set and save the resume preferences. + * + * @param resume + * @return + */ + public UserPreferencesPageFragment setResume(ResumeOption resume) { + Assert.assertTrue(resumeFieldset.isDisplayed()); + WebElement radio = null; + switch(resume) { + case none: radio = browser.findElement(noneRadio); break; + case auto: radio = browser.findElement(autoRadio); break; + case ondemand: radio = browser.findElement(ondemandRadio); break; + } + + radio.click(); + + WebElement saveButton = browser.findElement(saveSystemSettingsButton); + saveButton.click(); + Graphene.waitModel().until(new BusyPredicate()); + return this; + } + + public enum ResumeOption { + none, + auto, + ondemand + } +} diff --git a/src/test/java/org/olat/selenium/page/user/UserSettingsPage.java b/src/test/java/org/olat/selenium/page/user/UserSettingsPage.java new file mode 100644 index 0000000000000000000000000000000000000000..36f707ac7c7b174132b49db649587b4acd27b41d --- /dev/null +++ b/src/test/java/org/olat/selenium/page/user/UserSettingsPage.java @@ -0,0 +1,74 @@ +/** + * <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.user; + +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.graphene.Graphene; +import org.jcodec.common.Assert; +import org.olat.selenium.page.BusyPredicate; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * + * Initial date: 20.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class UserSettingsPage { + + @Drone + private WebDriver browser; + + @FindBy(className = "o_segments") + private WebElement segmentView; + + @FindBy(className = "o_sel_user_settings_prefs") + private WebElement preferencesSegmentLink; + @FindBy(className = "o_sel_user_settings_webdav") + private WebElement webdavSegmentLink; + @FindBy(className = "o_sel_user_settings_im") + private WebElement imSegmentLink; + @FindBy(className = "o_sel_user_settings_disclaimer") + private WebElement disclaimerSegmentLink; + + /** + * Check that the user settings is displayed. + * @return + */ + public UserSettingsPage assertOnUserSettings() { + Assert.assertTrue(segmentView.isDisplayed()); + return this; + } + + /** + * Open the user preferences + * @return + */ + public UserPreferencesPageFragment openPreferences() { + preferencesSegmentLink.click(); + Graphene.waitModel().until(new BusyPredicate()); + + WebElement main = browser.findElement(By.id("o_main")); + return Graphene.createPageFragment(UserPreferencesPageFragment.class, main); + } +} diff --git a/src/test/java/org/olat/selenium/page/user/UserToolsPage.java b/src/test/java/org/olat/selenium/page/user/UserToolsPage.java new file mode 100644 index 0000000000000000000000000000000000000000..d76b0a72607123d9fa3d7c9ed1f8271284878eb8 --- /dev/null +++ b/src/test/java/org/olat/selenium/page/user/UserToolsPage.java @@ -0,0 +1,103 @@ +/** + * <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.user; + +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.graphene.Graphene; +import org.jboss.arquillian.graphene.page.Page; +import org.jcodec.common.Assert; +import org.olat.selenium.page.BusyPredicate; +import org.olat.selenium.page.LoginPage; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * + * Initial date: 20.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class UserToolsPage { + + public static final By mySettingsClassName = By.className("o_sel_user_tools-mysettings"); + + @Drone + private WebDriver browser; + + @FindBy(id = "o_navbar_tools_personal") + private WebElement toolbarMenu; + @FindBy(id = "o_sel_navbar_my_menu_caret") + private WebElement toolbarCaretLink; + + @FindBy(className = "o_sel_user_tools-mysettings") + private WebElement mySettingsLink; + @FindBy(className = "o_logout") + private WebElement logoutLink; + + @Page + private UserSettingsPage userSettings; + + /** + * Check if the user menu is displayed. + * + * @return + */ + public UserToolsPage assertOnUserTools() { + Assert.assertTrue(toolbarMenu.isDisplayed()); + return this; + } + + /** + * Open the user menu with the tools. + * + * @return The user menu page + */ + public UserToolsPage openUserToolsMenu() { + if(!mySettingsLink.isDisplayed()) { + toolbarCaretLink.click(); + Graphene.waitModel().until().element(mySettingsClassName).is().visible(); + } + return this; + } + + /** + * Open the user settings. + * + * @return The user sesstings page fragment + */ + public UserSettingsPage openMySettings() { + Assert.assertTrue(mySettingsLink.isDisplayed()); + mySettingsLink.click(); + Graphene.waitModel().until(new BusyPredicate()); + return userSettings; + } + + /** + * Log out and wait until the login form appears + */ + public void logout() { + openUserToolsMenu(); + Graphene.guardHttp(logoutLink).click(); + Graphene.waitModel().until().element(LoginPage.loginFormBy).is().visible(); + } + +} diff --git a/src/test/java/org/olat/test/ArquillianDeployments.java b/src/test/java/org/olat/test/ArquillianDeployments.java index 3801d714b57c7a2bbe4a0baf14f593c3d5c1f9b3..724588a64513500da281d2394c48ab8b660af07d 100644 --- a/src/test/java/org/olat/test/ArquillianDeployments.java +++ b/src/test/java/org/olat/test/ArquillianDeployments.java @@ -145,8 +145,11 @@ public class ArquillianDeployments { || filename.endsWith("_zh_TW.properties")) { return false; } - } else if (filename.endsWith(".java") || filename.endsWith("instantMessagingTestContext.xml") || filename.endsWith("Mock.xml") || - filename.endsWith(".vsd") || filename.endsWith(".odg") || filename.endsWith(".odt") || filename.endsWith(".pdf")) { + } else if (filename.endsWith(".java") + || filename.endsWith(".vsd") + || filename.endsWith(".odg") + || filename.endsWith(".odt") + || filename.endsWith(".pdf")) { return false; } return true; @@ -163,12 +166,16 @@ public class ArquillianDeployments { private static class StaticFileFilter implements FileFilter { @Override public boolean accept(File pathname) { - String filename = pathname.getName(); - - if(filename.endsWith(".scss") || filename.endsWith(".psd") || filename.endsWith(".pxml")) { - return false; - } - return true; + String path = pathname.toString(); + boolean exclude = (path.contains("/static/themes/openolat/") + || path.contains("/static/themes/openolat/openolatexample") + || path.endsWith(".scss") + || path.endsWith(".psd") + || path.endsWith(".pxml") + || path.endsWith(".sh") + || path.endsWith(".scss") + || path.endsWith(".pxm")); + return !exclude; } } @@ -183,16 +190,14 @@ public class ArquillianDeployments { @Override public boolean include(ArchivePath path) { String pathStr = path.toString(); - if(pathStr.contains("/org/olat/core/test")) { - return false; - } - if(pathStr.contains("/org/olat/test/_spring") || pathStr.contains("/org/olat/test/file_resources")) { - return false; - } - if(pathStr.endsWith("Test.class]") || pathStr.endsWith("TestWithMocking.class]") || pathStr.endsWith("Junit4.class]")) { - return false; - } - return true; + boolean exclude = (pathStr.contains("/org/olat/core/test") + || pathStr.contains("/org/olat/selenium") + || pathStr.contains("/org/olat/test/_spring") + || pathStr.contains("/org/olat/test/file_resources") + || pathStr.endsWith("Test.class]") + || pathStr.endsWith("TestWithMocking.class]") + || pathStr.endsWith("Junit4.class]")); + return !exclude; } } } diff --git a/src/test/java/org/olat/test/rest/RepositoryRestClient.java b/src/test/java/org/olat/test/rest/RepositoryRestClient.java new file mode 100644 index 0000000000000000000000000000000000000000..0a4c2b1f0b1afc36eea6c6dd5badba19e1df6091 --- /dev/null +++ b/src/test/java/org/olat/test/rest/RepositoryRestClient.java @@ -0,0 +1,106 @@ +/** + * <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.test.rest; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.UUID; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriBuilder; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.olat.restapi.RestConnection; +import org.olat.restapi.support.vo.CourseVO; +import org.olat.test.ArquillianDeployments; + +/** + * + * Initial date: 19.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class RepositoryRestClient { + + + private final URL deploymentUrl; + private final String username; + private final String password; + + public RepositoryRestClient(URL deploymentUrl) { + this(deploymentUrl, "administrator", "openolat"); + } + + public RepositoryRestClient(URL deploymentUrl, String username, String password) { + this.deploymentUrl = deploymentUrl; + this.username = username; + this.password = password; + } + + public CourseVO deployDemoCourse() + throws URISyntaxException, IOException { + URL url = ArquillianDeployments.class.getResource("file_resources/Demo-Kurs-7.1.zip"); + File archive = new File(url.toURI()); + + String displayname = "Demo-Kurs-" + UUID.randomUUID().toString(); + return deployCourse(archive, "-", displayname); + } + + public CourseVO deployCourse(File archive, String resourcename, String displayname) + throws URISyntaxException, IOException { + + RestConnection conn = new RestConnection(deploymentUrl); + assertTrue(conn.login(username, password)); + + URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("repo/courses").build(); + HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON); + String softKey = UUID.randomUUID().toString(); + HttpEntity entity = MultipartEntityBuilder.create() + .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) + .addBinaryBody("file", archive, ContentType.APPLICATION_OCTET_STREAM, archive.getName()) + .addTextBody("filename", archive.getName()) + .addTextBody("resourcename", resourcename) + .addTextBody("displayname", displayname) + .addTextBody("access", "3") + .addTextBody("softkey", softKey) + .build(); + method.setEntity(entity); + + HttpResponse response = conn.execute(method); + assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201); + + CourseVO vo = conn.parse(response, CourseVO.class); + assertNotNull(vo); + assertNotNull(vo.getRepoEntryKey()); + assertNotNull(vo.getKey()); + return vo; + } +} diff --git a/src/test/java/org/olat/test/rest/UserRestClient.java b/src/test/java/org/olat/test/rest/UserRestClient.java new file mode 100644 index 0000000000000000000000000000000000000000..8b227d317d548be8cf3389e2b72f1d9c17b52b91 --- /dev/null +++ b/src/test/java/org/olat/test/rest/UserRestClient.java @@ -0,0 +1,127 @@ +/** + * <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.test.rest; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriBuilder; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPut; +import org.junit.Assert; +import org.olat.restapi.RestConnection; +import org.olat.user.restapi.UserVO; + +/** + * REST client for the user webservice. + * + * + * Initial date: 19.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class UserRestClient { + + private static final AtomicInteger counter = new AtomicInteger(); + + private final URL deploymentUrl; + private final String username; + private final String password; + + public UserRestClient(URL deploymentUrl) { + this(deploymentUrl, "administrator", "openolat"); + } + + public UserRestClient(URL deploymentUrl, String username, String password) { + this.deploymentUrl = deploymentUrl; + this.username = username; + this.password = password; + } + + public List<UserVO> createTestUsers(int count) + throws IOException, URISyntaxException { + RestConnection restConnection = new RestConnection(deploymentUrl); + assertTrue(restConnection.login(username, password)); + + List<UserVO> users = new ArrayList<UserVO>(count); + for(int i = 0; i < count; i++){ + users.add(createUser(restConnection)); + } + return users; + } + + public UserVO createTestUser() + throws IOException, URISyntaxException { + RestConnection restConnection = new RestConnection(deploymentUrl); + assertTrue(restConnection.login(username, password)); + + UserVO user = createUser(restConnection); + + restConnection.shutdown(); + return user; + } + + private UserVO createUser(RestConnection restConnection) + throws URISyntaxException, IOException { + String uuid = Integer.toString(counter.incrementAndGet()) + UUID.randomUUID().toString(); + + UserVO vo = new UserVO(); + String username = ("selenium-" + uuid).substring(0, 24); + vo.setLogin(username); + String password = ("passwd-" + uuid).substring(0, 24); + vo.setPassword(password); + vo.setFirstName("John-" + uuid); + vo.setLastName("Smith"); + vo.setEmail(username + "@frentix.com"); + vo.putProperty("telOffice", "39847592"); + vo.putProperty("telPrivate", "39847592"); + vo.putProperty("telMobile", "39847592"); + vo.putProperty("gender", "Female");//male or female + vo.putProperty("birthDay", "12/12/2009"); + + URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("users").build(); + HttpPut method = restConnection.createPut(request, MediaType.APPLICATION_JSON, true); + restConnection.addJsonEntity(method, vo); + method.addHeader("Accept-Language", "en"); + + HttpResponse response = restConnection.execute(method); + int responseCode = response.getStatusLine().getStatusCode(); + assertTrue(responseCode == 200 || responseCode == 201); + InputStream body = response.getEntity().getContent(); + UserVO current = restConnection.parse(body, UserVO.class); + Assert.assertNotNull(current); + + current.setPassword(vo.getPassword()); + return current; + } + + +} diff --git a/src/test/java/org/olat/util/FunctionalInstantMessagingUtil.java b/src/test/java/org/olat/util/FunctionalInstantMessagingUtil.java index 6fe7370f0727bf8162e642d7a4a5b393d5906725..9c4a8f51cb99c289e94d1b15f5f80df00e94d162 100644 --- a/src/test/java/org/olat/util/FunctionalInstantMessagingUtil.java +++ b/src/test/java/org/olat/util/FunctionalInstantMessagingUtil.java @@ -179,30 +179,6 @@ public class FunctionalInstantMessagingUtil { return(true); } - /** - * Show offline contacts. - * - * @param browser - * @return true on success - */ - private boolean openOfflineContacts(Selenium browser){ - functionalUtil.idle(browser); - - /* check if it's already open */ - StringBuffer locatorBuffer = new StringBuffer(); - - locatorBuffer.append("xpath=//a[contains(@class, '") - .append(getInstantMessagingShowOfflineContactsCss()) - .append("')]"); - - /* click if necessary */ - if(browser.isElementPresent(locatorBuffer.toString())){ - browser.click(locatorBuffer.toString()); - } - - return(true); - } - /** * Show groups. * diff --git a/src/test/java/org/olat/util/browser/Administrator.java b/src/test/java/org/olat/util/browser/Administrator.java deleted file mode 100644 index 48bcb498551a28dd838e609de40a109e408f5a44..0000000000000000000000000000000000000000 --- a/src/test/java/org/olat/util/browser/Administrator.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * <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.util.browser; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.jboss.arquillian.drone.api.annotation.Qualifier; - -/** - * - * @author jkraehemann, joel.kraehemann@frentix.com, frentix.com - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.FIELD, ElementType.PARAMETER }) -@Qualifier -public @interface Administrator { - -} diff --git a/src/test/java/org/olat/util/browser/Browser1.java b/src/test/java/org/olat/util/browser/Browser1.java deleted file mode 100644 index a5e695f75854fda310dcd317c6d61f2b91dba196..0000000000000000000000000000000000000000 --- a/src/test/java/org/olat/util/browser/Browser1.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * <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.util.browser; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.jboss.arquillian.drone.api.annotation.Qualifier; - -/** - * - * @author jkraehemann, joel.kraehemann@frentix.com, frentix.com - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.FIELD, ElementType.PARAMETER }) -@Qualifier -public @interface Browser1 -{ - -} \ No newline at end of file diff --git a/src/test/resources/arquillian.xml b/src/test/resources/arquillian.xml index 03aa5f2e1065f35f20948c83c38096a2f6bb2e70..d7936926b9008bc0ad72c526fc52000bb9a760d0 100644 --- a/src/test/resources/arquillian.xml +++ b/src/test/resources/arquillian.xml @@ -26,6 +26,10 @@ <property name="browser">*googlechrome</property> --> </extension> + + <extension qualifier="webdriver"> + <property name="browser">firefox</property> + </extension> <extension qualifier="student"> <property name="browserCapabilities">firefox</property>