package com.agile611.testng.webdriver;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;

public class KeyboardKeysTest extends BaseTest {
    @Test
    public void KeyboardKeysExample() throws InterruptedException {
        driver.get("http://the-internet.herokuapp.com/key_presses");
        Actions builder = new Actions(driver);
        builder.sendKeys(Keys.SPACE).build().perform();
        assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: SPACE"));
        builder.sendKeys(Keys.LEFT).build().perform();
        assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: LEFT"));

        WebElement textBox = driver.findElement(By.id("target"));
        textBox.click();
        textBox.sendKeys("Hello World");
        textBox.sendKeys(Keys.ESCAPE);
        assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: ESCAPE"));
    }
}