Index: lams_tool_notebook/lib/user-extensions.js =================================================================== diff -u --- lams_tool_notebook/lib/user-extensions.js (revision 0) +++ lams_tool_notebook/lib/user-extensions.js (revision e4adb3b6016ff16563d2d5e407119d4ebe254470) @@ -0,0 +1,386 @@ +/* + * License + * + * This file is part of The SeleniumFlex-API. + * + * The SeleniumFlex-API is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or any later version. + * + * The SeleniumFlex-API is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The SeleniumFlex-API. + * If not, see http://www.gnu.org/licenses/ + * + */ + +/** + * The following is the ID for the Flex object on the html page. + * Should be different depending on the application under test. + * Use the command flexSetFlexObjID to set the command during runtime + */ + +Selenium.prototype.getFlexObject = function(){ + var obj = (this.browserbot.locateElementByXPath('//embed', this.browserbot.getDocument())) ? this.browserbot.locateElementByXPath('//embed', this.browserbot.getDocument()) : this.browserbot.locateElementByXPath('//object', this.browserbot.getDocument()); + return obj.id; +} + +Selenium.prototype.flashObjectLocator = null; + +Selenium.prototype.callFlexMethod = function (method, id, args) { + + if (this.flashObjectLocator === null){ + this.flashObjectLocator = "CloudWizard";//this.getFlexObject(); + } + + // the object that contains the exposed Flex functions + var funcObj = null; + // get the flash object + var flashObj = selenium.browserbot.findElement(this.flashObjectLocator); + + if (flashObj.wrappedJSObject) { + flashObj = flashObj.wrappedJSObject; + } + + // find object holding functions + if(typeof(flashObj[method]) == 'function') + // for IE (will be the flash object itself) + funcObj = flashObj; + else { + // Firefox (will be a child of the flash object) + for(var i = 0; i < flashObj.childNodes.length; i++) { + var tmpFuncObj = flashObj.childNodes[i]; + if(typeof(tmpFuncObj) == 'function') { + funcObj = tmpFuncObj; + break; + } + } + } + + // throw a error to Selenium if the exposed function could not be found + if(funcObj == null) + throw new SeleniumError('Function ' + method + ' not found on the External Interface for the flash object ' + this.flashObjectLocator); + + return funcObj[method](id, args); +} + +Selenium.prototype.doFlexSetFlexObjID = function(flasObjID) { + if(null == flasObjID) throw new SeleniumError(flasObjID); + this.flashObjectLocator = flasObjID; +}; + +Selenium.prototype.doAssertFlexAlertTextPresent = function(searchStr) { + var retval = this.callFlexMethod('getFlexAlertTextPresent', searchStr); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doAssertFlexAlertTextNotPresent = function(searchStr) { + var retval = this.callFlexMethod('getFlexAlertTextPresent', searchStr); + if(retval == 'true') throw new SeleniumError('The string ' + searchStr + ' was found'); +}; + +Selenium.prototype.doVerifyFlexAlertTextPresent = function(searchStr) { + var retval = this.callFlexMethod('getFlexAlertTextPresent', searchStr); + if(retval != 'true') LOG.error(retval); +}; + +Selenium.prototype.doVerifyFlexAlertTextNotPresent = function(searchStr) { + var retval = this.callFlexMethod('getFlexAlertTextPresent', searchStr); + if(retval == 'true') LOG.error('The string ' + searchStr + ' was found'); +}; + +Selenium.prototype.getFlexASProperty = function(idProperty) { + var targets = idProperty.split('.'); + return this.callFlexMethod('getFlexASProperty', targets[0], targets[1]); +}; + +Selenium.prototype.getFlexProperty = function(idProperty) { + var ID = idProperty.split('.')[0]; + var property = idProperty.substring(idProperty.indexOf('.') + 1); + return this.callFlexMethod('getFlexProperty', ID, property); +}; + +Selenium.prototype.getFlexSelectedItemAtIndex = function(id) { + return this.callFlexMethod('getFlexSelectedItemAtIndex', id); +}; + +Selenium.prototype.getFlexNumSelectedItems = function(id) { + return this.callFlexMethod('getFlexNumSelectedItems', id); +}; + +Selenium.prototype.getFlexVisible = function(id) { + return this.callFlexMethod('getFlexVisible', id); +}; + +Selenium.prototype.getFlexTextPresent = function(id) { + return this.callFlexMethod('getFlexTextPresent', id); +}; + +Selenium.prototype.getFlexText = function(id) { + return this.callFlexMethod('getFlexText', id); +}; + +Selenium.prototype.getFlexStepper = function(id) { + return this.callFlexMethod('getFlexStepper', id); +}; + +Selenium.prototype.getFlexSelectionIndex = function(id) { + return this.callFlexMethod('getFlexSelectionIndex', id); +}; + +Selenium.prototype.getFlexSelection = function(id) { + return this.callFlexMethod('getFlexSelection', id); +}; + +Selenium.prototype.getFlexRadioButton = function(id) { + return this.callFlexMethod('getFlexRadioButton', id); +}; + +Selenium.prototype.getFlexParseInt = function(id) { + return this.callFlexMethod('getFlexParseInt', id); +}; + +Selenium.prototype.getFlexNumeric = function(id) { + return this.callFlexMethod('getFlexNumeric', id); +}; + +Selenium.prototype.getFlexGlobalPosition = function(id) { + return this.callFlexMethod('getFlexGlobalPosition', id); +}; + +Selenium.prototype.getFlexExists = function(id) { + return this.callFlexMethod('getFlexExists', id); +}; + +Selenium.prototype.getFlexErrorString = function(id) { + return this.callFlexMethod('getFlexErrorString', id); +}; + +Selenium.prototype.getFlexEnabled = function(id) { + return this.callFlexMethod('getFlexEnabled', id); +}; + +Selenium.prototype.getFlexDate = function(id) { + return this.callFlexMethod('getFlexDate', id); +}; + +Selenium.prototype.getFlexDataGridUIComponentLabel = function(id) { + return this.callFlexMethod('getFlexDataGridUIComponentLabel', id); +}; + +Selenium.prototype.getFlexDataGridRowIndexForFieldValue = function(id) { + return this.callFlexMethod('getFlexDataGridRowIndexForFieldValue', id); +}; + +Selenium.prototype.getFlexDataGridRowCount = function(id) { + return this.callFlexMethod('getFlexDataGridRowCount', id); +}; + +Selenium.prototype.getFlexDataGridFieldValueForGridRow = function(id) { + return this.callFlexMethod('getFlexDataGridFieldValueForGridRow', id); +}; + +Selenium.prototype.getFlexDataGridCellText = function(id) { + return this.callFlexMethod('getFlexDataGridCellText', id); +}; + +Selenium.prototype.getFlexDataGridCell = function(id) { + return this.callFlexMethod('getFlexDataGridCell', id); +}; + +Selenium.prototype.getFlexComponentInfo = function(id) { + return this.callFlexMethod('getFlexComponentInfo', id); +}; + +Selenium.prototype.getFlexComboContainsLabel = function(id) { + return this.callFlexMethod('getFlexComboContainsLabel', id); +}; + +Selenium.prototype.getFlexCheckBoxChecked = function(id) { + return this.callFlexMethod('getFlexCheckBoxChecked', id); +}; + +Selenium.prototype.getFlexAlertTextPresent = function(id) { + return this.callFlexMethod('getFlexAlertTextPresent', id); +}; + +Selenium.prototype.getFlexAlertText = function(id) { + return this.callFlexMethod('getFlexAlertText', id); +}; + +Selenium.prototype.getFlexAlertPresent = function(id) { + return this.callFlexMethod('getFlexAlertPresent', id); +}; + +Selenium.prototype.getDataGridUIComponentLabel = function(id) { + return this.callFlexMethod('getDataGridUIComponentLabel', id); +}; + +Selenium.prototype.getDataGridCellText = function(id) { + return this.callFlexMethod('getDataGridCellText', id); +}; + +Selenium.prototype.doRefreshIDToolTips = function(id, args) { + var retval = this.callFlexMethod('doRefreshIDToolTips', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexWaitForElementVisible = function(id, args) { + var retval = this.callFlexMethod('doFlexWaitForElementVisible', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexWaitForElement = function(id, args) { + var retval = this.callFlexMethod('doFlexWaitForElement', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexTypeAppend = function(id, args) { + var retval = this.callFlexMethod('doFlexTypeAppend', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexType = function(id, args) { + var retval = this.callFlexMethod('doFlexType', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexStepper = function(id, args) { + var retval = this.callFlexMethod('doFlexStepper', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexSetFocus = function(id, args) { + var retval = this.callFlexMethod('doFlexSetFocus', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexSetDataGridCell = function(id, args) { + var retval = this.callFlexMethod('doFlexSetDataGridCell', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexSelectMatchingOnField = function(id, args) { + var retval = this.callFlexMethod('doFlexSelectMatchingOnField', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexSelectIndex = function(id, args) { + var retval = this.callFlexMethod('doFlexSelectIndex', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexSelectComboByLabel = function(id, args) { + var retval = this.callFlexMethod('doFlexSelectComboByLabel', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexSelect = function(id, args) { + var retval = this.callFlexMethod('doFlexSelect', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexRefreshIDToolTips = function(id, args) { + var retval = this.callFlexMethod('doFlexRefreshIDToolTips', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexRadioButton = function(id, args) { + var retval = this.callFlexMethod('doFlexRadioButton', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexProperty = function(id, args) { + var retval = this.callFlexMethod('doFlexProperty', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexMouseUp = function(id, args) { + var retval = this.callFlexMethod('doFlexMouseUp', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexMouseRollOver = function(id, args) { + var retval = this.callFlexMethod('doFlexMouseRollOver', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexMouseRollOut = function(id, args) { + var retval = this.callFlexMethod('doFlexMouseRollOut', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexMouseOver = function(id, args) { + var retval = this.callFlexMethod('doFlexMouseOver', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexMouseMove = function(id, args) { + var retval = this.callFlexMethod('doFlexMouseMove', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexMouseDown = function(id, args) { + var retval = this.callFlexMethod('doFlexMouseDown', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexDragTo = function(id, args) { + var retval = this.callFlexMethod('doFlexDragTo', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexDoubleClick = function(id, args) { + var retval = this.callFlexMethod('doFlexDoubleClick', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexDate = function(id, args) { + var retval = this.callFlexMethod('doFlexDate', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexClickMenuBarUIComponent = function(id, args) { + var retval = this.callFlexMethod('doFlexClickMenuBarUIComponent', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexClickDataGridUIComponent = function(id, args) { + var retval = this.callFlexMethod('doFlexClickDataGridUIComponent', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexClickDataGridItem = function(id, args) { + var retval = this.callFlexMethod('doFlexClickDataGridItem', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexClick = function(id, args) { + var retval = this.callFlexMethod('doFlexClick', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexCheckBox = function(id, args) { + var retval = this.callFlexMethod('doFlexCheckBox', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexAlertResponse = function(id, args) { + var retval = this.callFlexMethod('doFlexAlertResponse', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexAddSelectMatchingOnField = function(id, args) { + var retval = this.callFlexMethod('doFlexAddSelectMatchingOnField', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; + +Selenium.prototype.doFlexAddSelectIndex = function(id, args) { + var retval = this.callFlexMethod('doFlexAddSelectIndex', id, args); + if(retval != 'true') throw new SeleniumError(retval); +}; Index: lams_tool_notebook/test/java/org/lamsfoundation/lams/tool/notebook/core/AbstractSeleniumTestCase.java =================================================================== diff -u --- lams_tool_notebook/test/java/org/lamsfoundation/lams/tool/notebook/core/AbstractSeleniumTestCase.java (revision 0) +++ lams_tool_notebook/test/java/org/lamsfoundation/lams/tool/notebook/core/AbstractSeleniumTestCase.java (revision e4adb3b6016ff16563d2d5e407119d4ebe254470) @@ -0,0 +1,572 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.notebook.core; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.LearningDesign; +import org.lamsfoundation.lams.learningdesign.ToolActivity; +import org.lamsfoundation.lams.learningdesign.dao.hibernate.ActivityDAO; +import org.lamsfoundation.lams.learningdesign.dao.hibernate.LearningDesignDAO; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.dao.hibernate.LessonDAO; +import org.lamsfoundation.lams.tool.Tool; +import org.lamsfoundation.lams.tool.dao.hibernate.ToolDAO; +import org.lamsfoundation.lams.usermanagement.service.UserManagementService; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.thoughtworks.selenium.HttpCommandProcessor; +import com.thoughtworks.selenium.SeleneseTestCase; + +public abstract class AbstractSeleniumTestCase extends SeleneseTestCase { + + /** + * Used as and activityUIID property while storing Learning Design + */ + protected static int defaultActivityUIId = 1; + + protected ToolDAO toolDAO; + protected ActivityDAO activityDAO; + protected UserManagementService userManagementService; + protected LessonDAO lessonDAO; + protected LearningDesignDAO learningDesignDAO; + + protected ApplicationContext context; + private static final String[] contextConfigLocation = new String[] { + "org/lamsfoundation/lams/localCommonContext.xml", + "org/lamsfoundation/lams/lesson/lessonApplicationContext.xml", + "org/lamsfoundation/lams/toolApplicationContext.xml", + }; + + /** the host name on which the Selenium Server resides */ + private static final String SERVER_HOST = "localhost"; + /** the port on which the Selenium Server is listening */ + private static final int SERVER_PORT = 5555; + /** + * the command string used to launch the browser, e.g. "*firefox" or + * "c:\\program files\\internet explorer\\iexplore.exe" + */ + private static final String BROWSER_START_COMMAND = "*firefox"; + /** + * the starting URL including just a domain name. We'll start the browser + * pointing at the Selenium resources on this URL, + */ + private static final String BROWSER_URL = "http://127.0.0.1:8080/lams/"; + + protected static final String SERVER_URL = "/lams/"; + protected static final String USER_LOGIN = "mmm"; + protected static final String USER_PASSWORD = "mmm"; + + public void setUp() throws Exception { + //TODO use super.setUp(); + context = new ClassPathXmlApplicationContext(contextConfigLocation); + toolDAO = (ToolDAO) this.context.getBean("toolDAO"); + activityDAO = (ActivityDAO) this.context.getBean("activityDAO"); + userManagementService = (UserManagementService) this.context.getBean("userManagementService"); + lessonDAO = (LessonDAO) this.context.getBean("lessonDAO"); + learningDesignDAO = (LearningDesignDAO) this.context.getBean("learningDesignDAO"); + + // selenium = new DefaultSelenium(SERVER_HOST, SERVER_PORT, BROWSER_START_COMMAND, BROWSER_URL); + HttpCommandProcessor proc = new HttpCommandProcessor(SERVER_HOST, + SERVER_PORT, BROWSER_START_COMMAND, BROWSER_URL); + selenium = new DefaultSeleniumFlex(proc); + selenium.start(); + selenium.setSpeed("1000"); + } + + public void tearDown() throws Exception { + super.tearDown(); + selenium.stop(); + } + + /** + * Our main test class. Currently it tests authoring, learning and + * monitoring sequentially one-by-one. Also it relies on the fact that you + * store new LD in authoring (otherwise you should reimplement this method). + * + * @throws Exception + */ + public void testEntireTool() throws Exception { + loginToLams(); + + //Authoring part + openAuthoringWindow(); + authoringTest(); + storeLearningDesign(); + closeAuthoringWindow(); + + createNewLesson(); + + //Learning part + learningTest(); + + //Monitoring part + openToolMonitor(); + monitoringTest(); + closeToolMonitor(); + } + + /** + * Returns tool's signature. This method should be overridden by all subclasses. + * + * @return tool's signature + */ + protected abstract String getToolSignature(); + + /** + * Returns the name of learning design that user entered saving it in authoring. + * Should be overridden by all subclasses. + * + * @return name of learning design + */ + protected abstract String getLearningDesignName(); + + /** + * Tests tool authoring. + * Should be overridden by all subclasses. + */ + protected abstract void authoringTest(); + + /** + * Tests tool learning. + * Should be overridden by all subclasses. + */ + protected abstract void learningTest(); + + /** + * Tests tool monitoring. + * Should be overridden by all subclasses. + */ + protected abstract void monitoringTest(); + + // TODO change this behavior (after main workflow will be setted up) + private String toolContentID; + private String contentFolderID; + /** + * Opens up all authoring windows. Should be done before testing tool's + * authoring. + */ + protected void openAuthoringWindow() throws Exception { + // open authoring canvas + selenium.click("//div[@id='header-my-courses']//div[@class='tab-middle-highlight']/a"); + selenium.waitForPopUp("aWindow", "10000"); + + Integer userID = userManagementService.getUserByLogin(USER_LOGIN).getUserId(); + String createUniqueContentFolderUrl = SERVER_URL + + "authoring/author.do?method=createUniqueContentFolder&userID=" + + userID; + final String createUniqueContentFolderId = "createUniqueContentFolderId"; + selenium.openWindow(createUniqueContentFolderUrl, createUniqueContentFolderId); + selenium.waitForPopUp(createUniqueContentFolderId, "10000"); + selenium.selectWindow(createUniqueContentFolderId); + String wddxPacket = selenium.getEval("this.browserbot.getDocument().getElementsByTagName('body')[0].innerHTML"); + contentFolderID = this.extractFolderIDFromWDDXPacket(wddxPacket); + selenium.close(); + selenium.selectWindow(null); + + Tool tool = toolDAO.getToolBySignature(getToolSignature()); + String getToolContentUrl = SERVER_URL + + "authoring/author.do?method=getToolContentID&toolID=" + + tool.getToolId(); + final String getToolContentId = "getToolContentId"; + selenium.openWindow(getToolContentUrl, getToolContentId); + selenium.waitForPopUp(getToolContentId, "10000"); + selenium.selectWindow(getToolContentId); + wddxPacket = selenium.getEval("this.browserbot.getDocument().getElementsByTagName('body')[0].innerHTML"); + toolContentID = this.extractToolContentIDFromWDDXPacket(wddxPacket); + selenium.close(); + selenium.selectWindow(null); + + String openToolUrl = SERVER_URL + tool.getAuthorUrl() + "?mode=author" + + "&toolContentID=" + toolContentID + "&contentFolderID=" + + contentFolderID; + final String openToolId = "openToolId"; + selenium.openWindow(openToolUrl.toString(), openToolId); + selenium.waitForPopUp(openToolId, "10000"); + selenium.selectWindow(openToolId); + } + + /** checks for verification errors and stops the browser */ + protected void closeAuthoringWindow() { + + } + + /** + * Stores learning design. Using getLearningDesignName() as a new design name. + */ + protected void storeLearningDesign() { + selenium.click("//span[@class='okIcon']"); + selenium.waitForPageToLoad("10000"); + //closes ok/reedit confirmation screen + selenium.click("//span[@class='close']"); + + //TODO remove next Paragraph + selenium.selectWindow(null); + Tool tool = toolDAO.getToolBySignature(getToolSignature()); + String openToolUrl = SERVER_URL + tool.getAuthorUrl() + "?mode=author" + + "&toolContentID=" + toolContentID + "&contentFolderID=" + + contentFolderID; + final String openToolId = "openToolId2"; + selenium.openWindow(openToolUrl.toString(), openToolId); + selenium.waitForPopUp(openToolId, "10000"); + selenium.selectWindow(openToolId); + + final String storeLearningDesignUrl = SERVER_URL + "servlet/authoring/storeLearningDesignDetails"; + String designDetails = constructWddxDesign(getToolSignature(), getLearningDesignName()); + selenium.runScript("var options = { " + "method:\"post\", " + + "postBody:\"" + designDetails + "\" " + + "};" + + "new Ajax.Request(\"" + storeLearningDesignUrl + "\",options);"); + + //TODO remove next Paragraph + selenium.close(); + + //closes Flash authoring screen + selenium.selectWindow("aWindow"); + selenium.close(); + selenium.selectWindow(null); + } + + /** + * Beware this method works wrong sometimes (due to the appearance of root element) + * + * @throws Exception + */ + protected void createNewLesson() throws Exception { + Long lastCreatedLessonId = getLastCreatedLessonId(true); + DefaultSeleniumFlex flexSelenium = (DefaultSeleniumFlex) selenium; + + + //TODO change the way workspaceFolderID setted + List titles = learningDesignDAO.getLearningDesignTitlesByWorkspaceFolder(new Integer(4)); + assertTrue("There is no stored learning design", titles.size() > 0); + Collections.sort(titles, String.CASE_INSENSITIVE_ORDER); + int count = 1; + for (String title : titles) { + if (title.equals(getLearningDesignName())) { + break; + } + count++; + } + assertTrue("There isn't learning design with name" + getLearningDesignName(),count <= titles.size()); + + flexSelenium.click("link=Add Lesson"); + Thread.sleep(6000); + waitForFlexExists("workspaceTree", 20, flexSelenium); + + // flexObjId is now setted to "cloudWizard" by default, change this if + // you want to use another one + // flexSelenium.flexSetFlexObjID("cloudWizard"); + + assertTrue(flexSelenium.getFlexEnabled("startButton").equals("true")); + flexSelenium.flexSelectIndex("workspaceTree", String.valueOf(count)); +// flexSelenium.flexType("resourceName_txi", "bueno"); + flexSelenium.flexClick("startButton"); + Thread.sleep(25000); + assertTrue("Lesson creation failed", lastCreatedLessonId < getLastCreatedLessonId(true)); + } + + /** + * Prepares learning environment. Should be invoked each time learning is going to be tested. + */ + protected void setUpLearning() { + selenium.runScript("openLearner(" + getLastCreatedLessonId(false) + ")"); +// selenium.click("link=" + getLearningDesignName()); + selenium.waitForPopUp("lWindow", "30000"); + String previousSpeed = selenium.getSpeed(); + selenium.setSpeed("3000"); + selenium.selectWindow("lWindow"); + selenium.setSpeed(previousSpeed); + } + + /** + * Shuts up learning environment. Should be invoked each time learning testing is done. + */ + protected void tearDownLearning() { + selenium.close(); + selenium.selectWindow(null); + } + + /** + * Launches Lams monitor, followed by tool's monitor popup. + */ + protected void openToolMonitor() { + Long lastCreatedLessonId = getLastCreatedLessonId(false); + LearningDesign learningDesign = lessonDAO.getLesson(lastCreatedLessonId).getLearningDesign(); + String contentFolderID = learningDesign.getContentFolderID(); + Activity activity = learningDesign.getFirstActivity(); + // doing this to prevent CGILib initialization exception + ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); + + selenium.runScript("openMonitorLesson(" + lastCreatedLessonId + ")"); + selenium.waitForPopUp("mWindow", "15000"); + + // openning tool monitor popup + Tool tool = toolDAO.getToolBySignature(getToolSignature()); + String monitorUrl = SERVER_URL + tool.getMonitorUrl() + + "?toolContentID=" + toolActivity.getToolContentId() + + "&contentFolderID=" + contentFolderID; + final String monitorId = "monitorId"; + selenium.openWindow(monitorUrl, monitorId); + selenium.waitForPopUp(monitorId, "50000"); + selenium.selectWindow(monitorId); + } + + /** + * Closes Lams monitor. (Optional activity) + */ + protected void closeToolMonitor() { + selenium.close(); + selenium.selectWindow(null); + } + + + /** */ + protected void loginToLams() throws Exception { + selenium.open(SERVER_URL); + selenium.type("j_username", USER_LOGIN); + selenium.type("j_password", USER_PASSWORD); + selenium.click("//p[@class='login-button']/a"); + selenium.waitForPageToLoad("10000"); + Thread.sleep(3000); + } + + // ***************************************************************************** + // methods for testing Flex + // ***************************************************************************** + + protected void waitForFlexExists(String objectID, int timeout, DefaultSeleniumFlex selenium) throws Exception { + while (timeout > 0 && !selenium.getFlexExists(objectID).contains("true")) { + Thread.sleep(1000); + timeout--; + } + if (timeout == 0) { + throw new Exception("waitForFlexExists flex object:" + objectID + " Timed Out"); + } + } + + protected void waitForFlexVisible(String objectID, int timeout, + DefaultSeleniumFlex selenium) throws Exception { + while (timeout > 0 && !selenium.getFlexVisible(objectID).equals("true")) { + Thread.sleep(1000); + timeout--; + } + if (timeout == 0) { + throw new Exception("waitForFlexVisible flex object:" + objectID + + " Timed Out"); + } + } + + + + // ***************************************************************************** + // auxiliary methods + // ***************************************************************************** + + /** + * Returns lessonId of the last created lesson. + * + * @return id + */ + private Long getLastCreatedLessonId(boolean returnNegative) { + Integer userID = userManagementService.getUserByLogin(USER_LOGIN).getUserId(); + List lessonsCreatedByUser = lessonDAO.getLessonsCreatedByUser(userID); + List lessonsByLDName = new ArrayList(); + for (Lesson lesson : lessonsCreatedByUser) { + if (lesson.getLessonName().equals(getLearningDesignName())){ + lessonsByLDName.add(lesson); + } + } + if (lessonsByLDName.size() == 0) { + if (returnNegative) { + return new Long(-1); + } else { + fail("Lesson creation failed."); + } + } + + Lesson lastCreatedLesson = lessonsCreatedByUser.iterator().next(); + for (Lesson lesson : lessonsByLDName) { + if (lesson.getCreateDateTime().after(lastCreatedLesson.getCreateDateTime()) ){ + lastCreatedLesson = lesson; + } + } + return lastCreatedLesson.getLessonId(); + } + + /** + * Given a WDDX packet in our normal format, gets the id number from within + * the <var + * name='messageValue'><number>num</number></var> + * + * @param wddxPacket + * @return id + */ + private String extractFolderIDFromWDDXPacket(String wddxPacket) { + int indexMessageValue = wddxPacket.indexOf(""); + assertTrue(" string not found", indexMessageValue > 0); + int endIndexMessageValue = wddxPacket.indexOf("", indexMessageValue); + return wddxPacket.substring(indexMessageValue + + "".length(), endIndexMessageValue); + } + + /** + * Given a WDDX packet in our normal format, gets the id number from within + * the <var + * name='messageValue'><number>num</number></var> + * + * @param wddxPacket + * @return id + */ + private String extractToolContentIDFromWDDXPacket(String wddxPacket) { + int indexMessageValue = wddxPacket.indexOf(""); + assertTrue(wddxPacket + "!! string not found", indexMessageValue > 0); + int endIndexMessageValue = wddxPacket.indexOf(".0", indexMessageValue); + String idString = wddxPacket.substring(indexMessageValue + + "".length(), + endIndexMessageValue); + try { + Long.parseLong(idString); + return idString; + } catch (NumberFormatException e) { + fail("Unable to get id number from WDDX packet. Format exception. String was " + + idString); + } + return null; + } + + private String constructWddxDesign(String toolSignature,String newLearningDesignName) { + Integer userID = userManagementService.getUserByLogin(USER_LOGIN).getUserId(); + Tool tool = toolDAO.getToolBySignature(toolSignature); + + // TemplateActivityByLibraryID(libraryID); + ToolActivity templateActivity = null; + for (Object activityObject : activityDAO.getAllActivities()) { + if (activityObject instanceof ToolActivity) { + ToolActivity activity = (ToolActivity) activityObject; + if ((activity.getLearningDesign() == null) + && activity.getTool().getToolId().equals(tool.getToolId())) { + templateActivity = activity; + } + } + } + + String design = + "" + + "
" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "string_null_value" + + "string_null_value" + + "" + tool.getToolId() + "" + + "" + toolContentID + "" + + "" + tool.getToolSignature() + "" + + "" + tool.getToolDisplayName() + "" + + "" + tool.getHelpUrl() + "" + + "" + tool.getAuthorUrl() + "" + + "" + + "" + templateActivity.getGroupingSupportType() + "" + + "2009-6-12T1:24:50+3:0" + + "" + + "" + + "" + + "-111111" + + "-111111" + + "" + templateActivity.getLibraryActivityUiImage() + "" + + "124" + + "132" + + "" + templateActivity.getHelpText() + "" + + "" + templateActivity.getDescription() + "" + + "" + templateActivity.getTitle() + "" + + "" + templateActivity.getLearningLibrary().getLearningLibraryId() + "" + + ""+ (defaultActivityUIId++) +"" + + "" + templateActivity.getActivityCategoryID() + "" + + "" + templateActivity.getActivityId() + "" + + "" + templateActivity.getActivityTypeId() + "" + + "" + + "" + + "" + + "" + contentFolderID + "" + + "2009-6-24T22:45:24+3:0" + + //TODO may be we need provide real workspaceFolderID +// WorkspaceFolderContentDAO dd; +// dd.getWorkspaceFolderContentByID(new Long(2)).getWorkspaceFolder().getWorkspaceFolderId(); + "4" + + "1" + + "0" + + "" + + "" + + "" + userID + "" + + "" + newLearningDesignName + "" + + "-111111" + + "1" + + "" + + "" + + ""; + return design; + } + + // /** + // * Given a WDDX packet in our normal format, return the map object in the + // messageValue parameter. This should + // * contain any returned ids. + // * + // * @param wddxPacket + // * @return Map + // */ + // protected String extractIdMapFromWDDXPacket(String wddxPacket) { + // + // Object obj = null; + // try { + // obj = WDDXProcessor.deserialize(wddxPacket); + // } catch (WddxDeserializationException e1) { + // fail("WddxDeserializationException " + e1.getMessage()); + // e1.printStackTrace(); + // } + // // WDDXProcessor.convertToBoolean(table, key) + // + // Map map = (Map) obj; + // Object uniqueContentFolderObj = map.get("createUniqueContentFolder"); + // assertNotNull("createUniqueContentFolder object found", + // uniqueContentFolderObj); + // if (!String.class.isInstance(uniqueContentFolderObj)) { + // fail("createUniqueContentFolder is not a String - try extractIdFromWDDXPacket(packet)"); + // } + // + // return (String) uniqueContentFolderObj; + // } + +} Fisheye: Tag e4adb3b6016ff16563d2d5e407119d4ebe254470 refers to a dead (removed) revision in file `lams_tool_notebook/test/java/org/lamsfoundation/lams/tool/notebook/core/SeleniumBaseTestCase.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_notebook/test/java/org/lamsfoundation/lams/tool/notebook/testscripts/TestNotebook.java =================================================================== diff -u -r94978257a4e34f04f7997f60558db2762811c72b -re4adb3b6016ff16563d2d5e407119d4ebe254470 --- lams_tool_notebook/test/java/org/lamsfoundation/lams/tool/notebook/testscripts/TestNotebook.java (.../TestNotebook.java) (revision 94978257a4e34f04f7997f60558db2762811c72b) +++ lams_tool_notebook/test/java/org/lamsfoundation/lams/tool/notebook/testscripts/TestNotebook.java (.../TestNotebook.java) (revision e4adb3b6016ff16563d2d5e407119d4ebe254470) @@ -18,107 +18,55 @@ * * http://www.gnu.org/licenses/gpl.txt * **************************************************************** - */ - -/* $Id$ */ -package org.lamsfoundation.lams.tool.notebook.testscripts; + */ -import org.lamsfoundation.lams.tool.notebook.core.SeleniumBaseTestCase; +/* $Id$ */ +package org.lamsfoundation.lams.tool.notebook.testscripts; -public class TestNotebook extends SeleniumBaseTestCase{ - - public static final String TOOL_SIGNATURE = "lantbk11"; - public static final String LEARNING_DESIGN_NAME = "bueno"; - - public void testAuthoring() throws Exception { - openToolAuthoringWindow(TOOL_SIGNATURE); +import org.lamsfoundation.lams.tool.notebook.core.AbstractSeleniumTestCase; +import org.lamsfoundation.lams.tool.notebook.util.NotebookConstants; + +public class TestNotebook extends AbstractSeleniumTestCase { + + + protected String getToolSignature() { + return NotebookConstants.TOOL_SIGNATURE; + } - assertEquals("Notebook", selenium.getTitle()); - - selenium.type("title", "leave your comment"); - selenium.runScript("FCKeditorAPI.GetInstance(\"instructions\").SetHTML(\"invent a new way of using Flash\")"); - selenium.click("tab-middle-link-2"); - selenium.click("lockOnFinished"); - selenium.click("tab-middle-link-3"); - selenium.type("onlineInstruction__lamstextarea", "online instructions"); - - storeLearningDesign(TOOL_SIGNATURE, LEARNING_DESIGN_NAME); - } + protected String getLearningDesignName() { + return "bueno"; + } - -// public void testFlex() throws Exception { -// loginToLams(); -// -// selenium.click("link=Add Lesson"); -// Thread.sleep(6000); -// -// DefaultSeleniumFlex flexSelenium = (DefaultSeleniumFlex)selenium; -// Thread.sleep(2000); -// flexSelenium.click("link=Add Lesson"); -// Thread.sleep(6000); -//// waitForFlexExists("resourceName_txi", 20, flexSelenium); -//// flexSelenium.wait(); -//// flexSelenium.flexSetFlexObjID("CloudWizard"); -// -// flexSelenium.flexType("resourceName_txi", "bueno"); -// flexSelenium.flexClick("startButton"); -// -//// flexSelenium.flexSelect(target) -// } - -// -// public void testLearning() throws Exception { -// loginToLams(); -// -// selenium.click("link=" + LEARNING_DESIGN_NAME); -// selenium.waitForPopUp("lWindow", "30000"); -// selenium.setSpeed("3000"); -// selenium.selectWindow("lWindow"); -// selenium.setSpeed("1000"); -// -// assertEquals("LAMS Learner", selenium.getTitle()); -// assertEquals("LAMS Learner", selenium.isElementPresent("//a[@id='finishButton']")); -// -// selenium.type("entryText", "have fun"); -// selenium.click("//a[@id='finishButton']/span"); -// selenium.waitForPageToLoad("30000"); -//// assertTrue(selenium.isTextPresent("Congratulations")); -// assertFalse(selenium.isElementPresent("entryText")); -// selenium.close(); -// selenium.selectWindow(null); -// -// selenium.click("link=" + LEARNING_DESIGN_NAME); -// selenium.waitForPopUp("lWindow", "30000"); -// selenium.setSpeed("3000"); -// selenium.selectWindow("lWindow"); -// selenium.setSpeed("1000"); -//// assertTrue(selenium.isTextPresent("Congratulations")); -// assertFalse(selenium.isElementPresent("entryText")); -// selenium.close(); -// selenium.selectWindow(null); -// } - -// public void testMonitoring() throws Exception { -// -// openToolMonitor(TOOL_SIGNATURE, LEARNING_DESIGN_NAME); -// -// assertEquals("Notebook", selenium.getTitle()); -// -// closeToolMonitor(); -// } - - + protected void authoringTest() { + assertEquals("Notebook", selenium.getTitle()); -// public void verifyFlexAppSumIsCorrect() { -// flexUITester.type("2").at("arg1"); -// flexUITester.type("3").at("arg2"); -// flexUITester.click("submit"); -// assertEquals("5", flexUITester.readFrom("result")); -// -// assertEquals("Clicking Colors", selenium.getTitle()); -// -// assertEquals("(Click here)", flashApp.call("getSquareLabel")); -// flashApp.call("click"); -// } + selenium.type("title", "leave your comment2222"); + selenium.runScript("FCKeditorAPI.GetInstance(\"instructions\").SetHTML(\"invent a new way of using Flash\")"); + selenium.click("tab-middle-link-2"); + selenium.click("lockOnFinished"); + selenium.click("tab-middle-link-3"); + selenium.type("onlineInstruction__lamstextarea", "online instructions"); + } + protected void learningTest() { + setUpLearning(); + assertEquals("LAMS Learner", selenium.getTitle()); + assertEquals("LAMS Learner", selenium.isElementPresent("//a[@id='finishButton']")); + selenium.type("entryText", "have fun"); + selenium.click("//a[@id='finishButton']/span"); + selenium.waitForPageToLoad("30000"); + // assertTrue(selenium.isTextPresent("Congratulations")); + assertFalse(selenium.isElementPresent("entryText")); + tearDownLearning(); + + setUpLearning(); + // assertTrue(selenium.isTextPresent("Congratulations")); + assertFalse(selenium.isElementPresent("entryText")); + tearDownLearning(); + } + + protected void monitoringTest() { + assertEquals("Notebook", selenium.getTitle()); + } + }