File tree 3 files changed +60
-0
lines changed
3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ public HoversPage clickHovers(){
26
26
return new HoversPage (driver );
27
27
}
28
28
29
+ public KeyPressesPage clickKeyPresses (){
30
+ clickLink ("Key Presses" );
31
+ return new KeyPressesPage (driver );
32
+ }
33
+
29
34
private void clickLink (String linkText ){
30
35
driver .findElement (By .linkText (linkText )).click ();
31
36
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments