Author: lfryc(a)redhat.com
Date: 2010-07-10 17:09:23 -0400 (Sat, 10 Jul 2010)
New Revision: 17901
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/javascript/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/javascript/JavaScriptEvaluator.java
Log:
JavaScriptEvaluator - simplifies manipulation with results of evaluated JavaScript
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/javascript/JavaScriptEvaluator.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/javascript/JavaScriptEvaluator.java
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/javascript/JavaScriptEvaluator.java 2010-07-10
21:09:23 UTC (rev 17901)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.selenium.javascript;
+
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.waiting.conversion.Convertor;
+
+import static org.jboss.test.selenium.utils.PrimitiveUtils.*;
+
+/**
+ * Simplifies manipulation with results of evaluated JavaScript.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public final class JavaScriptEvaluator {
+
+ private static final AjaxSelenium SELENIUM = AjaxSeleniumProxy.getInstance();
+
+ private JavaScriptEvaluator() {
+ }
+
+ /**
+ * Returns the evaluated JavaScript result.
+ *
+ * @param script
+ * to evaluate
+ * @return the evaluated JavaScript result.
+ */
+ public static String evaluateString(JavaScript script) {
+ return checkNull(SELENIUM.getEval(script));
+ }
+
+ /**
+ * Returns the evaluated JavaScript result as Boolean.
+ *
+ * @param script
+ * to evaluate
+ * @return the evaluated JavaScript result as Boolean.
+ */
+ public static Boolean evaluateBoolean(JavaScript script) {
+ return asBoolean(checkNull(SELENIUM.getEval(script)));
+ }
+
+ /**
+ * Returns the evaluated JavaScript result as Float.
+ *
+ * @param script
+ * to evaluate
+ * @return the evaluated JavaScript result as Float.
+ */
+ public static Float evaluateFloat(JavaScript script) {
+ return asFloat(checkNull(SELENIUM.getEval(script)));
+ }
+
+ /**
+ * Returns the evaluated JavaScript result as Double.
+ *
+ * @param script
+ * to evaluate
+ * @return the evaluated JavaScript result as Double.
+ */
+ public static Double evaluateDouble(JavaScript script) {
+ return asDouble(checkNull(SELENIUM.getEval(script)));
+ }
+
+ /**
+ * Returns the evaluated JavaScript result as Long.
+ *
+ * @param script
+ * to evaluate
+ * @return the evaluated JavaScript result as Long.
+ */
+ public static Long evaluateLong(JavaScript script) {
+ return asLong(checkNull(SELENIUM.getEval(script)));
+ }
+
+ /**
+ * Returns the evaluated JavaScript result as Integer.
+ *
+ * @param script
+ * to evaluate
+ * @return the evaluated JavaScript result as Integer.
+ */
+ public static Integer evaluateInteger(JavaScript script) {
+ return asInteger(checkNull(SELENIUM.getEval(script)));
+ }
+
+ /**
+ * Returns the evaluated JavaScript result converted to T by specified converter.
+ *
+ * @param script
+ * the script to evaluate
+ * @return the evaluated JavaScript result converted to T by specified converter.
+ */
+ public static <T> T evaluate(JavaScript script, Convertor<String, T>
converter) {
+ String result = checkNull(SELENIUM.getEval(script));
+ if (result == null) {
+ return null;
+ }
+ return converter.forwardConversion(result);
+ }
+
+ private static String checkNull(String evaluatedResult) {
+ if ("null".equals(evaluatedResult) ||
"undefined".equals(evaluatedResult)) {
+ return null;
+ }
+ return evaluatedResult;
+ }
+}