package zacksolutions.base;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.ExtentReports;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Initialization {
  public static WebDriver driver;
  public static Properties prop;
  public static ExtentReports extent;
  public static ExtentTest test;


  public Initialization() {

    try {

      prop = new Properties();
     FileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "/src/main/java/zacksolutions/config/config.properties");
      prop.load(fis);

    } catch (IOException e) {
      // TODO: handle exception
      e.printStackTrace();
    }

  }

  public void BrowserInit() {
    String path = System.getProperty("user.dir") + "/reports/index.html";
    ExtentSparkReporter spark = new ExtentSparkReporter(path);
    spark.config().setDocumentTitle("Zen Test Case");
    spark.config().setReportName("Zenful");
    extent = new ExtentReports();
    extent.attachReporter(spark);
    extent.setSystemInfo("Test Done By: ", "Sami");
    String browsername = prop.getProperty("browserC");
    if (browsername.equalsIgnoreCase("firefox")) {
      System.setProperty("web-driver.gecko.driver","user.dir" + "/drivers/geckodriver");
      driver = new FirefoxDriver();
      driver.get(prop.getProperty("url"));
    }
    if (browsername.equalsIgnoreCase("chrome")) {
      System.setProperty("web-driver.gecko.driver", "user.dir" + "/drivers/chromedriver");
      driver = new ChromeDriver();
      driver.get(prop.getProperty("url"));
    }
    driver.manage().window().maximize();
    driver.manage().deleteAllCookies();
  }
}
