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 default timeout values for explicit waits #94

Open
erratic-pattern opened this issue Apr 28, 2016 · 0 comments
Open

Add default timeout values for explicit waits #94

erratic-pattern opened this issue Apr 28, 2016 · 0 comments

Comments

@erratic-pattern
Copy link
Member

erratic-pattern commented Apr 28, 2016

A feature request based on conversation with @adinapoli in issue #92

Currently all wait* functions use explicit timeout parameters. Instead, include the ability to set a default timeout value as a state variable.

Variation 1: add state field directly to WDConfig and WDSession

conf = defaultConfig 
  { explicitWaitTimeout = Just 5  -- new config field. Nothing indicates indefinite waiting
  }

main = runSession conf $ do
  useWaitTimeout 10 -- can also set value via command instead of the config field 
  waitUntil foo
  useIndefiniteWait -- remove timeout. indefinite waiting
  waitUntil bar

  waitWithTimeoutUntil 10 baz -- explicit timeout value provided. function name too wordy?

Nice and simple with no additional types to work with. Easy to use in situations where test cases are heavily decoupled. However, since the timeout state is "global" to the session it can easily leak into unrelated test cases. Feels like I'm working with an imperative language instead of Haskell, but then again this library is already heavily imperative in design due to the nature of the WebDriver framework.

Variation 2: use a new state monad WDWait on top of WD that keeps track of timeout

In this variation, the wait* combinators result in a WDWait a instead of the current WD a. This new WDWait type is just a state monad on top of the existing WD monad with a simple timeout value.

main = runSession defaultConfig $ do
  withTimeout 10 $ do 
    waitUntil foo
    waitUntil bar
  withNoTimeout $ do -- no timeout. indefinite waiting
    waitUntil baz

This results in an block-structured code flow, but might be clunky when test cases are heavily split up or when many different timeouts are desired. Feels more like I'm working with Haskell.

EDIT: On further consideration I don't necessarily think isolated test cases would be clunky. In fact it has a natural-language-esque presentation:

withTimeout 10 . waitUntil $ ...

or

withNoTimeout . waitUntil $ ...

Questions and Considerations

  • Should we gut the existing functions that use mandatory timeout arguments, rename them to something else, or keep them as-is and use new names for the new functions? In any of these case, what names should we use?
  • What is the default for the default? 0? Some arbitrary number of seconds like 5 or 10? Wait indefinitely?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant