All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nginflow.automation.core.Application Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
package com.nginflow.automation.core;

import com.nginflow.automation.core.model.Browser;
import com.nginflow.automation.core.model.HttpTransaction;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import org.openqa.selenium.WebDriver;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class Application {

  private static ThreadLocal browserThreadLocal = new ThreadLocal<>();
  private static List storedDrivers = new ArrayList<>();
  private static HttpTransaction http;


  static {
    Runtime.getRuntime().addShutdownHook(new Thread(() ->
        storedDrivers.stream().forEach(s -> s.getDriver().quit())
    ));
  }

  public static void addBrowser(Browser browser) {
    storedDrivers.add(browser);
    browserThreadLocal.set(browser);
  }

  public static Browser getBrowser() {
    return browserThreadLocal.get();
  }

  public static void SetBrowser(Browser browser) {
    if (getBrowser() == null) {
      addBrowser(browser);
    }
  }

  public static void setHttpTransaction(HttpTransaction http) {
    if (Application.http == null) Application.http = http;
  }

  public static HttpTransaction getHttpTransaction() {
    return Application.http;
  }

  @FunctionalInterface
  public static interface CustomHandler {
    void handle(WebDriver driver, ScriptObjectMirror rule, Consumer onSuccess, Consumer onError);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy