Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for @Page in test superclass

  • Loading branch information...
commit dd63cff9f04cc22e4d9e17b4afdad5185a3c3c69 1 parent 4dcad72
Jean-Christophe Sirot authored
View
9 fluentlenium-core/src/main/java/org/fluentlenium/core/FluentAdapter.java
@@ -29,16 +29,17 @@ public FluentAdapter() {
protected void initTest() {
Class cls = null;
try {
- cls = Class.forName(this.getClass().getName());
- for (Field field : cls.getDeclaredFields()) {
+ for (cls = Class.forName(this.getClass().getName()); FluentAdapter.class.isAssignableFrom(cls); cls = cls.getSuperclass()) {
+ for (Field field : cls.getDeclaredFields()) {
if (field.isAnnotationPresent(Page.class)) {
field.setAccessible(true);
Class clsField = field.getType();
- cls = Class.forName(clsField.getName());
- Object page = initClass(cls);
+ Class clsPage = Class.forName(clsField.getName());
+ Object page = initClass(clsPage);
field.set(this, page);
}
}
+ }
} catch (ClassNotFoundException e) {
throw new ConstructionException("Class " + (cls != null ? cls.getName() : " null") + "not found", e);
} catch (IllegalAccessException e) {
View
24 fluentlenium-core/src/test/html/anotherpage.html
@@ -0,0 +1,24 @@
+<!--
+
+ Licensed 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
+
+-->
+
+<html>
+<head>
+ <title>Another Page</title>
+</head>
+<body style="" name="body">
+
+</body>
+</html>
View
51 fluentlenium-core/src/test/java/org/fluentlenium/integration/SuperclassPageTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed 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.fluentlenium.integration;
+
+import org.fluentlenium.core.FluentPage;
+import org.fluentlenium.core.annotation.Page;
+import org.fluentlenium.core.domain.FluentWebElement;
+import org.fluentlenium.integration.localtest.LocalFluentCase;
+import org.junit.ComparisonFailure;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class SuperclassPageTest extends PageTest {
+
+ @Page AnotherPage anotherPage;
+
+ @Test
+ public void checkGoToPagesDeclaredInThisClassAndSuperclass() {
+ page.go();
+ assertThat(title()).contains("Selenium");
+ anotherPage.go();
+ assertThat(title()).contains("Another Page");
+ }
+}
+
+class AnotherPage extends FluentPage {
+
+ @Override
+ public String getUrl() {
+ return LocalFluentCase.DEFAULT_URL + "anotherpage.html";
+ }
+
+ @Override
+ public void isAt() {
+ assertThat($("title").first().getText()).isEqualTo("Another Page");
+ }
+
+}
View
24 src/test/html/anotherpage.html
@@ -0,0 +1,24 @@
+<!--
+
+ Licensed 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
+
+-->
+
+<html>
+<head>
+ <title>Another Page</title>
+</head>
+<body style="" name="body">
+
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.