Author: sebawagner
Date: Sat Sep 21 06:50:09 2013
New Revision: 1525199

URL: http://svn.apache.org/r1525199
Log:
OPENMEETINGS-792 Some basic preparation to write tests

Added:
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java
      - copied, changed from r1523184, 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/OpenMeetingsSmokeTest.java
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/web/LoginUI.java
Removed:
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/OpenMeetingsSmokeTest.java
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/web/TestLoginUI.java
Modified:
    openmeetings/trunk/singlewebapp/build.xml
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java

Modified: openmeetings/trunk/singlewebapp/build.xml
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/build.xml?rev=1525199&r1=1525198&r2=1525199&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/build.xml (original)
+++ openmeetings/trunk/singlewebapp/build.xml Sat Sep 21 06:50:09 2013
@@ -60,6 +60,10 @@
 
        <!-- screenshare.out.dir -->
        <property name="screenshare.out.dir" 
value="${dist.webapps.dir}/screensharing" />
+       
+       <condition property="junit.run.selenium" value="true" else="false">
+               <isset property="selenium" />
+       </condition>
 
        <property name="main.out.dir" 
value="${build.base.dir}/classes/openmeetings" />
 
@@ -736,6 +740,117 @@
                        </fileset>
                </copy>
        </target>
+       
+       <!-- 
+               Prepare selenium tests by starting up an OpenMeetings instance
+               
+               makes a stop command before starting up to make sure no other 
is running
+        -->
+       
+       <target name="prepare-selenium-start-openmeetings" description="Prepare 
selenium tests by starting up an OpenMeetings instance" 
+               depends="prepare-selenium-stop-openmeetings, 
-prepare-selenium-port-properties" >
+               <exec dir="${dist.dir}/testred5" executable="red5-highperf.bat" 
osfamily="windows" output="${dist.dir}/testred5/red5_system.log">
+               </exec>
+               <!--this does only make sense if the unix executable is run 
obviously, however we do it for all -->
+               <chmod dir="${dist.dir}/testred5" perm="755" includes="**/*.sh" 
/>
+               <exec dir="${dist.dir}/testred5" executable="/bin/bash" 
osfamily="unix" output="${dist.dir}/testred5/red5_system.log">
+                       <arg value="red5-highperf.sh"/> 
+               </exec>
+               <!-- start up does take some time -->
+               <sleep seconds="30" />
+       </target>
+       
+       <target name="prepare-selenium-stop-openmeetings" description="Prepare 
selenium tests by starting up an OpenMeetings instance" >
+               <exec dir="${dist.dir}/testred5" executable="red5-shutdown.bat" 
osfamily="windows" output="${dist.dir}/testred5/red5_system.log">
+               </exec>
+               <!--this does only make sense if executed on unix(Linux or OSX 
are both unix style) is run obviously, 
+                       however we do it for all for now -->
+               <chmod dir="${dist.dir}/testred5" perm="755" includes="**/*.sh" 
/>
+               <exec dir="${dist.dir}/testred5" executable="/bin/bash" 
osfamily="unix" output="${dist.dir}/testred5/red5_system.log">
+                       <arg value="red5-shutdown.sh"/> 
+               </exec>
+               <!-- stop up does take a bit of time -->
+               <sleep seconds="10" />
+       </target>
+       
+       <target name="-prepare-selenium-copy-test-instance" 
description="Prepare selenium tests by starting up an OpenMeetings instance">
+               <copy todir="${dist.dir}/testred5">
+                       <fileset dir="${dist.dir}/red5">
+                       </fileset>
+               </copy>
+       </target>
+       
+       <target name="-prepare-selenium-port-properties" description="Set the 
http port to some exotic numbers so that we don't conflict with anything" 
+                       depends="-prepare-selenium-copy-test-instance">
+               <replace dir="${dist.dir}/testred5/conf" 
value="http.port=20080">
+                 <include name="**/red5.properties"/>
+                 <replacetoken>http.port=5080</replacetoken>
+               </replace>
+               <replace dir="${dist.dir}/testred5/conf" 
value="https.port=20443">
+                 <include name="**/red5.properties"/>
+                 <replacetoken>https.port=5443</replacetoken>
+               </replace>
+               <replace dir="${dist.dir}/testred5/conf" 
value="rtmp.port=20935">
+                 <include name="**/red5.properties"/>
+                 <replacetoken>rtmp.port=1935</replacetoken>
+               </replace>
+               <replace dir="${dist.dir}/testred5/conf" 
value="rtmps.port=20443">
+                 <include name="**/red5.properties"/>
+                 <replacetoken>rtmps.port=8443</replacetoken>
+               </replace>
+               <replace dir="${dist.dir}/testred5/conf" 
value="rtmpt.port=20088">
+                 <include name="**/red5.properties"/>
+                 <replacetoken>rtmpt.port=8088</replacetoken>
+               </replace>
+       </target>
+       
+       <target name="run-selenium" depends="-dist-test-no-clean, 
-run-selenium-junit">
+       </target>
+       
+       <target name="-run-selenium" if="${junit.run.selenium}" >
+               <antcall target="-run-selenium-junit"></antcall>
+       </target>
+       
+       <target name="-run-selenium-junit" 
depends="prepare-selenium-start-openmeetings" 
+                       description="Will run all selenium tests unless 
-Dtestcases=_file_name_pattern_ will be passed">
+               <taskdef resource="net/sf/antcontrib/antlib.xml">
+                       <classpath refid="junit.classpath" />
+               </taskdef>
+               <mkdir dir="${junit.report.dir}" />
+               
+               <junit maxmemory="1024m" printsummary="yes" 
dir="${junit.base.dir}" tempdir="${junit.base.dir}" fork="yes" 
+                       forkmode="perBatch" failureproperty="junit.failed" 
errorproperty="junit.error">
+                       <classpath refid="junit.classpath" />
+                       <jvmarg value="-Dom.home=${basedir}/${om.dist.webapp}" 
/>
+                       <jvmarg 
value="-Dlanguages.home=${webapp.dir}/languages" />
+                       <jvmarg value="-Dred5.root=${red5.root}" />
+                       <jvmarg value="-Dbasedir=${basedir}" />
+                       <jvmarg value="-Dred5.config_root=${red5.root}/conf" />
+                       <jvmarg value="-Dbackups.dir=${junit.backups.dir}" />
+                       <formatter type="${junit.test.formatter}" />
+                       <batchtest todir="${junit.report.dir}">
+                               <fileset dir="${main.out.dir}">
+                                       <include 
name="org/apache/openmeetings/test/selenium/${junit.test.pattern}.class" />
+                                       <exclude name="**/*$$*.class" />
+                               </fileset>
+                       </batchtest>
+               </junit>
+               
+               <junitreport todir="${junit.report.dir}">
+                       <fileset dir="${junit.report.dir}">
+                               <include name="TEST-*.xml" />
+                       </fileset>
+                       <report todir="${junit.report.dir}" />
+               </junitreport>
+               <fail message="Errors/failures in JUnit tests.">
+                       <condition>
+                               <or>
+                                       <isset property="junit.failed"/>
+                                       <isset property="junit.error"/>
+                               </or>
+                       </condition>
+               </fail>
+       </target>
 
        <!-- Unit Tests -->
        <property name="om.dist.webapp" 
value="${red5.root}/webapps/${project.distname}" />
@@ -743,7 +858,7 @@
        <condition property="junit.test.pattern" value="${testcases}" 
else="Test*">
                <isset property="testcases" />
        </condition>
-
+       
        <condition property="junit.test.formatter" value="${test.formatter}" 
else="xml">
                <isset property="test.formatter" />
        </condition>
@@ -761,7 +876,10 @@
                <pathelement path="${dist.classes.dir}" />
                <pathelement path="${main.out.dir}" />
        </path>
-       <target name="test" depends="-dist-test-no-clean" description="Will run 
all tests unless -Dtestcases=_file_name_pattern_ will be passed">
+       
+       
+       <target name="test" depends="-dist-test-no-clean, -run-selenium" 
+                       description="Will run all tests except selenium unless 
-Dtestcases=_file_name_pattern_ will be passed">
                <taskdef resource="net/sf/antcontrib/antlib.xml">
                        <classpath refid="junit.classpath" />
                </taskdef>
@@ -794,10 +912,12 @@
                        <batchtest todir="${junit.report.dir}">
                                <fileset dir="${main.out.dir}">
                                        <include 
name="org/apache/openmeetings/test/**/${junit.test.pattern}.class" />
+                                       <exclude 
name="org/apache/openmeetings/test/selenium/${junit.test.pattern}.class" />
                                        <exclude name="**/*$$*.class" />
                                </fileset>
                        </batchtest>
                </junit>
+               
                <junitreport todir="${junit.report.dir}">
                        <fileset dir="${junit.report.dir}">
                                <include name="TEST-*.xml" />

Modified: 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java?rev=1525199&r1=1525198&r2=1525199&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java
 Sat Sep 21 06:50:09 2013
@@ -18,9 +18,16 @@
  */
 package org.apache.openmeetings.test.selenium;
 
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 
+import org.apache.commons.io.FileUtils;
 import org.openqa.selenium.By;
+import org.openqa.selenium.OutputType;
+import org.openqa.selenium.TakesScreenshot;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 
@@ -31,14 +38,30 @@ public class SeleniumUtils {
        // we need to sleep to make sure Ajax could complete whatever it does
        static long defaultSleepInterval = 1000;
 
-       public static void inputText(WebDriver driver, String search, String 
inputText) throws Exception {
-               WebElement element = SeleniumUtils.findElement(driver, search);
+       public static void inputText(WebDriver driver, String search,
+                       String inputText) throws Exception {
+               WebElement element = SeleniumUtils.findElement(driver, search, 
true);
 
                // Would make send to check if this element is really an input 
text
                element.sendKeys(inputText);
        }
 
-       public static WebElement findElement(WebDriver driver, String search) 
throws Exception {
+       public static void click(WebDriver driver, String search) throws 
Exception {
+               WebElement element = SeleniumUtils.findElement(driver, search, 
true);
+               element.click();
+       }
+
+       /**
+        * 
+        * @param driver
+        * @param search
+        * @param throwException
+        *            under some circumstance you do't want to exit the test 
here
+        * @return
+        * @throws Exception
+        */
+       public static WebElement findElement(WebDriver driver, String search,
+                       boolean throwException) throws Exception {
                for (int i = 0; i < numberOfRetries; i++) {
                        WebElement element = _findElement(driver, search);
                        if (element != null) {
@@ -48,11 +71,22 @@ public class SeleniumUtils {
                        Thread.sleep(defaultSleepInterval);
                }
 
-               throw new Exception("Could not find element with specified path 
" + search);
+               if (throwException) {
+                       throw new Exception("Could not find element with 
specified path "
+                                       + search);
+               }
+
+               return null;
        }
 
        private static By[] _getSearchArray(String search) {
-               return new By[] { By.id(search), By.name(search), 
By.className(search), By.tagName(search), By.xpath(search) };
+               //If xpath we have to use it, if xpath is used with 
By.className(...) there will be an exception
+               if (search.startsWith("//")) {
+                       return new By[] { By.xpath(search) };
+               } else {
+                       return new By[] { By.id(search), By.name(search), 
By.className(search),
+                                       By.tagName(search), By.xpath(search) };
+               }
        }
 
        private static WebElement _findElement(WebDriver driver, String search) 
{
@@ -69,7 +103,8 @@ public class SeleniumUtils {
                return null;
        }
 
-       public static void elementExists(WebDriver driver, String search, 
boolean shouldExist) throws Exception {
+       public static void elementExists(WebDriver driver, String search,
+                       boolean shouldExist) throws Exception {
                Thread.sleep(defaultSleepInterval);
 
                boolean doesExist = !shouldExist;
@@ -105,4 +140,43 @@ public class SeleniumUtils {
                }
                return false;
        }
-}
+
+       public static void makeScreenShot(String testName, Exception e,
+                       WebDriver driver) {
+               try {
+                       DateFormat df = new 
SimpleDateFormat("MM-dd-yyyy_HH-mm-ss");
+                       String fileName = e.getMessage().replace(" ", "_");
+                       fileName = fileName.replaceAll("(\r\n|\n)", "");
+                       fileName = fileName.replaceAll("/", "");
+
+                       if (fileName.length() > 100) {
+                               fileName = fileName.substring(0, 100);
+                       }
+
+                       fileName = fileName + "_" + df.format(new Date()) + 
".png";
+                       File screenShotFile = ((TakesScreenshot) driver)
+                                       .getScreenshotAs(OutputType.FILE);
+
+                       String path = "." + File.separatorChar + "build"
+                                       + File.separatorChar + "screenshots" + 
File.separatorChar
+                                       + testName;
+
+                       File screenshotFolder = new File(path);
+                       if (!screenshotFolder.exists()) {
+                               screenshotFolder.mkdirs();
+                       }
+
+                       System.out.println("screenshot copy from: "
+                                       + screenShotFile.getAbsolutePath());
+                       System.out.println("Length Filename: " + 
fileName.length()
+                                       + " - Writing screenshot to: " + path + 
File.separatorChar
+                                       + fileName);
+
+                       FileUtils.moveFile(screenShotFile, new File(path
+                                       + File.separatorChar + fileName));
+               } catch (Exception err) {
+                       err.printStackTrace();
+               }
+
+       }
+}
\ No newline at end of file

Copied: 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java
 (from r1523184, 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/OpenMeetingsSmokeTest.java)
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java?p2=openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java&p1=openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/OpenMeetingsSmokeTest.java&r1=1523184&r2=1525199&rev=1525199&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/OpenMeetingsSmokeTest.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java
 Sat Sep 21 06:50:09 2013
@@ -18,38 +18,126 @@
  */
 package org.apache.openmeetings.test.selenium;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.JavascriptExecutor;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.firefox.FirefoxDriver;
 
-public class OpenMeetingsSmokeTest {
+public class TestSeleniumSmokeTest {
 
-       public static String BASE_URL = "http://localhost:5080/openmeetings";;
+       public static String BASE_URL = "http://localhost:20080/openmeetings";;
        public static String username = "swagner";
        public static String userpass = "qweqwe";
+       private static final String orgname = "seleniumtest";
+       private static final String email = "[email protected]";
 
-       public static void main(String[] args) {
-               try {
+       public WebDriver driver = null;
 
-                       WebDriver driver = new FirefoxDriver();
+       // setting this to false can be handy if you run the test from inside
+       // Eclipse, the browser will not shut down after the test so you can 
start
+       // to diagnose the test issue
+       public boolean doTearDownAfterTest = false;
+
+       @Before
+       public void setUp() {
+               driver = new FirefoxDriver();
+       }
 
+       @Test
+       public void smokeTest() throws Exception {
+               try {
                        driver.get(BASE_URL);
                        
+                       testWebSite();
+                       
                        SeleniumUtils.inputText(driver, "login", username);
                        SeleniumUtils.inputText(driver, "pass", userpass);
-                       
+
                        WebElement signInButton = 
SeleniumUtils.findElement(driver,
-                                       "//button[span[contains(text(), 'Sign 
in')]]");
+                                       "//button[span[contains(text(), 'Sign 
in')]]", true);
                        signInButton.click();
-                       
-                       SeleniumUtils.elementExists(driver, 
"//h3[contains(text(), 'Help and support')]", true);
-                       
-                       
 
+                       SeleniumUtils.elementExists(driver,
+                                       "//h3[contains(text(), 'Help and 
support')]", true);
                } catch (Exception e) {
-                       e.printStackTrace();
+                       
SeleniumUtils.makeScreenShot(this.getClass().getSimpleName(), e,
+                                       driver);
+                       throw e;
+               }
+       }
+
+       private void testWebSite() throws Exception {
+               
+               WebElement wicketExtensionsWizardHeaderTitle = 
SeleniumUtils.findElement(driver,
+                               "wicketExtensionsWizardHeaderTitle", false);
+               if (wicketExtensionsWizardHeaderTitle == null) {
+                       return;
                }
+               if 
(wicketExtensionsWizardHeaderTitle.getText().contains("Installation")) {
+                       System.out.println("Do Installation");
+                       doInstallation();
+               }
+               
+       }
+       
+       private void doInstallation() throws Exception {
+               Thread.sleep(3000L);
+               
+               WebElement buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               
+               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               
+               Thread.sleep(1000L);
+               
+               SeleniumUtils.inputText(driver, "view:cfg.username", username);
+               SeleniumUtils.inputText(driver, "view:cfg.password", userpass);
+               SeleniumUtils.inputText(driver, "view:cfg.email", email);
+               SeleniumUtils.inputText(driver, "view:cfg.group", orgname);
+               
+               buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               
+               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               
+               Thread.sleep(1000L);
+               
+               buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               
+               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               
+               Thread.sleep(1000L);
+               
+               buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               
+               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               
+               Thread.sleep(1000L);
+               
+               buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               
+               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               
+               Thread.sleep(1000L);
+               
+               WebElement buttons_finish = SeleniumUtils.findElement(driver, 
"buttons:finish", true);
+               
+               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_finish);
+               
+               //Installation takes a while
+               Thread.sleep(30000L);
+               
+               //the ajax loading thing does not work, just goto the main page
+               driver.get(BASE_URL);
+       }
 
+       @After
+       public void tearDown() throws Exception {
+               if (doTearDownAfterTest) {
+                       driver.close();
+                       driver.quit();
+               }
        }
 
 }

Added: 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/web/LoginUI.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/web/LoginUI.java?rev=1525199&view=auto
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/web/LoginUI.java
 (added)
+++ 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/web/LoginUI.java
 Sat Sep 21 06:50:09 2013
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.test.web;
+
+import org.apache.openmeetings.test.AbstractWicketTester;
+import org.apache.openmeetings.web.pages.MainPage;
+import org.apache.openmeetings.web.pages.auth.SignInPage;
+import org.apache.wicket.util.tester.FormTester;
+
+public class LoginUI extends AbstractWicketTester {
+
+        //@Test Needs to much memory to start this test, and there is nothing 
useful here inside other then some basic
+        //proof of concept (basically the concept failed)
+       public void testLoginUi() {
+               
+               tester.startPage(MainPage.class);
+               
+               tester.assertRenderedPage(SignInPage.class);
+               
+               FormTester formTester = tester.newFormTester("signin:signin");
+               formTester.setValue("login", username);
+               formTester.setValue("pass", userpass);
+               
+               //How to reference specific buttons in Wicket jQuery UI ?!
+               
+               formTester.submit();
+               
+               System.err.println("getLastRenderedPage: "+ 
tester.getLastRenderedPage().getMarkup().toString());
+               
+               //will fail
+               //tester.assertComponent("dashboard", DashboardPanel.class);
+               
+       }
+       
+}
+


Reply via email to