Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit be69e51

Browse files
committed
Changed @wait to @Waituntil and replaced enumeration with class reference in order to be more extendable
1 parent 7fdfd2c commit be69e51

File tree

11 files changed

+120
-132
lines changed

11 files changed

+120
-132
lines changed

documentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- [@Must](chapters/annotation-must.md)
1818
- [@Named](chapters/annotation-named.md)
1919
- [@PostConstruct](chapters/annotation-post-construct.md)
20-
- [@Wait](chapters/annotation-wait.md)
20+
- [@Wait](chapters/annotation-wait-until.md)
2121
- Utility Classes
2222
- [Conditions](chapters/conditions.md)
2323
- [ByProducers](chapters/by-producers.md)

documentation/chapters/annotation-must.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ public interface FooWidget extends PageFragment {
4848
}
4949
```
5050

51-
## Combination with @Wait
51+
## Combination with @WaitUntil
5252

53-
The `@Must` annotation can be used in combination with `@Wait`. This is especially useful in AJAX heavy applications where
54-
a fragment might be created with a short delay.
53+
The `@Must` annotation can be used in combination with `WaitUntil`. This is especially useful in AJAX heavy applications
54+
where a fragment might be created with a short delay.
5555

5656
**Example:**
57-
In this example the `widget` is checked as soon as `BarPage` is initialized. But `@Wait` will be triggered when invoking
57+
In this example the `widget` is checked as soon as `BarPage` is initialized. But `WaitUntil` will be triggered when invoking
5858
the method assuring that the widget is present before checking if it is visible.
5959
```java
6060
public interface BarPage extends Page {
6161

6262
@Must(Be.VISIBLE)
63-
@Wait(Until.PRESENT)
63+
WaitUntil(Present.class)
6464
@IdentifyUsing("#bar")
6565
BarWidget widget();
6666

@@ -74,4 +74,4 @@ public interface BarPage extends Page {
7474
- [Pages](page.md)
7575
- [Page Fragments](page-fragment.md)
7676
- [@PostConstruct](annotation-post-construct.md)
77-
- [@Wait](annotation-wait.md)
77+
- [@WaitUntil](annotation-wait-until.md)
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
[Home](../README.md)
22

3-
# @Wait
3+
# @WaitUntil
44
This annotation can be added to `@IdentifyUsing` annotated methods of `Page` or `PageFragment` subclasses.
55
When the annotated method is invoked a 'wait until' operation is executed using the annotations condition.
6+
The condition is provided via a class reference in order to support custom conditions. See [Conditions](conditions.md) for
7+
a set of provided page fragment related predicates.
68

7-
> Collection and Streams are currently NOT supported!
8-
9-
**The following conditions are available:**
9+
It is important to note that not all Predicate classes will work with this annotation.
10+
The mechanism with which the predicate is evaluated will initialize the given class via reflection
11+
and needs a default constructor to work!
1012

11-
- `VISIBLE`: The fragment is displayed on the current page.
12-
- `PRESENT`: The fragment is present in the current page's DOM.
13-
- `PRESENT_AND_VISIBLE`: The fragment is present in the current page's DOM and is displayed.
14-
- `ENABLED`: The fragment is enabled / not disabled.
15-
- `EDITABLE`: The fragment is enabled and not 'read-only'
16-
- `INTERACTABLE`: The fragment is visible and editable.
13+
> Collection and Streams are currently NOT supported!
1714
1815
**Example for page:**
1916
```java
2017
public interface FooPage extends Page {
2118

22-
@Wait(Until.VISIBLE)
19+
@WaitUntil(Visible.class)
2320
@IdentifyUsing("#foo")
2421
FooWidget widget();
2522

@@ -32,11 +29,11 @@ public interface FooPage extends Page {
3229
```java
3330
public interface FooWidget extends PageFragment {
3431

35-
@Wait(Until.VISIBLE)
32+
@WaitUntil(Visible.class)
3633
@IdentifyUsing("#one")
3734
TextField fieldOne();
3835

39-
@Wait(Until.VISIBLE)
36+
@WaitUntil(Visible.class)
4037
@IdentifyUsing("#two")
4138
TextField fieldTwo();
4239

@@ -49,3 +46,4 @@ public interface FooWidget extends PageFragment {
4946

5047
- [Pages](page.md)
5148
- [Page Fragments](page-fragment.md)
49+
- [Conditions](conditions.md)

documentation/chapters/page-fragment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ These annotations can be used within a `PageFragment`.
9696
- [@Must](annotation-must.md)
9797
- [@Named](annotation-named.md)
9898
- [@PostConstruct](annotation-post-construct.md)
99-
- [@Wait](annotation-wait.md)
99+
- [@WaitUntil](annotation-wait-until.md)
100100

101101
# Linked Documentation
102102

documentation/chapters/page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ These annotations can be used within a `Page`.
9898
- [@Must](annotation-must.md)
9999
- [@Named](annotation-named.md)
100100
- [@PostConstruct](annotation-post-construct.md)
101-
- [@Wait](annotation-wait.md)
101+
- [@WaitUntil](annotation-wait-until.md)
102102

103103
# Anatomy of a Page
104104
Pages generally provide four kinds of methods:

webtester-core/src/main/java/info/novatec/testit/webtester/internal/proxies/impls/IdentifyUsingImpl.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@
1111
import info.novatec.testit.webtester.browser.Browser;
1212
import info.novatec.testit.webtester.config.Configuration;
1313
import info.novatec.testit.webtester.internal.PageFragmentFactory;
14+
import info.novatec.testit.webtester.internal.exceptions.IllegalSignatureException;
1415
import info.novatec.testit.webtester.internal.proxies.PageFragmentModel;
1516
import info.novatec.testit.webtester.internal.proxies.PageFragmentModel.PageFragmentModelBuilder;
1617
import info.novatec.testit.webtester.pagefragments.PageFragment;
1718
import info.novatec.testit.webtester.pagefragments.annotations.Cached;
1819
import info.novatec.testit.webtester.pagefragments.annotations.IdentifyUsing;
1920
import info.novatec.testit.webtester.pagefragments.annotations.Named;
21+
import info.novatec.testit.webtester.pagefragments.annotations.WaitUntil;
2022
import info.novatec.testit.webtester.pagefragments.identification.ByProducers;
21-
import info.novatec.testit.webtester.pagefragments.annotations.Wait;
23+
import info.novatec.testit.webtester.waiting.Wait;
2224

2325

2426
@Slf4j
2527
public class IdentifyUsingImpl implements Implementation {
2628

29+
public static final String COULD_NOT_CREATE_PREDICATE_INSTANCE_MSG =
30+
"Could not create Predicate instance! Default constructor might be missing";
31+
2732
private static final String IDENTIFIED_BY_NAME = "%s identified by %s: %s";
2833

2934
private final Browser browser;
@@ -70,13 +75,26 @@ public PageFragment invoke(Object proxy, Method method, Object[] args) throws Th
7075
}
7176

7277
PageFragment pageFragment = factory.pageFragment(modelBuilder.build());
73-
if (method.isAnnotationPresent(Wait.class)) {
74-
method.getAnnotation(Wait.class).value().waitWith(pageFragment);
75-
}
78+
waitIfAnnotationPresent(method, pageFragment);
7679
return pageFragment;
7780

7881
}
7982

83+
private void waitIfAnnotationPresent(Method method, PageFragment fragment) {
84+
WaitUntil waitAnnotation = method.getAnnotation(WaitUntil.class);
85+
if (method.isAnnotationPresent(WaitUntil.class)) {
86+
doWaitUntil(waitAnnotation, fragment);
87+
}
88+
}
89+
90+
private void doWaitUntil(WaitUntil waitAnnotation, PageFragment fragment) {
91+
try {
92+
Wait.until(fragment).is(waitAnnotation.value().newInstance());
93+
} catch (InstantiationException | IllegalAccessException e) {
94+
throw new IllegalSignatureException(COULD_NOT_CREATE_PREDICATE_INSTANCE_MSG, e);
95+
}
96+
}
97+
8098
@SuppressWarnings("unchecked")
8199
private Class<? extends PageFragment> getReturnType(Method method) {
82100
return ( Class<? extends PageFragment> ) method.getReturnType();

webtester-core/src/main/java/info/novatec/testit/webtester/pagefragments/annotations/Until.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

webtester-core/src/main/java/info/novatec/testit/webtester/pagefragments/annotations/Wait.java

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package info.novatec.testit.webtester.pagefragments.annotations;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
import java.util.function.Predicate;
8+
9+
import info.novatec.testit.webtester.conditions.Conditions;
10+
import info.novatec.testit.webtester.conditions.pagefragments.Disabled;
11+
import info.novatec.testit.webtester.conditions.pagefragments.Editable;
12+
import info.novatec.testit.webtester.conditions.pagefragments.Enabled;
13+
import info.novatec.testit.webtester.conditions.pagefragments.Interactable;
14+
import info.novatec.testit.webtester.conditions.pagefragments.Invisible;
15+
import info.novatec.testit.webtester.conditions.pagefragments.Present;
16+
import info.novatec.testit.webtester.conditions.pagefragments.PresentAndVisible;
17+
import info.novatec.testit.webtester.conditions.pagefragments.ReadOnly;
18+
import info.novatec.testit.webtester.conditions.pagefragments.Selected;
19+
import info.novatec.testit.webtester.conditions.pagefragments.Visible;
20+
import info.novatec.testit.webtester.pagefragments.PageFragment;
21+
import info.novatec.testit.webtester.pages.Page;
22+
23+
24+
/**
25+
* Identification methods of {@link Page pages} and {@link PageFragment page fragments} can be annotation with this
26+
* annotation. With it the framework will wait until the specified {@link #value() predicate} returns true or the timeout is
27+
* reached.
28+
* <p>
29+
* <b>Important:</b> The used predicate class must provide a default constructor! Hence not all of our provided {@link
30+
* Conditions} will work. The following conditions can be used:
31+
* <ul>
32+
* <li>{@link Disabled}</li>
33+
* <li>{@link Editable}</li>
34+
* <li>{@link Enabled}</li>
35+
* <li>{@link Interactable}</li>
36+
* <li>{@link Invisible}</li>
37+
* <li>{@link Present}</li>
38+
* <li>{@link PresentAndVisible}</li>
39+
* <li>{@link ReadOnly}</li>
40+
* <li>{@link Selected}</li>
41+
* <li>{@link Visible}</li>
42+
* </ul>
43+
* <p>
44+
* <b>Example:</b>
45+
* <pre>
46+
* &#64;WaitUntil(Visible.class)
47+
* &#64;IdentifyUsing("#username")
48+
* TextField username();
49+
* </pre>
50+
*
51+
* @see WaitUntil
52+
* @since 2.0
53+
*/
54+
@Target(ElementType.METHOD)
55+
@Retention(RetentionPolicy.RUNTIME)
56+
public @interface WaitUntil {
57+
58+
/**
59+
* The until predicate to use for the wait operation.
60+
*
61+
* @return the until predicate to use
62+
* @since 2.0
63+
*/
64+
Class<? extends Predicate<PageFragment>> value();
65+
66+
// TODO: timeout
67+
68+
}

webtester-core/src/test/java/features/MustWithWaitFeatureTest.java renamed to webtester-core/src/test/java/features/MustWithWaitUntilFeatureTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
import integration.BaseIntegrationTest;
77

8+
import info.novatec.testit.webtester.conditions.pagefragments.PresentAndVisible;
89
import info.novatec.testit.webtester.internal.must.MustConditionException;
910
import info.novatec.testit.webtester.pagefragments.Button;
1011
import info.novatec.testit.webtester.pagefragments.annotations.Be;
1112
import info.novatec.testit.webtester.pagefragments.annotations.IdentifyUsing;
1213
import info.novatec.testit.webtester.pagefragments.annotations.Must;
13-
import info.novatec.testit.webtester.pagefragments.annotations.Until;
14-
import info.novatec.testit.webtester.pagefragments.annotations.Wait;
14+
import info.novatec.testit.webtester.pagefragments.annotations.WaitUntil;
1515
import info.novatec.testit.webtester.pages.Page;
1616

1717

18-
public class MustWithWaitFeatureTest extends BaseIntegrationTest {
18+
public class MustWithWaitUntilFeatureTest extends BaseIntegrationTest {
1919

2020
@Before
2121
public void openPage() {
@@ -42,7 +42,7 @@ public void demonstrateFailingMustBeBehaviour() {
4242
public interface PassingFeaturePage extends Page {
4343

4444
@Must(Be.VISIBLE)
45-
@Wait(Until.PRESENT_AND_VISIBLE)
45+
@WaitUntil(PresentAndVisible.class)
4646
@IdentifyUsing("#button")
4747
Button button();
4848

0 commit comments

Comments
 (0)