Keyboards Test

This commit is contained in:
Guillem Hernandez Sola
2026-04-21 12:12:58 +02:00
parent 379246891e
commit 68eae36331

View File

@@ -2,6 +2,7 @@ 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;
@@ -12,10 +13,14 @@ public class KeyboardKeysTest extends BaseTest {
driver.get("http://the-internet.herokuapp.com/key_presses");
Actions builder = new Actions(driver);
builder.sendKeys(Keys.SPACE).build().perform();
Thread.sleep(2000);
assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: SPACE"));
builder.sendKeys(Keys.LEFT).build().perform();
Thread.sleep(2000);
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"));
}
}