package com.example.Utils;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

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

public class BaseClass {

    public WebDriver driver;
    public WebDriver WebDriverManager() throws IOException {
        FileInputStream fis=new FileInputStream(System.getProperty("user.dir")+"//src//main//resources//global.properties");
        Properties prop=new Properties();
        prop.load(fis);
        String url=prop.getProperty("Url");
        String browser_properties=prop.getProperty("browser");
        String browser_maven=System.getProperty("browser");
        String browser=browser_maven!=null ?browser_maven:browser_properties;
        if(driver==null) {
            if(browser.equalsIgnoreCase("chrome"))
            {                //For chrome browser any other browser can add their
            System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver");
            driver = new ChromeDriver();
            driver.manage().window().maximize();
            }
//          if(prop.getProperty("browser").equalsIgnoreCase("firefox"))
//          {
//            //fire fox browser driver
//
//           }
            driver.get(url);
        }
        return driver;
    }
}
