Skip to content
Snippets Groups Projects
Commit 8409c858 authored by jkraehemann's avatar jkraehemann
Browse files

OO-346: implemented test.

parent cea9595f
No related branches found
No related tags found
No related merge requests found
/**
* <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 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.test.ArquillianDeployments;
import org.olat.util.FunctionalCourseUtil;
import org.olat.util.FunctionalRepositorySiteUtil;
import org.olat.util.FunctionalRepositorySiteUtil.CourseWizardAccess;
import org.olat.util.FunctionalRepositorySiteUtil.CourseWizardElement;
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 FunctionalCourseTest {
public final static String COURSE_TITLE = "wizard-course";
public final static String COURSE_DESCRIPTION = "course created by wizard";
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ArquillianDeployments.createDeployment();
}
@Drone
DefaultSelenium browser;
@ArquillianResource
URL deploymentUrl;
static FunctionalUtil functionalUtil;
static FunctionalRepositorySiteUtil functionalRepositorySiteUtil;
static FunctionalCourseUtil functionalCourseUtil;
static boolean initialized = false;
@Before
public void setup() throws IOException, URISyntaxException{
if(!initialized){
functionalUtil = new FunctionalUtil();
functionalUtil.setDeploymentUrl(deploymentUrl.toString());
functionalRepositorySiteUtil = new FunctionalRepositorySiteUtil(functionalUtil);
functionalCourseUtil = new FunctionalCourseUtil(functionalUtil, functionalRepositorySiteUtil);
initialized = true;
}
}
@Test
@RunAsClient
public void checkCreate(){
/* login */
Assert.assertTrue(functionalUtil.login(browser, functionalUtil.getUsername(), functionalUtil.getPassword(), true));
/* open repository site */
Assert.assertTrue(functionalUtil.openSite(browser, OlatSite.LEARNING_RESOURCES));
/* create course using wizard */
CourseWizardElement[] elementArray = new CourseWizardElement[]{
CourseWizardElement.INFO_PAGE,
CourseWizardElement.FORUM,
CourseWizardElement.ENROLLMENT,
CourseWizardElement.DOWNLOAD_FOLDER,
CourseWizardElement.EMAIL};
Assert.assertTrue(functionalRepositorySiteUtil.createCourseUsingWizard(browser, COURSE_TITLE, COURSE_DESCRIPTION,
elementArray, null, true, CourseWizardAccess.USERS));
/* click each node once */
for(int i = 0; i < elementArray.length; i++){
functionalCourseUtil.open(browser, i);
}
}
}
......@@ -69,10 +69,6 @@ public class FunctionalCourseUtil {
public final static String REPOSITORY_POPUP_CREATE_RESOURCE_CSS = "o_sel_repo_popup_create_resource";
public final static String REPOSITORY_POPUP_IMPORT_RESOURCE_CSS = "o_sel_repo_popup_import_resource";
public final static String REPOSITORY_POPUP_CSS = "o_sel_edit_repositoryentry_popup";
public final static String REPOSITORY_SAVE_DETAILS_CSS = "o_sel_repo_save_details";
public final static String REPOSITORY_ADD_FORWARD_CSS = "o_sel_repo_add_forward";
public final static String MAP_EDIT_CSS = "o_sel_edit_map";
public final static String BLOG_NO_POSTS_CSS = "o_blog_no_posts";
......@@ -264,11 +260,8 @@ public class FunctionalCourseUtil {
private String wikiChooseRepositoryFileCss;
private String feedChooseRepositoryFileCss;
private String mapChooseRepositoryFileCss;
private String repositoryPopupCss;
private String repositoryPopupCreateResourceCss;
private String repositorySaveDetailsCss;
private String repositoryAddForwardCss;
private String mapEditCss;
......@@ -319,10 +312,7 @@ public class FunctionalCourseUtil {
setFeedChooseRepositoryFileCss(FEED_CHOOSE_REPOSITORY_FILE_CSS);
setMapChooseRepositoryFileCss(MAP_CHOOSE_REPOSITORY_FILE_CSS);
setRepositoryPopupCss(REPOSITORY_POPUP_CSS);
setRepositoryPopupCreateResourceCss(REPOSITORY_POPUP_CREATE_RESOURCE_CSS);
setRepositorySaveDetailsCss(REPOSITORY_SAVE_DETAILS_CSS);
setRepositoryAddForwardCss(REPOSITORY_ADD_FORWARD_CSS);
setMapEditCss(MAP_EDIT_CSS);
......@@ -342,6 +332,17 @@ public class FunctionalCourseUtil {
if(!functionalRepositorySiteUtil.openCourse(browser, courseId))
return(false);
return(open(browser, nth));
}
/**
* @param browser
* @param nth
* @return true on success
*
* Opens the nth course element in the current course.
*/
public boolean open(Selenium browser, int nth){
StringBuffer selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=//ul[contains(@class, 'b_tree_l1')]//li[")
......@@ -1058,7 +1059,6 @@ public class FunctionalCourseUtil {
*
* Opens and fills in the "create resource" popup.
*/
//FIXME:JK: needs an additional class to find elements
private boolean createRepositoryResource(Selenium browser, String chooseRepositoryCss, String title, String description){
/* click on "choose, create or import file" button */
StringBuffer selectorBuffer = new StringBuffer();
......@@ -1084,46 +1084,8 @@ public class FunctionalCourseUtil {
functionalUtil.waitForPageToLoad(browser);
/* fill in title */
selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=//div[contains(@class, '")
.append(getRepositoryPopupCss())
.append("')]//form//input[@type='text']");
functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
browser.type(selectorBuffer.toString(), title);
/* fill in description */
functionalUtil.typeMCE(browser, getRepositoryPopupCss(), description);
/* click save */
selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=(//div[contains(@class, '")
.append(getRepositoryPopupCss())
.append("')]//form//div[contains(@class, '")
.append(getRepositorySaveDetailsCss())
.append("')]//button)[1]");
functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
browser.click(selectorBuffer.toString());
/* click next */
selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=//div[contains(@class, 'b_window')]//a[contains(@class, '")
.append(getRepositoryAddForwardCss())
.append("')]");
functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
browser.click(selectorBuffer.toString());
functionalUtil.waitForPageToUnloadElement(browser, selectorBuffer.toString());
return(true);
/* */
return(functionalRepositorySiteUtil.fillInRepositoryEntryPopup(browser, title, description));
}
/**
......@@ -1499,14 +1461,6 @@ public class FunctionalCourseUtil {
this.mapChooseRepositoryFileCss = mapChooseRepositoryFileCss;
}
public String getRepositoryPopupCss() {
return repositoryPopupCss;
}
public void setRepositoryPopupCss(String repositoryPopupCss) {
this.repositoryPopupCss = repositoryPopupCss;
}
public String getRepositoryPopupCreateResourceCss() {
return repositoryPopupCreateResourceCss;
}
......@@ -1515,22 +1469,6 @@ public class FunctionalCourseUtil {
this.repositoryPopupCreateResourceCss = repositoryPopupCreateResourceCss;
}
public String getRepositorySaveDetailsCss() {
return repositorySaveDetailsCss;
}
public void setRepositorySaveDetailsCss(String repositorySaveDetailsCss) {
this.repositorySaveDetailsCss = repositorySaveDetailsCss;
}
public String getRepositoryAddForwardCss() {
return repositoryAddForwardCss;
}
public void setRepositoryAddForwardCss(String repositoryAddForwardCss) {
this.repositoryAddForwardCss = repositoryAddForwardCss;
}
public String getMapEditCss() {
return mapEditCss;
}
......
......@@ -35,6 +35,13 @@ import com.thoughtworks.selenium.Selenium;
*/
public class FunctionalRepositorySiteUtil {
public final static String REPOSITORY_POPUP_CSS = "o_sel_edit_repositoryentry_popup";
public final static String REPOSITORY_SAVE_DETAILS_CSS = "o_sel_repo_save_details";
public final static String REPOSITORY_ADD_FORWARD_CSS = "o_sel_repo_add_forward";
public final static String COURSE_WIZARD_PUBLISH_CHECKBOX = "publishCheckbox";
public final static String COURSE_WIZARD_ACCESS_OPTION_ID = "o_fioaccessChooser_SELBOX";
public final static String REPOSITORY_SITE_MENU_TREE_SELECTED_CSS = "b_tree_selected";
public final static String REPOSITORY_SITE_CATALOG_CSS = "o_sel_repo_catalog";
......@@ -130,6 +137,67 @@ public class FunctionalRepositorySiteUtil {
MEMBERS_ONLY;
}
public enum NextSteps {
WIZARD("sw"),
COURSE_EDITOR("ce"),
DETAILED_VIEW("dv");
private String value;
NextSteps(String value){
setValue(value);
}
public String getValue(){
return(value);
}
public void setValue(String value){
this.value = value;
}
}
public enum CourseWizardElement {
INFO_PAGE("sp"),
ENROLLMENT("en"),
DOWNLOAD_FOLDER("bc"),
FORUM("fo"),
EMAIL("co");
private String value;
CourseWizardElement(String value){
setValue(value);
}
public String getValue(){
return(value);
}
public void setValue(String value){
this.value = value;
}
}
public enum CourseWizardAccess {
USERS("acl_olat"),
USERS_AND_GUESTS("acl_guest");
private String value;
CourseWizardAccess(String value){
setValue(value);
}
public String getValue(){
return(value);
}
public void setValue(String value){
this.value = value;
}
}
public final static String TOOLBOX_CONTENT_CSS = "b_toolbox_content";
public final static String TOOLBOX_COURSE_CSS = "o_toolbox_course";
public final static String TOOLBOX_CONTENT_PACKAGE_CSS = "o_toolbox_content";
......@@ -142,6 +210,13 @@ public class FunctionalRepositorySiteUtil {
public final static String TOOLBOX_SHAREDFOLDER_CSS = "o_toolbox_sharedfolder";
public final static String TOOLBOX_GLOSSARY_CSS = "o_toolbox_glossary";
private String repositoryPopupCss;
private String repositorySaveDetailsCss;
private String repositoryAddForwardCss;
private String courseWizardPublishCheckbox;
private String courseWizardAccessOptionCss;
private String repositorySiteMenuTreeSelectedCss;
private String repositorySiteCatalogCss;
......@@ -177,6 +252,13 @@ public class FunctionalRepositorySiteUtil {
public FunctionalRepositorySiteUtil(FunctionalUtil functionalUtil){
setRepositoryPopupCss(REPOSITORY_POPUP_CSS);
setRepositorySaveDetailsCss(REPOSITORY_SAVE_DETAILS_CSS);
setRepositoryAddForwardCss(REPOSITORY_ADD_FORWARD_CSS);
setCourseWizardPublishCheckbox(COURSE_WIZARD_PUBLISH_CHECKBOX);
setCourseWizardAccessOptionId(COURSE_WIZARD_ACCESS_OPTION_ID);
setRepositorySiteMenuTreeSelectedCss(REPOSITORY_SITE_MENU_TREE_SELECTED_CSS);
setRepositorySiteCatalogCss(REPOSITORY_SITE_CATALOG_CSS);
......@@ -613,6 +695,170 @@ public class FunctionalRepositorySiteUtil {
return(id);
}
/**
* @param browser
* @param title
* @param description
* @return
*
*
*/
public boolean fillInRepositoryEntryPopup(Selenium browser, String title, String description){
/* fill in title */
StringBuffer selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=//div[contains(@class, '")
.append(getRepositoryPopupCss())
.append("')]//form//input[@type='text']");
functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
browser.type(selectorBuffer.toString(), title);
/* fill in description */
functionalUtil.typeMCE(browser, getRepositoryPopupCss(), description);
/* click save */
selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=(//div[contains(@class, '")
.append(getRepositoryPopupCss())
.append("')]//form//div[contains(@class, '")
.append(getRepositorySaveDetailsCss())
.append("')]//button)[1]");
functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
browser.click(selectorBuffer.toString());
/* click next */
selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=//div[contains(@class, 'b_window')]//a[contains(@class, '")
.append(getRepositoryAddForwardCss())
.append("')]");
functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
browser.click(selectorBuffer.toString());
functionalUtil.waitForPageToUnloadElement(browser, selectorBuffer.toString());
return(true);
}
/**
* @param browser
* @param title
* @param description
* @param element
* @param catalog
* @param publish
* @param access
* @return true on success
*
* Creates a course using the wizard whereas the specified settings
* will applied.
*/
public boolean createCourseUsingWizard(Selenium browser, String title, String description,
CourseWizardElement[] element, String catalog, boolean publish, CourseWizardAccess access){
if(!clickCreate(browser, getToolboxCourseCss())){
return(false);
}
if(!fillInRepositoryEntryPopup(browser, title, description)){
return(false);
}
/* select wizard */
functionalUtil.clickRadio(browser, null, NextSteps.WIZARD.getValue());
/* click next */
StringBuffer selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=(//div[contains(@class, '")
.append(getRepositoryAddForwardCss())
.append("')]//button)[last()]");
functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString());
browser.click(selectorBuffer.toString());
functionalUtil.waitForPageToUnloadElement(browser, selectorBuffer.toString());
/* select course element */
for(CourseWizardElement current: element){
functionalUtil.clickCheckbox(browser, null, current.getValue());
}
functionalUtil.clickWizardNext(browser);
/* catalog */
if(catalog != null){
//TODO:JK: implement me
}
functionalUtil.clickWizardNext(browser);
/* publish */
if(!publish){
selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=//div[contains(@class, 'b_wizard')]//input[@type='checkbox' and @name='")
.append(getCourseWizardPublishCheckbox())
.append("']");
browser.click(selectorBuffer.toString());
}
if(access != null){
functionalUtil.selectOption(browser, getCourseWizardAccessOptionId(), access.getValue());
}
functionalUtil.clickWizardFinish(browser);
return(true);
}
public String getRepositoryPopupCss() {
return repositoryPopupCss;
}
public void setRepositoryPopupCss(String repositoryPopupCss) {
this.repositoryPopupCss = repositoryPopupCss;
}
public String getRepositorySaveDetailsCss() {
return repositorySaveDetailsCss;
}
public void setRepositorySaveDetailsCss(String repositorySaveDetailsCss) {
this.repositorySaveDetailsCss = repositorySaveDetailsCss;
}
public String getRepositoryAddForwardCss() {
return repositoryAddForwardCss;
}
public void setRepositoryAddForwardCss(String repositoryAddForwardCss) {
this.repositoryAddForwardCss = repositoryAddForwardCss;
}
public String getCourseWizardPublishCheckbox() {
return courseWizardPublishCheckbox;
}
public void setCourseWizardPublishCheckbox(String courseWizardPublishCheckbox) {
this.courseWizardPublishCheckbox = courseWizardPublishCheckbox;
}
public String getCourseWizardAccessOptionId() {
return courseWizardAccessOptionCss;
}
public void setCourseWizardAccessOptionId(String courseWizardAccessOptionCss) {
this.courseWizardAccessOptionCss = courseWizardAccessOptionCss;
}
public String getRepositorySiteMenuTreeSelectedCss() {
return repositorySiteMenuTreeSelectedCss;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment