OpenViduClientBrowserTest.java 22.7 KB
Newer Older
1
/*
2
 * (C) Copyright 2017-2019 OpenVidu (https://openvidu.io/)
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 * 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.
 */
16
package io.openvidu.test;
17

18 19
import static io.openvidu.test.config.RoomTestConfiguration.ROOM_APP_CLASSNAME_DEFAULT;
import static io.openvidu.test.config.RoomTestConfiguration.ROOM_APP_CLASSNAME_PROP;
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
import static org.junit.Assert.fail;
import static org.kurento.commons.PropertiesManager.getProperty;
import static org.kurento.test.config.TestConfiguration.SELENIUM_SCOPE_PROPERTY;
import static org.kurento.test.config.TestConfiguration.TEST_URL_TIMEOUT_DEFAULT;
import static org.kurento.test.config.TestConfiguration.TEST_URL_TIMEOUT_PROPERTY;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.kurento.commons.PropertiesManager;
import org.kurento.jsonrpc.JsonUtils;
import org.kurento.test.base.BrowserTest;
import org.kurento.test.browser.Browser;
import org.kurento.test.browser.BrowserType;
import org.kurento.test.browser.WebPage;
import org.kurento.test.browser.WebPageType;
import org.kurento.test.config.BrowserScope;
import org.kurento.test.config.TestScenario;
import org.kurento.test.services.KmsService;
import org.kurento.test.services.Service;
import org.kurento.test.services.TestService;
import org.kurento.test.services.WebServerService;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.ElementNotVisibleException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.Point;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.google.gson.JsonArray;

/**
 * Base for Kurento Room tests with browsers.
 *
 * @author Radu Tom Vlad (rvlad@naevatec.com)
 * @since 6.2.1
 */
public abstract class OpenViduClientBrowserTest<W extends WebPage> extends BrowserTest<W> {

  public interface UserLifecycle {
    public void run(int numUser, int iteration) throws Exception;
  }

  public interface Task {
    public void exec(int numTask) throws Exception;
  }

  static class KmsUriSetterService extends TestService {

    private KmsService kms;

    public KmsUriSetterService(KmsService kms) {
      this.kms = kms;
    }

    @Override
    public TestServiceScope getScope() {
      return kms.getScope();
    }

    @Override
    public void start() {
      super.start();
      String uri = kms.getWsUri();
      System.setProperty("kms.uris", "[\"" + uri + "\"]");
      System.setProperty("kms.uri", uri);
      log.debug("Set system properties 'kms.uri' to {} & 'kms.uris' to [{}] ", uri, uri);
    }

  }

  public static long TASKS_TIMEOUT_IN_MINUTES = 15 * 60;

  public static int POLLING_LATENCY = 100;
  public static int WEB_TEST_MAX_WIDTH = 1200;
  public static int WEB_TEST_LEFT_BAR_WIDTH = 60;
  public static int WEB_TEST_TOP_BAR_WIDTH = 30;
  public static int WEB_TEST_BROWSER_WIDTH = 500;
  public static int WEB_TEST_BROWSER_HEIGHT = 400;

  public static String ROOM_PREFIX = "room";
  public static String USER_BROWSER_PREFIX = "browser";
  public static String USER_FAKE_PREFIX = "user";

  public static @Service(1) KmsService kms = new KmsService();
  public static @Service(2) KmsUriSetterService kmsUriSetter = new KmsUriSetterService(kms);

  public static BrowserScope testScope = BrowserScope.LOCAL;
  public static Class<?> webServerClass;

  static {
    loadWebServerClass();
    if (webServerClass == null) {
      Assert.fail("Unable to load any of the provided classnames for the web server test service");
    }

    String scopeProp = PropertiesManager.getProperty(SELENIUM_SCOPE_PROPERTY);
    if (scopeProp != null) {
      testScope = BrowserScope.valueOf(scopeProp.toUpperCase());
    }
  }

  public static @Service(99) WebServerService webServer = new WebServerService(webServerClass);

  public static int testTimeout;

  public static SecureRandom random = new SecureRandom();

  public WebPageType webPageType = WebPageType.ROOM;

  public int PLAY_TIME = 5; // seconds

  public int ITERATIONS = 2;

  public Object browsersLock = new Object();

  public String roomName = ROOM_PREFIX;

  public Map<String, Exception> execExceptions = new HashMap<String, Exception>();

  public boolean failed = false;

  public OpenViduClientBrowserTest() {
    setDeleteLogsIfSuccess(false); // always keep the logs
  }

  @BeforeClass
  public static void beforeClass() {
    testTimeout = getProperty(TEST_URL_TIMEOUT_PROPERTY, TEST_URL_TIMEOUT_DEFAULT);
    log.debug("Test timeout: {}", testTimeout);
  }

  @Override
  public void setupBrowserTest() throws InterruptedException {
    super.setupBrowserTest();

    execExceptions.clear();

    if (testScenario != null && testScenario.getBrowserMap() != null
        && testScenario.getBrowserMap().size() > 0) {
      int row = 0;
      int col = 0;
      for (final String browserKey : testScenario.getBrowserMap().keySet()) {
        Browser browser = getPage(browserKey).getBrowser();
        browser.getWebDriver().manage().window()
            .setSize(new Dimension(WEB_TEST_BROWSER_WIDTH, WEB_TEST_BROWSER_HEIGHT));
        browser
            .getWebDriver()
            .manage()
            .window()
            .setPosition(
                new Point(col * WEB_TEST_BROWSER_WIDTH + WEB_TEST_LEFT_BAR_WIDTH, row
                    * WEB_TEST_BROWSER_HEIGHT + WEB_TEST_TOP_BAR_WIDTH));
        col++;
        if (col * WEB_TEST_BROWSER_WIDTH + WEB_TEST_LEFT_BAR_WIDTH > WEB_TEST_MAX_WIDTH) {
          col = 0;
          row++;
        }
      }
    }
  }

  @Override
  public void teardownBrowserTest() {
    super.teardownBrowserTest();
    failWithExceptions();
  }

  public static Collection<Object[]> localChromes(String caller, int browsers, WebPageType pageType) {
    TestScenario test = new TestScenario();
    for (int i = 0; i < browsers; i++) {
      Browser browser = new Browser.Builder().webPageType(pageType).browserType(BrowserType.CHROME)
          .scope(BrowserScope.LOCAL).build();
      test.addBrowser(getBrowserKey(i), browser);
    }
    log.debug("{}: Web browsers: {}, webPageType: {}, test scope: {}, Browsers map keySet: {}",
        caller, browsers, pageType, testScope.toString(), test.getBrowserMap().keySet());
    return Arrays.asList(new Object[][] { { test } });
  }

  public static void loadWebServerClass() {
    try {
      List<String> auxList = JsonUtils.toStringList(PropertiesManager.getPropertyJson(
          ROOM_APP_CLASSNAME_PROP, ROOM_APP_CLASSNAME_DEFAULT, JsonArray.class));

      for (String aux : auxList) {
        log.info("Loading class '{}' as the test's web server service", aux);
        try {
          webServerClass = Class.forName(aux);
          break;
        } catch (Exception e) {
          log.warn("Couldn't load web server class '{}': {}", aux, e.getMessage());
          log.debug("Couldn't load web server class '{}'", aux, e);
        }
      }
    } catch (Exception e) {
      log.error("Incorrect value for property '{}'", ROOM_APP_CLASSNAME_PROP, e);
    }
  }

  public static void sleep(long seconds) {
    try {
      Thread.sleep(seconds * 1000);
    } catch (InterruptedException e) {
      log.warn("Interrupted while sleeping {}seconds", seconds, e);
    }
  }

  public static String getBrowserKey(int index) {
    return USER_BROWSER_PREFIX + index;
  }

  public static String getBrowserStreamName(int index) {
    return getBrowserKey(index) + "_webcam";
  }

  public static String getBrowserVideoStreamName(int index) {
    return "video-" + getBrowserStreamName(index);
  }

  public static String getBrowserNativeStreamName(int index) {
    return "native-" + getBrowserVideoStreamName(index);
  }

  public static String getFakeKey(int index) {
    return USER_FAKE_PREFIX + index;
  }

  public static String getFakeStreamName(int index) {
    return getFakeKey(index) + "_webcam";
  }

  public static String getFakeStreamName(String userName) {
    return userName + "_webcam";
  }

  public static String getFakeVideoStreamName(int index) {
    return "video-" + getFakeStreamName(index);
  }

  public static String getFakeNativeStreamName(int index) {
    return "native-" + getFakeVideoStreamName(index);
  }

  public static CountDownLatch[] createCdl(int numLatches, int numUsers) {
    final CountDownLatch[] cdl = new CountDownLatch[numLatches];
    for (int i = 0; i < numLatches; i++) {
      cdl[i] = new CountDownLatch(numUsers);
    }
    return cdl;
  }

  public void iterParallelUsers(int numUsers, int iterations, final UserLifecycle user)
      throws InterruptedException, ExecutionException, TimeoutException {

    int totalExecutions = iterations * numUsers;
    ExecutorService threadPool = Executors.newFixedThreadPool(totalExecutions);
    ExecutorCompletionService<Void> exec = new ExecutorCompletionService<>(threadPool);
    List<Future<Void>> futures = new ArrayList<>();

    try {
      for (int j = 0; j < iterations; j++) {
        final int it = j;
        log.info("it#{}: Starting execution of {} users", it, numUsers);
        for (int i = 0; i < numUsers; i++) {
          final int numUser = i;
          final Browser browser = getPage(getBrowserKey(i)).getBrowser();
          futures.add(exec.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
              Thread.currentThread().setName("it" + it + "|browser" + numUser);
              if (it > 0) {
                log.debug("Page reloaded");
                browser.reload();
              }
              user.run(numUser, it);
              return null;
            }
          }));
        }

        for (int i = 0; i < numUsers; i++) {
          try {
            exec.take().get();
          } catch (ExecutionException e) {
            log.error("Execution exception", e);
            throw e;
          }
        }
        log.info("it#{}: Finished execution of {} users", it, numUsers);
      }
    } finally {
      threadPool.shutdownNow();
    }
  }

  public void parallelTasks(int numThreads, final String thPrefix, String taskName, final Task task) {
    ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);
    ExecutorCompletionService<Void> exec = new ExecutorCompletionService<>(threadPool);
    try {
      for (int i = 0; i < numThreads; i++) {
        final int numTask = i;
        exec.submit(new Callable<Void>() {
          @Override
          public Void call() throws Exception {
            String thname = Thread.currentThread().getName();
            Thread.currentThread().setName(thPrefix + numTask);
            task.exec(numTask);
            Thread.currentThread().setName(thname);
            return null;
          }
        });
      }
      for (int i = 0; i < numThreads; i++) {
        String thTask = taskName + "-" + thPrefix + i;
        try {
          log.debug("Waiting for the {} execution to complete ({}/{})", thTask, i + 1, numThreads);
          exec.take().get();
          log.debug("Job {} completed ({}/{})", thTask, i + 1, numThreads);
        } catch (ExecutionException e) {
          log.debug("Execution exception of {} ({}/{})", thTask, i + 1, numThreads, e);
          execExceptions.put(taskName + "-" + thPrefix + i, e);
        } catch (InterruptedException e) {
          log.error("Interrupted while waiting for execution of task{}", i, e);
        }
      }
    } finally {
      threadPool.shutdown();
      try {
        threadPool.awaitTermination(TASKS_TIMEOUT_IN_MINUTES, TimeUnit.MINUTES);
      } catch (InterruptedException e) {
        log.warn("Tasks were executed more than {} minutes. Stopping it", TASKS_TIMEOUT_IN_MINUTES);
        threadPool.shutdownNow();
      }

    }
  }

  public void joinToRoom(int pageIndex, String userName, String roomName) {
    Browser userBrowser = getPage(getBrowserKey(pageIndex)).getBrowser();
    WebElement nameInput = findElement(userName, userBrowser, "name");
    nameInput.clear();
    nameInput.sendKeys(userName);
    WebElement roomInput = findElement(userName, userBrowser, "roomName");
    roomInput.clear();
    roomInput.sendKeys(roomName);
    findElement(userName, userBrowser, "joinBtn").submit();
    log.debug("Clicked on 'joinBtn' in {}", userName);
  }

  public void exitFromRoom(int pageIndex, String userName) {
    Browser userBrowser = getPage(getBrowserKey(pageIndex)).getBrowser();
    try {
      Actions actions = new Actions(userBrowser.getWebDriver());
      actions.click(findElement(userName, userBrowser, "buttonLeaveRoom")).perform();
      log.debug("'buttonLeaveRoom' clicked on in {}", userName);
    } catch (ElementNotVisibleException e) {
      log.warn("Button 'buttonLeaveRoom' is not visible. Session can't be closed");
    }
  }

  public void unsubscribe(int pageIndex, int unsubscribeFromIndex) {
    String clickableVideoTagId = getBrowserVideoStreamName(unsubscribeFromIndex);
    selectVideoTag(pageIndex, clickableVideoTagId);

    WebDriver userWebDriver = getPage(getBrowserKey(pageIndex)).getBrowser().getWebDriver();
    try {
      userWebDriver.findElement(By.id("buttonDisconnect")).click();
    } catch (ElementNotVisibleException e) {
      String msg = "Button 'buttonDisconnect' is not visible. Can't unsubscribe from media.";
      log.warn(msg);
      fail(msg);
    }
  }

  public void selectVideoTag(int pageIndex, String targetVideoTagId) {
    WebDriver userWebDriver = getPage(getBrowserKey(pageIndex)).getBrowser().getWebDriver();
    try {
      WebElement element = userWebDriver.findElement(By.id(targetVideoTagId));
      Actions actions = new Actions(userWebDriver);
      actions.moveToElement(element).click().perform();
    } catch (ElementNotVisibleException e) {
      String msg = "Video tag '" + targetVideoTagId + "' is not visible, thus not selectable.";
      log.warn(msg);
      fail(msg);
    }
  }

  protected void unpublish(int pageIndex) {
    WebDriver userWebDriver = getPage(getBrowserKey(pageIndex)).getBrowser().getWebDriver();
    try {
      userWebDriver.findElement(By.id("buttonDisconnect")).click();
    } catch (ElementNotVisibleException e) {
      log.warn("Button 'buttonDisconnect' is not visible. Can't unpublish media.");
    }
  }

  public WebElement findElement(String label, Browser browser, String id) {
    try {
      return new WebDriverWait(browser.getWebDriver(), testTimeout, POLLING_LATENCY)
          .until(ExpectedConditions.presenceOfElementLocated(By.id(id)));
    } catch (TimeoutException e) {
      log.warn("Timeout when waiting for element {} to exist in browser {}", id, label);
      int originalTimeout = 60;
      try {
        originalTimeout = browser.getTimeout();
        log.debug("Original browser timeout (s): {}, set to 10", originalTimeout);
        browser.setTimeout(10);
        browser.changeTimeout(10);
        WebElement elem = browser.getWebDriver().findElement(By.id(id));
        log.info("Additional findElement call was able to locate {} in browser {}", id, label);
        return elem;
      } catch (NoSuchElementException e1) {
        log.debug("Additional findElement call couldn't locate {} in browser {} ({})", id, label,
            e1.getMessage());
        throw new NoSuchElementException("Element with id='" + id + "' not found after "
            + testTimeout + " seconds in browser " + label);
      } finally {
        browser.setTimeout(originalTimeout);
        browser.changeTimeout(originalTimeout);
      }
    }
  }

  public void waitWhileElement(String label, Browser browser, String id) throws TimeoutException {
    int originalTimeout = 60;
    try {
      originalTimeout = browser.getTimeout();
      log.debug("Original browser timeout (s): {}, set to 1", originalTimeout);
      browser.setTimeout(1);
      browser.changeTimeout(1);
      new WebDriverWait(browser.getWebDriver(), testTimeout, POLLING_LATENCY)
          .until(ExpectedConditions.invisibilityOfElementLocated(By.id(id)));
    } catch (org.openqa.selenium.TimeoutException e) {
      log.warn("Timeout when waiting for element {} to disappear in browser {}", id, label, e);
      throw new TimeoutException("Element with id='" + id + "' is present in page after "
          + testTimeout + " seconds");
    } finally {
      browser.setTimeout(originalTimeout);
      browser.changeTimeout(originalTimeout);
    }
  }

  /**
   * Wait for stream of another browser user.
   *
   * @param index
   *          own user index
   * @param label
   *          browser name (user name)
   * @param targetIndex
   *          the target user index
   */
  public void waitForStream(int index, String label, int targetIndex) {
    waitForStream(index, label, getBrowserNativeStreamName(targetIndex));
  }

  /**
   * Wait for stream of a fake user.
   *
   * @param index
   *          own user index
   * @param label
   *          browser name (user name)
   * @param targetIndex
   *          the target user index
   */
  public void waitForStreamFake(int index, String label, int targetIndex) {
    waitForStream(index, label, getFakeNativeStreamName(targetIndex));
  }

  /**
   * Wait for stream of user whose video tag has already been generated.
   *
   * @param index
   *          own user index
   * @param label
   *          browser name (user name)
   * @param targetVideoTagId
   *          expected video tag id
   */
  public void waitForStream(int index, String label, String targetVideoTagId) {
    String hostKey = getBrowserKey(index);
    Browser browser = getPage(hostKey).getBrowser();
    int i = 0;
    for (; i < testTimeout; i++) {
      WebElement video = findElement(label, browser, targetVideoTagId);
      String srcAtt = video.getAttribute("src");
      if (srcAtt != null && srcAtt.startsWith("blob")) {
        break;
      }
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
    if (i == testTimeout) {
      Assert.fail("Video tag '" + targetVideoTagId + "' is not playing media after " + testTimeout
          + " seconds in '" + hostKey + "'");
    }
  }

  public void verify(boolean[] activeBrowserUsers) {
    verify(activeBrowserUsers, null);
  }

  public void verify(boolean[] activeBrowserUsers, Map<String, Boolean> activeFakeUsers) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < activeBrowserUsers.length; i++) {
      if (activeBrowserUsers[i]) {
        sb.append(USER_BROWSER_PREFIX + i + ": active, ");
      } else {
        sb.append(USER_BROWSER_PREFIX + i + ": not, ");
      }
    }
    log.debug("Checking Browser users (active or not): [{}]", sb);
    if (activeFakeUsers != null && !activeFakeUsers.isEmpty()) {
      log.debug("Checking Fake users (active or not): {}", activeFakeUsers);
    }

    long startTime = System.nanoTime();

    for (int i = 0; i < activeBrowserUsers.length; i++) {

      if (activeBrowserUsers[i]) {
        Browser browser = getPage(getBrowserKey(i)).getBrowser();
        String browserLabel = getBrowserStreamName(i);
        String browserUsername = USER_BROWSER_PREFIX + i;

        for (int j = 0; j < activeBrowserUsers.length; j++) {
          String videoElementId = "video-" + getBrowserStreamName(j);
          verifyVideoInBrowser(browser, browserLabel, browserUsername, videoElementId,
              activeBrowserUsers[j]);
        }

        if (activeFakeUsers != null) {
          for (Entry<String, Boolean> fakeEntry : activeFakeUsers.entrySet()) {
            String videoElementId = "video-" + getFakeStreamName(fakeEntry.getKey());
            verifyVideoInBrowser(browser, browserLabel, browserUsername, videoElementId,
                fakeEntry.getValue());
          }
        }
      }
    }
    long endTime = System.nanoTime();
    double duration = ((double) endTime - startTime) / 1_000_000;
    log.debug("Checked active users: [{}] {} - in {} millis", sb, activeFakeUsers != null
        && !activeFakeUsers.isEmpty() ? "& " + activeFakeUsers : "", duration);
  }

  public void verifyVideoInBrowser(Browser browser, String browserLabel, String chromeName,
      String videoElementId, boolean isActive) {
    if (isActive) {
      log.debug("Verifing element {} exists in browser of {}", videoElementId, chromeName);
      try {
        WebElement video = findElement(browserLabel, browser, videoElementId);
        if (video == null) {
          fail("Video element " + videoElementId + " was not found in browser of " + chromeName);
        }
      } catch (NoSuchElementException e) {
        fail(e.getMessage());
      }
      log.debug("OK - element {} found in browser of {}", videoElementId, chromeName);
    } else {
      log.debug("Verifing element {} is missing from browser of {}", videoElementId, chromeName);
      try {
        waitWhileElement(browserLabel, browser, videoElementId);
      } catch (TimeoutException e) {
        fail(e.getMessage());
      }
      log.debug("OK - element {} is missing from browser of {}", videoElementId, chromeName);
    }
  }

  public void failWithExceptions() {
    if (!failed && !execExceptions.isEmpty()) {
      failed = true;
      StringBuffer sb = new StringBuffer();
      log.warn("\n+-------------------------------------------------------+\n"
          + "|   Failing because of the following test errors:       |\n"
          + "+-------------------------------------------------------+");
      for (String exKey : execExceptions.keySet()) {
        Exception e = execExceptions.get(exKey);
        log.warn("Error on '{}'", exKey, e);
        sb.append(exKey).append(" - ").append(e.getMessage()).append("\n");
      }
      sb.append("Check logs for more details");
      log.warn("\n+-------------------------------------------------------+\n"
          + "|   End of errors list                                  |\n"
          + "+-------------------------------------------------------+");
      Assert.fail(sb.toString());
    }
  }
}