Skip to content

Commit 7124444

Browse files
committed
Implement support for Mac platform
1 parent aba7030 commit 7124444

File tree

7 files changed

+98
-37
lines changed

7 files changed

+98
-37
lines changed

gradlew

100644100755
File mode 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/main/java/com/nordstrom/automation/selenium/examples/MacPage.java renamed to src/main/java/com/nordstrom/automation/selenium/examples/MacDocumentPage.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@
55

66
import com.nordstrom.automation.selenium.model.Page;
77

8-
/**
9-
* This class is the model for the target view of the sample application used by the Appium Macintosh unit test.
10-
*/
11-
public class MacPage extends Page {
8+
public class MacDocumentPage extends Page {
129

1310
/**
1411
* Constructor for main view context.
1512
*
1613
* @param driver driver object
1714
*/
18-
public MacPage(WebDriver driver) {
19-
super(driver);
20-
}
21-
15+
public MacDocumentPage(WebDriver driver) {
16+
super(driver);
17+
}
18+
2219
/**
2320
* This enumeration defines element locator constants.
2421
*/
2522
protected enum Using implements ByEnum {
26-
/** text field */
27-
EDIT_FIELD(By.className("XCUIElementTypeTextView"));
23+
TEXT_VIEW(By.id("First Text View"));
2824

2925
private final By locator;
3026

@@ -44,7 +40,7 @@ public By locator() {
4440
* @param keys string to type into text field
4541
*/
4642
public void modifyDocument(String keys) {
47-
findElement(Using.EDIT_FIELD).sendKeys(keys);
43+
findElement(Using.TEXT_VIEW).sendKeys(keys);
4844
}
4945

5046
/**
@@ -53,7 +49,7 @@ public void modifyDocument(String keys) {
5349
* @return text field content
5450
*/
5551
public String accessDocument() {
56-
return findElement(Using.EDIT_FIELD).getText();
52+
return findElement(Using.TEXT_VIEW).getText();
5753
}
5854

5955
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.nordstrom.automation.selenium.examples;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
6+
import com.nordstrom.automation.selenium.model.Page;
7+
8+
/**
9+
* This class is the model for the target view of the sample application used by the Appium Macintosh unit test.
10+
*/
11+
public class MacLaunchPage extends Page {
12+
13+
/**
14+
* Constructor for main view context.
15+
*
16+
* @param driver driver object
17+
*/
18+
public MacLaunchPage(WebDriver driver) {
19+
super(driver);
20+
}
21+
22+
/**
23+
* This enumeration defines element locator constants.
24+
*/
25+
protected enum Using implements ByEnum {
26+
NEW_DOCUMENT(By.id("New Document"));
27+
28+
private final By locator;
29+
30+
Using(By locator) {
31+
this.locator = locator;
32+
}
33+
34+
@Override
35+
public By locator() {
36+
return locator;
37+
}
38+
}
39+
40+
public MacDocumentPage openNewDocument() {
41+
findElement(Using.NEW_DOCUMENT).click();
42+
setWindowState(WindowState.WILL_CLOSE);
43+
MacDocumentPage newPage = new MacDocumentPage(driver);
44+
newPage.setWindowState(WindowState.WILL_CLOSE);
45+
return newPage;
46+
}
47+
48+
}

src/main/java/com/nordstrom/automation/selenium/model/ContainerMethodInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.openqa.selenium.NoAlertPresentException;
1010
import org.openqa.selenium.SearchContext;
1111
import org.openqa.selenium.TimeoutException;
12+
import org.openqa.selenium.UnsupportedCommandException;
1213
import org.openqa.selenium.WebDriver;
1314
import org.openqa.selenium.WebDriverException;
1415
import org.openqa.selenium.WebElement;
@@ -139,7 +140,7 @@ public Object intercept(@This final Object obj, @Origin final Method method, @Al
139140
driver.switchTo().alert();
140141
// alert is shown
141142
hasDialog = true;
142-
} catch (NoAlertPresentException eaten) {
143+
} catch (NoAlertPresentException | UnsupportedCommandException eaten) {
143144
try {
144145
// get stale wait reference element by XPath
145146
reference = driver.findElement(By.xpath("//*"));

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
}

src/test/java/com/nordstrom/automation/selenium/mac/MacTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
import org.testng.annotations.Test;
77

88
import com.nordstrom.automation.selenium.annotations.InitialPage;
9-
import com.nordstrom.automation.selenium.examples.MacPage;
9+
import com.nordstrom.automation.selenium.examples.MacDocumentPage;
10+
import com.nordstrom.automation.selenium.examples.MacLaunchPage;
1011
import com.nordstrom.automation.selenium.platform.TargetPlatform;
1112
import com.nordstrom.automation.selenium.support.TestNgTargetBase;
1213

13-
@InitialPage(MacPage.class)
14+
@InitialPage(MacLaunchPage.class)
1415
public class MacTest extends TestNgTargetBase {
1516

1617
@Test
1718
@TargetPlatform(MAC_APP_NAME)
1819
public void testEditing() {
19-
MacPage page = getInitialPage();
20-
page.modifyDocument("Hello world!");
21-
assertEquals(page.accessDocument(), "Hello world!");
20+
MacLaunchPage launchPage = getInitialPage();
21+
MacDocumentPage documentPage = launchPage.openNewDocument();
22+
documentPage.modifyDocument("Hello world!");
23+
assertEquals(documentPage.accessDocument(), "Hello world!");
2224
}
2325

2426
}

0 commit comments

Comments
 (0)