Author: lfryc(a)redhat.com
Date: 2010-07-10 17:11:05 -0400 (Sat, 10 Jul 2010)
New Revision: 17906
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/SeleniumGetter.java
Log:
added SeleniumGetter - abstract implementation and factory for simplified obtaining
values, text and evaluation of scripts
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/SeleniumGetter.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/SeleniumGetter.java
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/jboss/test/selenium/SeleniumGetter.java 2010-07-10
21:11:05 UTC (rev 17906)
@@ -0,0 +1,101 @@
+package org.jboss.test.selenium;
+
+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.locator.ElementLocator;
+import org.jboss.test.selenium.utils.PrimitiveUtils;
+import org.jboss.test.selenium.waiting.conversion.Convertor;
+
+public abstract class SeleniumGetter<P> {
+ protected AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+ protected P parameter;
+
+ public SeleniumGetter(P parameter) {
+ this.parameter = parameter;
+ }
+
+ protected abstract String obtainValue();
+
+ public Boolean asBoolean() {
+ return PrimitiveUtils.asBoolean(obtainValue());
+ }
+
+ public Integer asInteger() {
+ return PrimitiveUtils.asInteger(obtainValue());
+ }
+
+ public Long asLong() {
+ return PrimitiveUtils.asLong(obtainValue());
+ }
+
+ public Float asFloat() {
+ return PrimitiveUtils.asFloat(obtainValue());
+ }
+
+ public Double asDouble() {
+ return PrimitiveUtils.asDouble(obtainValue());
+ }
+
+ public <C> C convert(Convertor<String, C> converter) {
+ return converter.forwardConversion(obtainValue());
+ }
+
+ public static ValueGetter getValue(ElementLocator elementLocator) {
+ return new ValueGetter(elementLocator);
+ }
+
+ public static TextGetter getText(ElementLocator elementLocator) {
+ return new TextGetter(elementLocator);
+ }
+
+ public static Evaluator getEval(JavaScript script) {
+ return new Evaluator(script);
+ }
+
+ public static class ValueGetter extends SeleniumGetter<ElementLocator> {
+
+ public ValueGetter(ElementLocator parameter) {
+ super(parameter);
+ }
+
+ @Override
+ protected String obtainValue() {
+ return selenium.getValue(parameter);
+ }
+
+ }
+
+ public static class TextGetter extends SeleniumGetter<ElementLocator> {
+
+ public TextGetter(ElementLocator parameter) {
+ super(parameter);
+ }
+
+ @Override
+ protected String obtainValue() {
+ return selenium.getText(parameter);
+ }
+ }
+
+ public static class Evaluator extends SeleniumGetter<JavaScript> {
+
+ public Evaluator(JavaScript parameter) {
+ super(parameter);
+ }
+
+ @Override
+ protected String obtainValue() {
+ String evaluated = selenium.getEval(parameter);
+ evaluated = checkNull(evaluated);
+ return evaluated;
+ }
+ }
+
+ private static String checkNull(String evaluatedResult) {
+ if ("null".equals(evaluatedResult) ||
"undefined".equals(evaluatedResult)) {
+ return null;
+ }
+ return evaluatedResult;
+ }
+}
Show replies by date