package zacksolutions;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class AutomateGiteaLoginTest {
    WebDriver driver;
    @BeforeTest
    @Parameters("Browser")
    public void setUp(String browser){
        if(browser.equalsIgnoreCase("FireFox")){
            System.out.println("Initiating Fire Fox ");
            System.getProperty("web-driver.gecko","user.dir" + "/SeleniumPractice/InterviewCodingQuestionQA/Drivers/geckodriver");
            driver = new FirefoxDriver();
        } else if( browser.equalsIgnoreCase("Chrome")){
            System.out.println("Initiating Chrome");
            System.getProperty("web-driver.chrome","user.dir" + "/SeleniumPractice/InterviewCodingQuestionQA/Drivers/chromedriver");
            driver = new ChromeDriver();
        }
        driver.get("https://gitea.zacksolutions.dev/");
        driver.manage().window().maximize();
        System.out.println(driver.getTitle());
    }
    @Test
    public void giteaLogin(){
        WebElement signIn = driver.findElement(By.cssSelector(".item[rel$='nofollow']"));
        signIn.click();
        driver.findElement(By.cssSelector("input[id='user_name']")).sendKeys("Zakaria");
        driver.findElement(By.cssSelector("input[id='password']")).sendKeys("engraved-alone-naming");
        driver.findElement(By.cssSelector("button[class$='ui primary button']")).click();
        System.out.println(driver.getTitle());
        String User = driver.findElement(By.cssSelector("span[class='text truncated-item-container'] span[class='truncated-item-name']")).getText();
        System.out.println(User);
    }
    @AfterTest
    public void tearDown(){
        driver.close();
    }
}
