/*
(non-Javadoc)

@see org.finra.jtaf.ewd.ExtWebDriver#selectWindow(java.lang.String) TODO:
use {@link org.finra.jtaf.ewd.timer.WaitForConditionTimer}
490753
@Override
	public void selectWindow(String windowId) {
		long endTime = System.currentTimeMillis() + maxRequestTimeout;

		Set<String> currentWindowHandles = wd.getWindowHandles();
		boolean found = false;
		while (!found && System.currentTimeMillis() < endTime) {
			if (currentWindowHandles.contains(windowId)) {
				found = true;
			} else {
				currentWindowHandles = wd.getWindowHandles();
			}
		}

		if (found)
			wd.switchTo().window(windowId);
		else
			throw new TimeOutException("Could not select " + windowId
					+ " within " + maxRequestTimeout + " milliseconds");
	}
2174
public Timer newTimer(String opType, int sampleCount)
    {
        final Timer timer = new Timer(sampleCount);

        if (!timers.containsKey(opType))
            timers.put(opType, new ArrayList<Timer>());

        timers.get(opType).add(timer);
        return timer;
    }
307937
@Override
    public TriggerResult onElement(Object element, long timestamp, TimeWindow window, TriggerContext ctx) {
        ctx.registerEventTimeTimer(window.getEnd() + ctx.getMaxLagMs(), window);
        return TriggerResult.CONTINUE;
    }
604048
public void select(String optionLocator) {
        getDispatcher().beforeSelect(this, optionLocator);
        
        if (StringUtils.isBlank(optionLocator)) {
            throw new IllegalArgumentException("Locator cannot be null or empty.");
        }
        if (optionLocator.split("=").length != 2) {
            StringBuilder errMsg = new StringBuilder("Invalid locator specified :");
            errMsg.append(optionLocator);
            errMsg.append(". Locator should be of the form label=<value> (or) ");
            errMsg.append("value=<value> (or) ");
            errMsg.append("index=<value> (or) ");
            errMsg.append("id=<value>.");
            throw new IllegalArgumentException(errMsg.toString());
        }
        String locatorToUse = optionLocator.split("=")[1].trim();
        String tLocator = optionLocator.toLowerCase().split("=")[0].trim();
        if (tLocator.indexOf("label") >= 0) {
            // label was given
            new Select(getElement()).selectByVisibleText(locatorToUse);
        } else if (tLocator.indexOf("value") >= 0) {
            // value was given
            new Select(getElement()).selectByValue(locatorToUse);
        } else if (tLocator.indexOf("index") >= 0) {
            // index was given
            new Select(getElement()).selectByIndex(Integer.parseInt(locatorToUse));
        } else if (tLocator.indexOf("id") >= 0) {
            // id was given
            getElement().findElementById(locatorToUse).click();
        } else {
            throw new NoSuchElementException("Unable to find " + optionLocator);
        }
        
        getDispatcher().afterSelect(this, optionLocator);
    }
419706
@Override
    public void onWindowAdded(Window window) {
        if (windowListeners != null) {
            try {
                windowListeners.onWindowAdded(window);
            } catch (Exception e) {
                logger.error("", e);
            }
        }
    }
869521
public void select(TimelineEvent event, TimelineUpdater timelineUpdater) {
        int index = getIndex(event);

        if (timelineUpdater != null) {
            // update UI
            timelineUpdater.select(index);
        }
    }
1140750
public int waitForWindowActivated(String windowName) {
    if (getScopeServices().getConnection() == null) {
      throw new CommunicationException(
          "waiting for a window failed because Opera is not connected.");
    }

    return getScopeServices().waitForDesktopWindowActivated(windowName,
                                                            OperaIntervals.WINDOW_EVENT_TIMEOUT
                                                                .getMs());

  }
994495
private void fromWindow(PatternDescrBuilder<?> pattern) throws RecognitionException {
        String window = "";

        match(input,
                DRL6Lexer.ID,
                DroolsSoftKeywords.WINDOW,
                null,
                DroolsEditorType.KEYWORD);
        if (state.failed)
            return;

        Token id = match(input,
                DRL6Lexer.ID,
                null,
                null,
                DroolsEditorType.IDENTIFIER);
        if (state.failed)
            return;
        window = id.getText();

        if (state.backtracking == 0) {
            pattern.from().window(window);
            if (input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
            }
        }
    }
965028
@Override
  public <T> Cursor<T> selectCursor(String statement) {
    return session.selectCursor(statement);
  }
1169842
public void switchToNewWindow() {
        String action = "Switching to the new window";
        String expected = "New window is available and selected";
        try {
            parentWindow = driver.getWindowHandle();
            for (String winHandle : driver.getWindowHandles()) {
                driver.switchTo().window(winHandle);
            }
        } catch (Exception e) {
            reporter.fail(action, expected, "New window was unable to be selected. " + e.getMessage());
            log.warn(e);
            return;
        }
        reporter.pass(action, expected, expected);
    }
770815
public int waitForWindowUpdated(String windowName) {
    if (getScopeServices().getConnection() == null) {
      throw new CommunicationException(
          "waiting for a window failed because Opera is not connected.");
    }

    return getScopeServices().waitForDesktopWindowUpdated(windowName,
                                                          OperaIntervals.WINDOW_EVENT_TIMEOUT
                                                              .getMs());
  }
853985
public View waitForView(View view, int timeout){
		return waitForView(view, timeout, true, true);
	}
876716
public void waitForElementPresent(final By by, final int maximumSeconds) {
		WebDriverWait wait = new WebDriverWait(driver, maximumSeconds);
		wait.until(ExpectedConditions.presenceOfElementLocated((by)));
	}
542159
function (selector, value) {
    return this.waitForDOM(selector).execute(function (selector, value) {
      var element = document.querySelector(selector);
      if (element) {
        element.value = value;
      }
    }, [ selector, value ]);
  }
180752
function() {
        if (this.timerId != null) {
            window.clearTimeout(this.timerId);
            this.timerId = null;
        }
        if (this.rightclickTimerId != null) {
            window.clearTimeout(this.rightclickTimerId);
            this.rightclickTimerId = null;
        }
    }
892622
private void setTimeoutOnSelenium() {
		executeCommand("setTimeout", new String[] { "" + this.timeout });
        WebDriver.Timeouts timeouts = getWebDriver().manage().timeouts();
        timeouts.setScriptTimeout(this.timeout, TimeUnit.MILLISECONDS);
        timeouts.pageLoadTimeout(this.timeout, TimeUnit.MILLISECONDS);
	}
940852
@Override
    public Boolean executeCommand(int timeout, String componentName, Object... data) throws QTasteException {
        setData(data);
        long maxTime = System.currentTimeMillis() + 1000 * timeout;
        String buttonText = mData[0].toString();
        component = null;

        while (System.currentTimeMillis() < maxTime) {
            DialogPane targetPopup = null;
            List<Stage> popups = findPopups();
            Collections.reverse(popups);
            for (Stage popup : popups) {
                DialogPane dialogPane = getDialogPane(popup);
                if (!dialogPane.isVisible() || dialogPane.isDisabled()) {
                    String msg = "Ignore the dialog '" + popup.getTitle() + "' cause:\n ";
                    if (!dialogPane.isVisible()) {
                        msg += "\t is not visible";
                    }
                    if (dialogPane.isDisabled()) {
                        msg += "\t is disabled";
                    }
                    LOGGER.info(msg);
                    continue;
                }
                if (activateAndFocusWindow(popup)) {
                    targetPopup = dialogPane;
                    break;
                } else {
                    LOGGER.info("Ignore the dialog '" + popup.getTitle() + "' cause:\n  \t is not focused");
                }
            }

            component = findButton(targetPopup, buttonText);

            if ( component != null && !component.isDisabled() && checkComponentIsVisible(component) )
                break;

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                LOGGER.warn("Exception during the component search sleep...");
            }
        }

        if (component == null) {
            throw new QTasteTestFailException("The button with the text \"" + buttonText + "\" is not found.");
        }
        if (component.isDisabled()) {
            throw new QTasteTestFailException("The button with the text \"" + buttonText + "\" is disabled.");
        }
        if (!checkComponentIsVisible(component)) {
            throw new QTasteTestFailException("The button with the text \"" + buttonText + "\" is not visible!");
        }

        prepareActions();
        Platform.runLater(this);
        return true;
    }