package com.sample;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;

public class SampleGoogle {
    @Test
        public void testGoogleSearch() throws InterruptedException {
            // Optional. If not specified, WebDriver searches the PATH for chromedriver.
           // System.setProperty("webdriver.chrome.driver", "/Users/jsonai/chromedriver.exe");
           WebDriver driver = new ChromeDriver();

           driver.get("http://www.google.com/");
        Thread.sleep(5000);  // Let the user actually see something!

        //2.Find the search Text box in the page
        WebElement searchBox = driver.findElement(By.name("q"));

        //3.Input the search text
        searchBox.sendKeys("Selenium");

        //4.Press the submit button
        searchBox.submit();
        Thread.sleep(5000);  // Let the user actually see something!

        //5.Close all the browser
        driver.quit();


        }

        @Test
    public void testSafeWay() throws InterruptedException {

        WebDriver driver = new ChromeDriver();
        driver.get("http://www.safeway.com/");

           // WebElement signInLinkMain = driver.findElement(By.xpath("//span[contains(text(),'Sign In / Up')]"));
            WebElement signInLinkMain = driver.findElement(By.linkText("Sign In / Up")) ;
            signInLinkMain.click();

        WebElement signInModal = driver.findElement(By.id("sign-in-modal-link")) ;
        signInModal.click();

        WebElement signInButton = driver.findElement(By.id("btnSignIn")) ;
        signInButton.submit();

        Thread.sleep(5000);  // Let the user actually see something!

        String expectedEmailMessage = "Please enter your email address.";
        String expectedPwdMessage = "Please enter a password.";
        String actualEmailErrMsg = driver.findElement(By.id("errorMsgEmail")).getText();
        String actualPwdMsg = driver.findElement(By.id("errorMsgPwd")).getText();

        Assertions.assertEquals(expectedEmailMessage, actualEmailErrMsg);
        Assertions.assertEquals(expectedPwdMessage, actualPwdMsg);

            //5.Close all the browser
        driver.quit();


    }
    }


