package com.playwrightdemo.test;

import com.playwrightdemo.pages.LoginPage;
import com.playwrightdemo.utils.ConfigReader;
import com.playwrightdemo.utils.ExcelUtilities;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.IOException;

public class LoginPageTest extends BaseTest{


    LoginPage loginPage;

    Logger logger= LogManager.getLogger(this.getClass());

    ExcelUtilities excelUtilities;

    LoginPageTest() {

        super();
    }




    private void logTestMethodName(String status) {
        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        String methodName = stackTraceElements[2].getMethodName();
        logger.info("Test method '" + methodName + "' " + status);
    }


    @BeforeTest

    public void setUP() throws IOException {

        loginPage=new LoginPage();

//        intialization();

  //      excelUtilities=new ExcelUtilities();


    }

    @DataProvider (name = "ExcellenceLoginData")

public Object[][] multipleLoginDataProvider() {

        Object[][] loginData= ExcelUtilities.getCellData();

        return loginData;

    }




    @Test (enabled = true)

    public void verifyPageURL(){

       // Assert.assertEquals(loginPage.getPageURL(),"https://excellencedemo.ishir.org/login");

        logTestMethodName("passed");
        //logger.info("This test is passed");

    }


    @Test (enabled = true)

    public void verifyPageTitle(){

        Assert.assertEquals(loginPage.getPageTitle(),"Excellence Center");

        logTestMethodName("passed");

        //logger.info("This test is passed");

    }

    @Test (enabled = true)

    public void verifyInvalidLogin(){
     loginPage.fillEmail("TestUser");
       loginPage.fillPassword("test123");
       loginPage.clickLoginButton();
        Assert.assertEquals( loginPage.getErrorMessage(),"These credentials do not match our records.");

        logTestMethodName("passed");

    }

    @Test (enabled = true)

    public void verifyValidLogin(){
        loginPage.fillEmail(ConfigReader.getAppUserName());
        loginPage.fillPassword(ConfigReader.getAppPassword());
        loginPage.clickLoginButton();
        Assert.assertEquals( loginPage.getDashboardMenuTextContent(),"Dashboard");

        logTestMethodName("passed");

    }



    @Test (enabled = true,dataProvider = "ExcellenceLoginData")

    public void verifyMultipleUserLogin(String email,String pwd, String userName){

        loginPage.fillEmail(email);
        loginPage.fillPassword(pwd);
        loginPage.clickLoginButton();

       Assert.assertEquals( loginPage.getDashboardMenuTextContent(),"Dashboard");
       Assert.assertEquals( loginPage.getUserNameDisplayed(), userName);

        logTestMethodName("passed");
    }




}
