Skip to content

Commit e652142

Browse files
authored
Implement working unit test for XCUITest (#311)
1 parent aba7030 commit e652142

File tree

2 files changed

+33
-19
lines changed
  • src
    • main/java/com/nordstrom/automation/selenium/examples
    • test/java/com/nordstrom/automation/selenium/ios

2 files changed

+33
-19
lines changed

src/main/java/com/nordstrom/automation/selenium/examples/IOSPage.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/test/java/com/nordstrom/automation/selenium/ios/IOSTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class IOSTest extends TestNgTargetBase {
1717
@TargetPlatform(IOS_APP_NAME)
1818
public void testEditing() {
1919
IOSPage page = getInitialPage();
20-
page.modifyField("Hello world!");
21-
assertEquals(page.accessField(), "Hello world!");
20+
assertEquals(page.computeSum(1, 2), 3);
21+
assertEquals(page.getAnswerAsString(), "3");
2222
}
2323

2424
}

0 commit comments

Comments
 (0)