/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2018 wcm.io
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package io.wcm.qa.galenium.interaction;

import static io.wcm.qa.galenium.reporting.GaleniumReportUtil.getLogger;
import static io.wcm.qa.galenium.util.GaleniumContext.getDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public final class Wait {

  private Wait() {
    // do not instantiate
  }

  /**
   * Load URL and wait passed number of seconds for it to be loaded.
   * @param url to load
   * @param timeOutInSeconds how long to wait for URL to be current
   */
  public static void forUrl(String url, int timeOutInSeconds) {
    getLogger().trace("waiting for URL: '" + url + "'");
    WebDriverWait wait = new WebDriverWait(getDriver(), timeOutInSeconds);
    wait.until(ExpectedConditions.urlToBe(url));
    getLogger().trace("found URL: '" + url + "'");
  }

  /**
   * Load URL and wait for it to be loaded.
   * @param url to load
   */
  public static void forUrl(String url) {
    Wait.forUrl(url, 5);
  }


}

@@ -739,74 +739,56 @@
 er;%0A
+%0A
 import 
-static io.wcm.qa.ga
+org.openqa.se
 lenium.
-util.GaleniumContext.getDrive
+JavascriptExecuto
 r;%0A
-%0A
 impo
@@ -899,79 +899,924 @@
 t;%0A%0A
-public final class Wait %7B%0A%0A  private Wait() %7B%0A    // do not instantiate
+import io.wcm.qa.galenium.util.GaleniumContext;%0A%0Apublic final class Wait %7B%0A%0A  private static final int DEFAULT_POLLING_INTERVAL = 100;%0A  private static final int DEFAULT_TIMEOUT = 1;%0A%0A  private Wait() %7B%0A    // do not instantiate%0A  %7D%0A%0A  /**%0A   * Wait for domReady for a maximum of one second.%0A   */%0A  public static void forDomReady() %7B%0A    forDomReady(DEFAULT_TIMEOUT);%0A  %7D%0A%0A  /**%0A   * Wait for %22DOM ready%22 for a maximum of seconds specified by parameter.%0A   * @param timeOutInSeconds how long to wait for %22DOM ready%22%0A   */%0A  public static void forDomReady(int timeOutInSeconds) %7B%0A    WebDriverWait wait = getWait(timeOutInSeconds);%0A    wait.until(driver -%3E ((JavascriptExecutor)driver).executeScript(%22return document.readyState%22).equals(%22complete%22));%0A  %7D%0A%0A  /**%0A   * Load URL and wait for it to be loaded.%0A   * @param url to load%0A   */%0A  public static void forUrl(String url) %7B%0A    Wait.forUrl(url, DEFAULT_TIMEOUT);
 %0A  %7D
@@ -2140,39 +2140,16 @@
 t = 
-new WebDriverWait(getDriver(), 
+getWait(
 time
@@ -2274,157 +2274,320 @@
 %0A%0A  
-/**%0A   * Load URL and wait for it to be loaded.%0A   * @param url to load%0A   */%0A  public static void forUrl(String url) %7B%0A    Wait.forUrl(url, 5
+private static WebDriverWait getWait(int timeOutInSeconds) %7B%0A    return getWait(timeOutInSeconds, DEFAULT_POLLING_INTERVAL);%0A  %7D%0A%0A  private static WebDriverWait getWait(int timeOutInSeconds, int pollingInterval) %7B%0A    return new WebDriverWait(GaleniumContext.getDriver(), timeOutInSeconds, pollingInterval
 );%0A  %7D%0A%0A
 %0A%7D%0A
@@ -2583,11 +2583,10 @@
 );%0A  %7D%0A%0A
-%0A
 %7D%0A

add DOM ready convenience methods to Wait