package AllureReporting;

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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;

import java.time.Duration;

public class Tests {

    WebDriver obj = new ChromeDriver();
    SoftAssert test;

    WebDriverWait wait = new WebDriverWait(obj,Duration.ofSeconds(5));

    @BeforeClass
    public void setup() {
        obj.manage().timeouts().implicitlyWait(Duration.ofSeconds(8));
        obj.get("https://rahulshettyacademy.com/locatorspractice/");
        test = new SoftAssert();  // Initialize SoftAssert
    }

    @Test(priority = 1)
    public void correctRedirect() {
        String title = obj.getTitle();
        System.out.println("Page title is: " + title);  // For debugging
        test.assertEquals(title, "Rahul Shetty Academy - Login page");  // Expected title
    }

    @Test(priority = 2)
    public void login() {
        // Creating web elements for Email and password
        WebElement email = obj.findElement(By.id("inputUsername"));
        email.sendKeys("Qazi");

        WebElement password = obj.findElement(By.xpath("//input[@placeholder='Password']"));
        password.sendKeys("rahulshettyacademy");

        wait.until(ExpectedConditions.visibilityOf(password));
        WebElement button = obj.findElement(By.cssSelector(".submit.signInBtn"));
        button.click();

        String result = obj.findElement(By.cssSelector("div.login-container h2")).getText().trim();
        test.assertEquals(result, "Hello Qazi,");  // Adjusted expected text
    }

    @Test(priority = 3)
    public void reg()
    {
      throw new SkipException("test is skip");
    }

    @AfterClass
    public void after() {
        test.assertAll();
        obj.quit();  // Close the browser
    }
}
