code: private double popup(double seconds) {
          // wait for up to XX seconds for the error message
          double end = System.currentTimeMillis() + (seconds * 1000);
          WebDriverWait wait = new WebDriverWait(app.getDriver(), (long) seconds, DEFAULT_POLLING_INTERVAL);
          wait.until(ExpectedConditions.alertIsPresent());
          return Math.min((seconds * 1000) - (end - System.currentTimeMillis()), seconds * 1000) / 1000;
      }
docs: Wait for a popup to be present, and
  then returns the amount of time that was waited
  
  @param seconds - maximum time to wait in seconds
  @return double - the total time waited