Skip to content

Commit 6be7a85

Browse files
committed
Working with Keys
1 parent d973e62 commit 6be7a85

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

webdriver_java/src/main/java/pages/HomePage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public HoversPage clickHovers(){
2626
return new HoversPage(driver);
2727
}
2828

29+
public KeyPressesPage clickKeyPresses(){
30+
clickLink("Key Presses");
31+
return new KeyPressesPage(driver);
32+
}
33+
2934
private void clickLink(String linkText){
3035
driver.findElement(By.linkText(linkText)).click();
3136
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package pages;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.Keys;
5+
import org.openqa.selenium.WebDriver;
6+
7+
public class KeyPressesPage {
8+
9+
private WebDriver driver;
10+
private By inputField = By.id("target");
11+
private By resultText = By.id("result");
12+
13+
public KeyPressesPage(WebDriver driver){
14+
this.driver = driver;
15+
}
16+
17+
public void enterText(String text){
18+
driver.findElement(inputField).sendKeys(text);
19+
}
20+
21+
public void enterPi(){
22+
enterText(Keys.chord(Keys.ALT, "p") + "=3.14");
23+
}
24+
25+
public String getResult(){
26+
return driver.findElement(resultText).getText();
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package keys;
2+
3+
import base.BaseTests;
4+
import org.openqa.selenium.Keys;
5+
import org.testng.annotations.Test;
6+
7+
import static org.testng.Assert.assertEquals;
8+
9+
public class KeysTests extends BaseTests {
10+
11+
@Test
12+
public void testBackspace(){
13+
var keyPage = homePage.clickKeyPresses();
14+
keyPage.enterText("A" + Keys.BACK_SPACE);
15+
assertEquals(keyPage.getResult(), "You entered: BACK_SPACE");
16+
}
17+
18+
@Test
19+
public void testPi(){
20+
var keyPage = homePage.clickKeyPresses();
21+
keyPage.enterPi();
22+
/*
23+
NOTE: we didn't finish this test in the video.
24+
We debugged to watch it enter the pi key
25+
*/
26+
}
27+
}

0 commit comments

Comments
 (0)