You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by se...@apache.org on 2013/09/14 06:25:39 UTC
svn commit: r1523184 - in /openmeetings/trunk/singlewebapp: ./
src/test/java/org/apache/openmeetings/test/selenium/
Author: sebawagner
Date: Sat Sep 14 04:25:37 2013
New Revision: 1523184
URL: http://svn.apache.org/r1523184
Log:
OPENMEETINGS-792 Add Selenium library and some basic validation methods for writing tests
Added:
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/OpenMeetingsSmokeTest.java
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java
Modified:
openmeetings/trunk/singlewebapp/ivy.xml
Modified: openmeetings/trunk/singlewebapp/ivy.xml
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/ivy.xml?rev=1523184&r1=1523183&r2=1523184&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/ivy.xml (original)
+++ openmeetings/trunk/singlewebapp/ivy.xml Sat Sep 14 04:25:37 2013
@@ -34,6 +34,7 @@
<conf name="mysql" description="MySQL JDBC driver" />
<conf name="mvn" description="Maven Ant task to build Red5" />
<conf name="tomcat7" description="Libraries necessary for patching Red5 to use Tomcat7" />
+ <conf name="selenium" description="Selenium dependencies" />
</configurations>
<dependencies>
<!-- START OF mainlib -->
@@ -401,6 +402,11 @@
<dependency org="tomcatplugin" name="tomcatplugin" rev="1.4" conf="tomcat7->*" transitive="false">
<include type="jar" />
</dependency>
+
+ <!-- Selenium -->
+ <dependency org="org.seleniumhq.selenium" name="selenium-java" conf="selenium->*" rev="2.35.0" >
+ <include type="jar" />
+ </dependency>
<exclude org="javax.servlet" module="servlet-api" type="*" ext="*" conf="*" matcher="exact"/>
</dependencies>
Added: 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/OpenMeetingsSmokeTest.java?rev=1523184&view=auto
==============================================================================
--- openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/OpenMeetingsSmokeTest.java (added)
+++ openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/OpenMeetingsSmokeTest.java Sat Sep 14 04:25:37 2013
@@ -0,0 +1,55 @@
+/*
+ * 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.selenium;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.firefox.FirefoxDriver;
+
+public class OpenMeetingsSmokeTest {
+
+ public static String BASE_URL = "http://localhost:5080/openmeetings";
+ public static String username = "swagner";
+ public static String userpass = "qweqwe";
+
+ public static void main(String[] args) {
+ try {
+
+ WebDriver driver = new FirefoxDriver();
+
+ driver.get(BASE_URL);
+
+ SeleniumUtils.inputText(driver, "login", username);
+ SeleniumUtils.inputText(driver, "pass", userpass);
+
+ WebElement signInButton = SeleniumUtils.findElement(driver,
+ "//button[span[contains(text(), 'Sign in')]]");
+ signInButton.click();
+
+ SeleniumUtils.elementExists(driver, "//h3[contains(text(), 'Help and support')]", true);
+
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
Added: 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=1523184&view=auto
==============================================================================
--- openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java (added)
+++ openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java Sat Sep 14 04:25:37 2013
@@ -0,0 +1,167 @@
+/*
+ * 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.selenium;
+
+import java.util.List;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+public class SeleniumUtils {
+
+ //we need to retry some actions because our web site is dynamic
+ static int numberOfRetries = 10;
+
+ //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);
+
+ // 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 {
+
+ for (int i=0;i<numberOfRetries;i++) {
+ WebElement element = _findElement(driver, search);
+ if (element != null) {
+ return element;
+ }
+
+ Thread.sleep(defaultSleepInterval);
+ }
+
+
+ throw new Exception("Could not find element with specified path "
+ + search);
+ }
+
+ private static WebElement _findElement(WebDriver driver, String search) {
+
+ try {
+ WebElement element = driver.findElement(By.id(search));
+ if (element != null) {
+ return element;
+ }
+ } catch (Exception e) {
+ // Do not show any warnings
+ }
+
+ try {
+ WebElement element = driver.findElement(By.name(search));
+ if (element != null) {
+ return element;
+ }
+ } catch (Exception e) {
+ // Do not show any warnings
+ }
+ try {
+ WebElement element = driver.findElement(By.className(search));
+ if (element != null) {
+ return element;
+ }
+ } catch (Exception e) {
+ // Do not show any warnings
+ }
+ try {
+ WebElement element = driver.findElement(By.tagName(search));
+ if (element != null) {
+ return element;
+ }
+ } catch (Exception e) {
+ // Do not show any warnings
+ }
+ try {
+ WebElement element = driver.findElement(By.xpath(search));
+ if (element != null) {
+ return element;
+ }
+ } catch (Exception e) {
+ // Do not show any warnings
+ }
+
+ return null;
+
+
+ }
+
+ public static void elementExists(WebDriver driver, String search, boolean shouldExist) throws Exception {
+
+ Thread.sleep(defaultSleepInterval);
+
+ boolean doesExist = !shouldExist;
+
+ for (int i=0;i<numberOfRetries;i++) {
+ doesExist = checkExists(driver, search);
+ if (doesExist == shouldExist) {
+ break;
+ }
+
+ Thread.sleep(defaultSleepInterval);
+ }
+
+ if (doesExist != shouldExist) {
+ if (shouldExist) {
+ throw new Exception("Element could not be found: " + search);
+ } else {
+ throw new Exception("Unexpected Element was found: " + search);
+ }
+ }
+
+ }
+
+ private static boolean checkExists(WebDriver driver, String search)
+ throws Exception {
+ try {
+ List<WebElement> element = driver.findElements(By.id(search));
+ if (element.size() > 0) {
+ return true;
+ }
+
+ element = driver.findElements(By.name(search));
+ if (element.size() > 0) {
+ return true;
+ }
+
+ element = driver.findElements(By.className(search));
+ if (element.size() > 0) {
+ return true;
+ }
+
+ element = driver.findElements(By.tagName(search));
+ if (element.size() > 0) {
+ return true;
+ }
+
+ element = driver.findElements(By.xpath(search));
+ if (element.size() > 0) {
+ return true;
+ }
+ } catch (Exception e) {
+ // Do not show any warnings
+ }
+ return false;
+ }
+
+}