@@ -23,8 +23,10 @@ public IOSPage(WebDriver driver) {
2323 * This enumeration defines element locator constants.
2424 */
2525 protected enum Using implements ByEnum {
26- /** text field */
27- TEXT_FIELD (By .className ("XCUIElementTypeTextField" ));
26+ INTEGER_A (By .id ("IntegerA" )),
27+ INTEGER_B (By .id ("IntegerB" )),
28+ COMPUTE_SUM (By .id ("ComputeSumButton" )),
29+ ANSWER (By .id ("Answer" ));
2830
2931 private final By locator ;
3032
@@ -38,23 +40,35 @@ public By locator() {
3840 }
3941 }
4042
41- /**
42- * Populate text field with the specified string.
43- *
44- * @param keys string to type into text field
45- */
46- public void modifyField (String keys ) {
47- findElement (Using .TEXT_FIELD ).click ();
48- findElement (Using .TEXT_FIELD ).sendKeys (keys );
43+ public int computeSum (int a , int b ) {
44+ updateIntegerA (a );
45+ updateIntegerB (b );
46+ return computeSum ();
4947 }
5048
51- /**
52- * Get text field content.
53- *
54- * @return text field content
55- */
56- public String accessField () {
57- return findElement (Using .TEXT_FIELD ).getText ();
49+ public void updateIntegerA (int a ) {
50+ findElement (Using .INTEGER_A ).sendKeys (Integer .toString (a ));
51+ }
52+
53+ public void updateIntegerB (int b ) {
54+ findElement (Using .INTEGER_B ).sendKeys (Integer .toString (b ));
55+ }
56+
57+ public int computeSum () {
58+ findElement (Using .COMPUTE_SUM ).click ();
59+ return getAnswerAsInt ();
60+ }
61+
62+ public int getAnswerAsInt () {
63+ try {
64+ return Integer .parseInt (getAnswerAsString ());
65+ } catch (NumberFormatException e ) {
66+ return 0 ;
67+ }
68+ }
69+
70+ public String getAnswerAsString () {
71+ return findElement (Using .ANSWER ).getText ();
5872 }
5973
6074}
0 commit comments