Author: sebawagner
Date: Sat Sep 28 05:29:59 2013
New Revision: 1527152

URL: http://svn.apache.org/r1527152
Log:
OPENMEETINGS-792 Fix test to successfully do install, in case it detects it is 
not installed yet, timeout for installation wizzard progress is 120seconds, but 
it will check in 3 second intervals for the link in the complete screen 

Modified:
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java

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=1527152&r1=1527151&r2=1527152&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 28 05:29:59 2013
@@ -50,6 +50,34 @@ public class SeleniumUtils {
                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 List<WebElement> findElements(WebDriver driver, String 
search,
+                       boolean throwException) throws Exception {
+               for (int i = 0; i < numberOfRetries; i++) {
+                       List<WebElement> elements = _findElement(driver, 
search);
+                       if (elements != null) {
+                               return elements;
+                       }
+
+                       Thread.sleep(defaultSleepInterval);
+               }
+
+               if (throwException) {
+                       throw new Exception("Could not find element with 
specified path "
+                                       + search);
+               }
+
+               return null;
+       }
 
        /**
         * 
@@ -63,9 +91,9 @@ public class SeleniumUtils {
        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) {
-                               return element;
+                       List<WebElement> elements = _findElement(driver, 
search);
+                       if (elements != null) {
+                               return elements.get(0);
                        }
 
                        Thread.sleep(defaultSleepInterval);
@@ -89,12 +117,15 @@ public class SeleniumUtils {
                }
        }
 
-       private static WebElement _findElement(WebDriver driver, String search) 
{
+       private static List<WebElement> _findElement(WebDriver driver, String 
search) {
                for (By by : _getSearchArray(search)) {
                        try {
-                               WebElement element = driver.findElement(by);
-                               if (element != null) {
-                                       return element;
+                               
+                               
+                               
+                               List<WebElement> elements = 
driver.findElements(by);
+                               if (elements != null && elements.size() > 0) {
+                                       return elements;
                                }
                        } catch (Exception e) {
                                // Do not show any warnings

Modified: 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java?rev=1527152&r1=1527151&r2=1527152&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/TestSeleniumSmokeTest.java
 Sat Sep 28 05:29:59 2013
@@ -18,17 +18,19 @@
  */
 package org.apache.openmeetings.test.selenium;
 
+import java.util.List;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.Keys;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.firefox.FirefoxDriver;
 
 public class TestSeleniumSmokeTest {
 
-       public static String BASE_URL = "http://localhost:20080/openmeetings";;
+       public static String BASE_URL = "http://localhost:5080/openmeetings";;
        public static String username = "swagner";
        public static String userpass = "qweqwe";
        private static final String orgname = "seleniumtest";
@@ -86,9 +88,9 @@ public class TestSeleniumSmokeTest {
        private void doInstallation() throws Exception {
                Thread.sleep(3000L);
                
-               WebElement buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               List<WebElement> buttons_next = 
SeleniumUtils.findElements(driver, "buttons:next", true);
                
-               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               buttons_next.get(1).sendKeys(Keys.RETURN);
                
                Thread.sleep(1000L);
                
@@ -97,39 +99,57 @@ public class TestSeleniumSmokeTest {
                SeleniumUtils.inputText(driver, "view:cfg.email", email);
                SeleniumUtils.inputText(driver, "view:cfg.group", orgname);
                
-               buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               buttons_next = SeleniumUtils.findElements(driver, 
"buttons:next", true);
                
-               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               buttons_next.get(1).sendKeys(Keys.RETURN);
                
                Thread.sleep(1000L);
                
-               buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               buttons_next = SeleniumUtils.findElements(driver, 
"buttons:next", true);
                
-               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               buttons_next.get(1).sendKeys(Keys.RETURN);
                
                Thread.sleep(1000L);
                
-               buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               buttons_next = SeleniumUtils.findElements(driver, 
"buttons:next", true);
                
-               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               buttons_next.get(1).sendKeys(Keys.RETURN);
                
                Thread.sleep(1000L);
                
-               buttons_next = SeleniumUtils.findElement(driver, 
"buttons:next", true);
+               buttons_next = SeleniumUtils.findElements(driver, 
"buttons:next", true);
                
-               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_next);
+               buttons_next.get(1).sendKeys(Keys.RETURN);
                
-               Thread.sleep(1000L);
+               Thread.sleep(2000L);
+               
+               List<WebElement> elements = SeleniumUtils.findElements(driver, 
"buttons:finish", true);
                
-               WebElement buttons_finish = SeleniumUtils.findElement(driver, 
"buttons:finish", true);
+               elements.get(1).sendKeys(Keys.RETURN);
                
-               ((JavascriptExecutor) 
driver).executeScript("arguments[0].click();", buttons_finish);
+               long maxMilliSecondsWait = 120000;
                
-               //Installation takes a while
-               Thread.sleep(30000L);
+               while (maxMilliSecondsWait > 0) {
+                       
+                       //check if installation is complete by searching for 
the link on the success page
+                       WebElement enterApplicationLink = 
SeleniumUtils.findElement(driver, 
+                                                               
"//a[contains(@href,'install')]", false);
+                       
+                       if (enterApplicationLink == null) {
+                               System.out.println("Installation running - wait 
3 more seconds and check again");
+                               
+                               Thread.sleep(3000L);
+                               maxMilliSecondsWait -= 3000;
+                       } else {
+                               maxMilliSecondsWait = 0;
+                               
+                               enterApplicationLink.click();
+                               
+                               return;
+                       }
+               }
                
-               //the ajax loading thing does not work, just goto the main page
-               driver.get(BASE_URL);
+               throw new Exception("Timeout during installation");
        }
 
        @After


Reply via email to