package zacksolutions;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.time.Duration;

public class Locators {
    public static void main(String[] args) throws InterruptedException {
        Locators lc = new Locators();
        lc.loginPage();
    }

    public void loginPage() throws InterruptedException {
        System.setProperty("web-driver.gecko.driver", "/home/ilyes/LearnSelenium/DemoProject/drivers/geckodriver");
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
        String url = "https://rahulshettyacademy.com/locatorspractice/";
        driver.get(url);
        driver.findElement(By.cssSelector("input[id='inputUsername']")).sendKeys("Zakaria");
        driver.findElement(By.cssSelector("input[name='inputPassword']")).sendKeys("Zakaria");
        driver.findElement(By.cssSelector("button[type='submit']")).click();
        String Err = driver.findElement(By.cssSelector("p.error")).getText();
        System.out.println(Err);
        driver.findElement(By.linkText("Forgot your password?")).click();
        driver.findElement(By.xpath("//input[@placeholder='Name']")).sendKeys("Desmond");
        driver.findElement(By.xpath("//input[@placeholder='Email']")).sendKeys("hdesmond@island.con");
        driver.findElement(By.cssSelector("input[placeholder='Phone Number']")).sendKeys("5551118888");
        Thread.sleep(1000);
        driver.findElement(By.cssSelector(".reset-pwd-btn")).click();
        System.out.println("");
        String newUser = driver.findElement(By.cssSelector("form p")).getText();
        System.out.println(newUser);
        String passw = "rahulshettyacademy";
        System.out.println("New User Created please enter the password: " + passw);
        Thread.sleep(1000);
        driver.findElement(By.cssSelector(".go-to-login-btn")).click();
        Thread.sleep(1000);
        driver.findElement(By.cssSelector("input[id='inputUsername']")).sendKeys("Desmond");
        driver.findElement(By.cssSelector("input[placeholder='Password']")).sendKeys(passw);
        driver.findElement(By.xpath("//input[@id='chkboxOne']")).click();
        driver.findElement(By.xpath("//input[@id='chkboxTwo']")).click();
        driver.findElement(By.cssSelector("button[type='submit']")).click();
        Thread.sleep(1000);
        String homePage = driver.getTitle();
        System.out.println(homePage);

        Thread.sleep(2000);
        driver.close();

    }
}