package Tests;

import Utility.ExcelUtils;
import Utility.KeywordUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.*;
import org.testng.asserts.SoftAssert;

import java.util.concurrent.TimeUnit;


public class LoginTestClass {

    private WebDriver driver;
    private SoftAssert sa;
    private ExcelUtils excelUtils;
    private KeywordUtils keywordUtils;


    private String geckoDriverPath;
    private String excelPath;



    private String seznamURL = "https://www.seznam.cz/";
    private String username = "pikachubatman";
    private String password = "heslo12345";
    private String wrongPassword = "heslo";
    private String correctErrorMessage = "Chybně zadané heslo nebo uživatelské jméno";
    private String wrongErrorMessage = "Chybně zadané heslo nebo uživatelské jméno JNDVBHFSVBSDBEFCSHFCHN";

    @BeforeClass
    public void beforeClass() throws Exception {
        geckoDriverPath = "C:\\Users\\lukas\\IdeaProjects\\BpSeznamEmail\\geckodriver.exe";
        System.setProperty("webdriver.gecko.driver", geckoDriverPath);
        excelPath = "C:\\Users\\lukas\\IdeaProjects\\BpSeznamEmail\\src\\main\\java\\DataEngine\\LoginTests.xlsx";

        excelUtils = new ExcelUtils();
        excelUtils.setExcelFile(excelPath);

        keywordUtils = new KeywordUtils(excelUtils);

    }


    @AfterMethod
    public void afterMethod()
    {
        driver.quit();
    }

    @BeforeMethod
    public void beforeMethod() throws Exception {
        sa = new SoftAssert();
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        keywordUtils.initPages(driver, sa);
    }


    @Test(priority = 1)
    public void unsuccessfulLoginTCKeywords() throws Exception {
        keywordUtils.initTC("Unsuccessful_Login");
        keywordUtils.performTest();
        sa.assertAll(); //This can't be in @AfterMethod because it's feature of testNG that if there is failure in @AfterMethod the test run is terminated
    }

    @Test(priority = 2)
    public void successfulLoginTCKeywords() throws Exception {
        keywordUtils.initTC("Successful_Login");
        keywordUtils.performTest();
        sa.assertAll();
    }




/*
    @Test
    public void unsuccessfulLoginTC() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {

        // login
        SeznamPage seznamPage = new SeznamPage(driver, sa);
        seznamPage.goToURL(seznamURL);
        seznamPage.isSeznamPageDisplayed(true);
        seznamPage.clickShowLoginButton();
        seznamPage.fillUsernameTextbox(username);
        seznamPage.fillPasswordTextbox(wrongPassword);
        seznamPage.clickLoginButton();

        //check unsuccessful login and login with correct credentials
        LoginPage loginPage = new LoginPage(driver, sa);
        loginPage.isLoginPageDisplayed(true);
        loginPage.checkErrorMessage(wrongErrorMessage);
        loginPage.setPassword(password);
        loginPage.clickOnSubmitButton();

        //check successful Login
        OverviewPage overviewPage = new OverviewPage(driver, sa);
        overviewPage.isOverviewPageDisplayed(true);


    }
   */
}


