Author: lfryc(a)redhat.com
Date: 2011-01-19 13:42:01 -0500 (Wed, 19 Jan 2011)
New Revision: 21100
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/retriever/ColorRetriever.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/TestSimple.java
Log:
fixed the jquery tests by introducing color conversion mechanism
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/retriever/ColorRetriever.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/retriever/ColorRetriever.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/retriever/ColorRetriever.java 2011-01-19
18:42:01 UTC (rev 21100)
@@ -0,0 +1,109 @@
+/*
+ * 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.cheiron.retriever;
+
+import java.awt.Color;
+
+import org.apache.commons.lang.Validate;
+import org.jboss.test.selenium.css.CssProperty;
+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.ColorUtils;
+import org.jboss.test.selenium.waiting.conversion.Convertor;
+import org.jboss.test.selenium.waiting.conversion.PassOnConvertor;
+import org.jboss.test.selenium.waiting.retrievers.AbstractRetriever;
+import org.jboss.test.selenium.waiting.retrievers.Retriever;
+
+import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
+import static org.jboss.test.selenium.encapsulated.JavaScript.js;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class ColorRetriever extends AbstractRetriever<Color> implements
Retriever<Color> {
+
+ private AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ private ElementLocator<?> elementLocator;
+
+ public ColorRetriever() {
+ }
+
+ public Color retrieve() {
+ Validate.notNull(elementLocator);
+
+ String value = selenium.getStyle(elementLocator, CssProperty.COLOR);
+ return ColorUtils.convertToAWTColor(value);
+ }
+
+ public JavaScript getJavaScriptRetrieve() {
+ final String colorPropertyName = CssProperty.COLOR.getPropertyName();
+ return js(format("selenium.getStyle('{0}', '{1}')",
elementLocator.getAsString(), colorPropertyName));
+ }
+
+ public static ColorRetriever getInstance() {
+ return new ColorRetriever();
+ }
+
+ public ColorRetriever locator(ElementLocator<?> elementLocator) {
+ Validate.notNull(elementLocator);
+
+ ColorRetriever copy = copy();
+ copy.elementLocator = elementLocator;
+
+ return copy;
+ }
+
+ /**
+ * Returns a copy of this textRetriever with exactly same settings.
+ *
+ * Keeps the immutability of this class.
+ *
+ * @return the exact copy of this textRetriever
+ */
+ private ColorRetriever copy() {
+ ColorRetriever copy = new ColorRetriever();
+ copy.elementLocator = elementLocator;
+ return copy;
+ }
+
+ /**
+ * Uses {@link PassOnConvertor} to pass the JavaScript result to result value.
+ */
+ public Convertor<Color, String> getConvertor() {
+ return new ColorConvertor();
+ }
+
+ public static class ColorConvertor implements Convertor<Color, String> {
+ @Override
+ public String forwardConversion(Color object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Color backwardConversion(String object) {
+ return ColorUtils.convertToAWTColor(object);
+ }
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/TestSimple.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/TestSimple.java 2011-01-19
18:32:36 UTC (rev 21099)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richJQuery/TestSimple.java 2011-01-19
18:42:01 UTC (rev 21100)
@@ -26,9 +26,10 @@
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.testng.Assert.assertEquals;
+import java.awt.Color;
import java.net.URL;
-import org.jboss.test.selenium.css.CssProperty;
+import org.jboss.cheiron.retriever.ColorRetriever;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.testng.annotations.Test;
@@ -46,6 +47,8 @@
RichJQueryAttributes attributes = new RichJQueryAttributes();
+ ColorRetriever buttonColorRetriver = new ColorRetriever().locator(button);
+
@Override
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/richJQuery/simple.xhtml");
@@ -55,20 +58,21 @@
public void testDefaultTiming() {
setupDomReadyTypeAttributes();
attributes.setTiming(null);
- assertEquals("red", selenium.getStyle(button, CssProperty.COLOR));
+ assertEquals(buttonColorRetriver.retrieve(), Color.RED);
}
@Test
public void testTimingImmediate() {
setupImmediateTypeAttributes();
+ buttonColorRetriver.initializeValue();
selenium.click(button);
-
waitGui.until(styleEquals.locator(button).property(CssProperty.COLOR).value("red"));
+ assertEquals(waitModel.waitForChangeAndReturn(buttonColorRetriver), Color.RED);
}
@Test
public void testTimingDomReady() {
setupDomReadyTypeAttributes();
- assertEquals("red", selenium.getStyle(button, CssProperty.COLOR));
+ assertEquals(buttonColorRetriver.retrieve(), Color.RED);
}
@Test