Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Browser#openAndWait for convenience(Fixes #28) #30

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/java/com/redhat/darcy/web/api/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import com.redhat.darcy.ui.api.View;
import com.redhat.darcy.ui.api.elements.Findable;
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.
*/
Expand Down Expand Up @@ -67,6 +71,34 @@ default <T extends View> Event<T> open(ViewUrl<T> viewUrl) {
*/
<T extends View> Event<T> open(String url, T destination);

/**
* 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 extends View> T openAndWaitUpTo(ViewUrl<T> viewUrl, Duration duration) {
return open(viewUrl).waitUpTo(duration);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add an override that accepts a Long and a ChronoUnit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/**
* 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 extends View> T openAndWaitUpTo(ViewUrl<T> viewUrl, Long amount, ChronoUnit unit) {
return open(viewUrl).waitUpTo(Duration.of(amount, unit));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this override -- I don't like the hard coded 2 minute wait time here. We can address default times in Synq -- darcy-framework/synq#17


/**
* @return the current URL string this Browser window is pointing to.
*/
Expand Down