package com.agile611.testng.webdriver;

import java.net.URL;
import java.time.Duration;

import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

public class BaseRemoteWebDriverTest {
    public RemoteWebDriver driver;
    @BeforeClass(alwaysRun = true) //Inicialización del navegador
    public void setUp() throws Exception {
        String browser = System.getProperty("browser");
        if (browser != null && browser.equalsIgnoreCase("chrome")) {
            ChromeOptions options = new ChromeOptions();
            driver = new RemoteWebDriver(new URL("http://0.0.0.0:4444/wd/hub"), options);
        } else {
            FirefoxOptions options = new FirefoxOptions();
            driver = new RemoteWebDriver(new URL("http://0.0.0.0:4444/wd/hub"), options);
        }
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
    }

    @AfterClass(alwaysRun = true) //El cierre del navegador
    public void tearDown() throws Exception {
        driver.quit();
    }
}
