Created
September 12, 2019 03:10
-
-
Save Jacobvu84/c02518072c30d48cbba34850968608de to your computer and use it in GitHub Desktop.
Swipe open the notification shade on the device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class iOSPushNotification extends AppiumObject implements Interaction { | |
private String show; | |
public iOSPushNotification(String show) { | |
this.show = show; | |
} | |
@Override | |
@Step("{0} #show push notification") | |
public <T extends Actor> void performAs(T actor) { | |
if ("shows".equals(show)) { | |
showNotifications(actor); | |
} else { | |
hideNotifications(actor); | |
} | |
} | |
private void showNotifications(Actor actor) { | |
manageNotifications(actor, "shows"); | |
} | |
private void hideNotifications(Actor actor) { | |
manageNotifications(actor, "hides"); | |
} | |
private void manageNotifications(Actor actor, String show) { | |
Dimension size = getScreenSize(actor); | |
int yMargin = 50; | |
int xMid = size.width / 2; | |
if ("shows".equals(show)) { | |
withAction(actor).press(PointOption.point(xMid, yMargin)); | |
} else { | |
withAction(actor).press(PointOption.point(xMid, size.height - yMargin)); | |
} | |
withAction(actor).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))); | |
if ("shows".equals(show)) { | |
withAction(actor).moveTo(PointOption.point(xMid, size.height - yMargin)); | |
} else { | |
withAction(actor).moveTo(PointOption.point(xMid, yMargin)); | |
} | |
withAction(actor).perform(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment