From 447d812001fdaeac89907b4e616f1e5baa877ac1 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Mon, 23 Feb 2015 11:50:12 -0500 Subject: [PATCH 1/4] Add Browser#openAndWait for convience --- .../com/redhat/darcy/web/api/Browser.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/redhat/darcy/web/api/Browser.java b/src/main/java/com/redhat/darcy/web/api/Browser.java index 5aebf0c..4edb359 100644 --- a/src/main/java/com/redhat/darcy/web/api/Browser.java +++ b/src/main/java/com/redhat/darcy/web/api/Browser.java @@ -22,6 +22,9 @@ import com.redhat.darcy.ui.api.View; import com.redhat.darcy.ui.api.elements.Findable; import com.redhat.synq.Event; + +import java.time.Duration; + /** * Abstracts all of the interactions a user might make with a browser. */ @@ -48,6 +51,23 @@ default Event open(ViewUrl viewUrl) { return open(viewUrl.url(), viewUrl.destination()); } + /** + * Constructs an {@link com.redhat.synq.Event} that will opens the URL and block until the + * associated {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} + * parameter, and then calls {@link Event#waitUpTo(java.time.Duration)} to open the url and + * block the thread until the view is loaded. Will block the thread for a maximum of the + * specified duration, at which point a {@link com.redhat.synq.TimeoutException} will be + * thrown. + * @param viewUrl If you don't have a {@link com.redhat.darcy.web.api.ViewUrl} instance, but you + * know the url and the resulting {@link com.redhat.darcy.ui.api.View}, see + * {@link #open(String, com.redhat.darcy.ui.api.View)}. + * @param duration Maximum specified duration of the view loading + * @return The awaited view once it has met all criteria for loading + */ + default T openAndWait(ViewUrl viewUrl, Duration duration) { + return open(viewUrl).waitUpTo(duration); + } + /** * Constructs an event that will opens the URL and block until the associated * {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} parameter. From c6b65818dc07431be76fa26a8c297bd84d4d951a Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Mon, 23 Feb 2015 11:57:16 -0500 Subject: [PATCH 2/4] Add default Browser#openAndWait that only accepts a ViewUrl and uses our currently two minute duration --- .../com/redhat/darcy/web/api/Browser.java | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/redhat/darcy/web/api/Browser.java b/src/main/java/com/redhat/darcy/web/api/Browser.java index 4edb359..a646716 100644 --- a/src/main/java/com/redhat/darcy/web/api/Browser.java +++ b/src/main/java/com/redhat/darcy/web/api/Browser.java @@ -24,6 +24,7 @@ import com.redhat.synq.Event; import java.time.Duration; +import java.time.temporal.ChronoUnit; /** * Abstracts all of the interactions a user might make with a browser. @@ -51,6 +52,25 @@ default Event open(ViewUrl viewUrl) { return open(viewUrl.url(), viewUrl.destination()); } + /** + * Constructs an event that will opens the URL and block until the associated + * {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} parameter. + * Note that merely calling this function does not actually open the URL and wait. You + * have to call {@link Event#waitUpTo(java.time.Duration)}, the core terminal operation in + * the Event DSL. + *

+ * Because an {@link com.redhat.synq.Event} is returned, the event that you ultimately wait for + * can be further configured if desired, adding {@link Event#failIf(com.redhat.synq.Event)} + * clauses, and the like. + * + * @param destination The {@link com.redhat.darcy.ui.api.View} you expect to be loaded after + * navigating to the specified url. The returned {@link com.redhat.synq.Event} will be + * configured to wait for a {@link com.redhat.darcy.ui.api.TransitionEvent} to occur for this + * view. + * @return An {@link com.redhat.synq.Event} that can be further configured and awaited. + */ + Event open(String url, T destination); + /** * Constructs an {@link com.redhat.synq.Event} that will opens the URL and block until the * associated {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} @@ -69,23 +89,20 @@ default T openAndWait(ViewUrl viewUrl, Duration duration) { } /** - * Constructs an event that will opens the URL and block until the associated - * {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} parameter. - * Note that merely calling this function does not actually open the URL and wait. You - * have to call {@link Event#waitUpTo(java.time.Duration)}, the core terminal operation in - * the Event DSL. - *

- * Because an {@link com.redhat.synq.Event} is returned, the event that you ultimately wait for - * can be further configured if desired, adding {@link Event#failIf(com.redhat.synq.Event)} - * clauses, and the like. - * - * @param destination The {@link com.redhat.darcy.ui.api.View} you expect to be loaded after - * navigating to the specified url. The returned {@link com.redhat.synq.Event} will be - * configured to wait for a {@link com.redhat.darcy.ui.api.TransitionEvent} to occur for this - * view. - * @return An {@link com.redhat.synq.Event} that can be further configured and awaited. + * Constructs an {@link com.redhat.synq.Event} that will opens the URL and block until the + * associated {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} + * parameter, and then calls {@link Event#waitUpTo(java.time.Duration)} with a default value to + * open the url and block the thread until the view is loaded. Will block the thread for a + * maximum of the two minutes, at which point a {@link com.redhat.synq.TimeoutException} will be + * thrown. + * @param viewUrl If you don't have a {@link com.redhat.darcy.web.api.ViewUrl} instance, but you + * know the url and the resulting {@link com.redhat.darcy.ui.api.View}, see + * {@link #open(String, com.redhat.darcy.ui.api.View)}. + * @return The awaited view once it has met all criteria for loading */ - Event open(String url, T destination); + default T openAndWait(ViewUrl viewUrl) { + return open(viewUrl).waitUpTo(Duration.of(2, ChronoUnit.MINUTES)); + } /** * @return the current URL string this Browser window is pointing to. From 38d96a5c5c561a96b0a8b62e664b4ab27ff24f71 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Tue, 24 Feb 2015 09:53:32 -0500 Subject: [PATCH 3/4] Modify javadoc --- src/main/java/com/redhat/darcy/web/api/Browser.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/redhat/darcy/web/api/Browser.java b/src/main/java/com/redhat/darcy/web/api/Browser.java index a646716..2c17c5e 100644 --- a/src/main/java/com/redhat/darcy/web/api/Browser.java +++ b/src/main/java/com/redhat/darcy/web/api/Browser.java @@ -74,10 +74,9 @@ default Event open(ViewUrl viewUrl) { /** * Constructs an {@link com.redhat.synq.Event} that will opens the URL and block until the * associated {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} - * parameter, and then calls {@link Event#waitUpTo(java.time.Duration)} to open the url and - * block the thread until the view is loaded. Will block the thread for a maximum of the - * specified duration, at which point a {@link com.redhat.synq.TimeoutException} will be - * thrown. + * parameter, and then calls {@link Event#waitUpTo(java.time.Duration)} to open the url. Will + * block the thread for a maximum of the specified duration, at which point a + * {@link com.redhat.synq.TimeoutException} will be thrown. * @param viewUrl If you don't have a {@link com.redhat.darcy.web.api.ViewUrl} instance, but you * know the url and the resulting {@link com.redhat.darcy.ui.api.View}, see * {@link #open(String, com.redhat.darcy.ui.api.View)}. @@ -92,9 +91,8 @@ default T openAndWait(ViewUrl viewUrl, Duration duration) { * Constructs an {@link com.redhat.synq.Event} that will opens the URL and block until the * associated {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} * parameter, and then calls {@link Event#waitUpTo(java.time.Duration)} with a default value to - * open the url and block the thread until the view is loaded. Will block the thread for a - * maximum of the two minutes, at which point a {@link com.redhat.synq.TimeoutException} will be - * thrown. + * open the url. Will block the thread for a maximum of the two minutes, at which point a + * {@link com.redhat.synq.TimeoutException} will be thrown. * @param viewUrl If you don't have a {@link com.redhat.darcy.web.api.ViewUrl} instance, but you * know the url and the resulting {@link com.redhat.darcy.ui.api.View}, see * {@link #open(String, com.redhat.darcy.ui.api.View)}. From 27769a03da08e539894a60421c424dd619cc6d23 Mon Sep 17 00:00:00 2001 From: Andrew Bocz Date: Fri, 17 Apr 2015 11:14:23 -0400 Subject: [PATCH 4/4] Remove baked in wait and add default for long and chronounit --- .../com/redhat/darcy/web/api/Browser.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/redhat/darcy/web/api/Browser.java b/src/main/java/com/redhat/darcy/web/api/Browser.java index 2c17c5e..1075501 100644 --- a/src/main/java/com/redhat/darcy/web/api/Browser.java +++ b/src/main/java/com/redhat/darcy/web/api/Browser.java @@ -72,34 +72,31 @@ default Event open(ViewUrl viewUrl) { Event open(String url, T destination); /** - * Constructs an {@link com.redhat.synq.Event} that will opens the URL and block until the - * associated {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} - * parameter, and then calls {@link Event#waitUpTo(java.time.Duration)} to open the url. Will - * block the thread for a maximum of the specified duration, at which point a - * {@link com.redhat.synq.TimeoutException} will be thrown. + * Opens the URL and immediately blocks the thread for a maximum of the specified + * duration, after which a {@link com.redhat.synq.TimeoutException} will be thrown. * @param viewUrl If you don't have a {@link com.redhat.darcy.web.api.ViewUrl} instance, but you * know the url and the resulting {@link com.redhat.darcy.ui.api.View}, see * {@link #open(String, com.redhat.darcy.ui.api.View)}. * @param duration Maximum specified duration of the view loading * @return The awaited view once it has met all criteria for loading */ - default T openAndWait(ViewUrl viewUrl, Duration duration) { + default T openAndWaitUpTo(ViewUrl viewUrl, Duration duration) { return open(viewUrl).waitUpTo(duration); } /** - * Constructs an {@link com.redhat.synq.Event} that will opens the URL and block until the - * associated {@link com.redhat.darcy.ui.api.View} is loaded, as defined by the {@link ViewUrl} - * parameter, and then calls {@link Event#waitUpTo(java.time.Duration)} with a default value to - * open the url. Will block the thread for a maximum of the two minutes, at which point a - * {@link com.redhat.synq.TimeoutException} will be thrown. + * Opens the URL and immediately blocks the thread for a maximum of the duration of the + * specified amount of units, after which a {@link com.redhat.synq.TimeoutException} will be + * thrown. * @param viewUrl If you don't have a {@link com.redhat.darcy.web.api.ViewUrl} instance, but you * know the url and the resulting {@link com.redhat.darcy.ui.api.View}, see * {@link #open(String, com.redhat.darcy.ui.api.View)}. + * @param amount The amount of the duration, expressed in units + * @param unit The unit the duration is measured in * @return The awaited view once it has met all criteria for loading */ - default T openAndWait(ViewUrl viewUrl) { - return open(viewUrl).waitUpTo(Duration.of(2, ChronoUnit.MINUTES)); + default T openAndWaitUpTo(ViewUrl viewUrl, Long amount, ChronoUnit unit) { + return open(viewUrl).waitUpTo(Duration.of(amount, unit)); } /**