Selenide: Switching to a window with a configurable timeout

Created on 15 Sep 2016  路  8Comments  路  Source: selenide/selenide

In com.codeborne.selenide.SelenideTargetLocator.window(int):

  public WebDriver window(int index) {
    try {
      return Wait().until(windowToBeAvailableAndSwitchToIt(index));
    }
    catch (TimeoutException e) {
      throw wrapThrowable(e, timeout);
    }
  }

The Wait() used relied on the timeout configuration. Is it possible for us to have a configurable timeout similar to SelenideElement.waitUntil(Condition condition, long timeoutMilliseconds)?

I have some pop-up windows that may open after a period that is longer than the configured timeout. It would not be good to increase the timeout value just to cover these cases.

feature help wanted

All 8 comments

@kenston Generally, it's not a bad idea to increase the timeout. It doesn't affect tests execution time (unless you have a lot-lot-lot of failing tests).

But yes, we could create additional methods like

  • switchTo().window(2, 8000); or
  • in(8000, ms).switchTo().window(2); or
  • in("8s").switchTo().window(2); or
  • switchTo(withTimeout(8000)).window(2);

What you suggest?

@asolntsev Agree on the idea of increasing timeout. It should not be a problem during actual execution of test suites, but I'm afraid it will slowdown development/debugging with unnecessary waits on something that will fail.

switchTo(withTimeout(8000)).window(2); is simple and sufficient. in(8000, ms).switchTo().window(2); or in("8s").switchTo().window(2); look interesting if it's going to configure any default Wait() (covering even Selenide.dismiss(...) and other future cases). Will in(8000, ms) return Selenide?

@kenston I don't know yet what it should return. That's the question. I am afraid this feature will require a bigger refactoring. But no doubt, we still need to do it.

@asolntsev @kenston thoughts on:

switchTo().window(index, timeout); 
switchTo().window(nameOrHandleOrTitle, timeout);

We can overload the SelenideTargetLocator window methods for index/title/handle etc ? I am against the concept of:

in(8000, ms).switchTo()... I think it implies a static wait here, which I don't think fits selenide style. we should increase the timeout we will look for the window temporarily without tampering with the Configuration timeout I think or sleeping the thread for a static amount of time etc.

@symonk Agree. Just one more suggestion: let set timeout type to java.time.Duration, not long.
Then users can use it like this:

switchTo().window(2, Duration.ofSeconds(15)); 
switchTo().window("some title", Duration.ofMilliseconds(8888));

I will take this one, starting soon

@symonk Any news on this?

@kenston @symonk @jlentink Done in Selenide 5.7.0, see https://github.com/selenide/selenide/pull/1054

Was this page helpful?
0 / 5 - 0 ratings