You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2013/09/14 09:18:29 UTC
svn commit: r1523189 -
/openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.java
Author: solomax
Date: Sat Sep 14 07:18:29 2013
New Revision: 1523189
URL: http://svn.apache.org/r1523189
Log:
[OPENMEETINGS-792] code clean up
Modified:
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/selenium/SeleniumUtils.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=1523189&r1=1523188&r2=1523189&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 14 07:18:29 2013
@@ -25,102 +25,64 @@ 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
+ // 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
+
+ // 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 {
+ 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++) {
+ 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);
+
+ throw new Exception("Could not find element with specified path " + search);
}
- private static WebElement _findElement(WebDriver driver, String search) {
+ private static By[] _getSearchArray(String search) {
+ return new By[] { By.id(search), By.name(search), By.className(search), By.tagName(search), By.xpath(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;
+ private static WebElement _findElement(WebDriver driver, String search) {
+ for (By by : _getSearchArray(search)) {
+ try {
+ WebElement element = driver.findElement(by);
+ if (element != null) {
+ return element;
+ }
+ } catch (Exception e) {
+ // Do not show any warnings
}
- } 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++) {
+
+ 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);
@@ -128,40 +90,19 @@ public class SeleniumUtils {
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;
+ private static boolean checkExists(WebDriver driver, String search) {
+ for (By by : _getSearchArray(search)) {
+ try {
+ List<WebElement> element = driver.findElements(by);
+ if (element.size() > 0) {
+ return true;
+ }
+ } catch (Exception e) {
+ // Do not show any warnings
}
-
- 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;
}
-
}