Skip to content

Instantly share code, notes, and snippets.

@Jacobvu84
Created September 12, 2019 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jacobvu84/c02518072c30d48cbba34850968608de to your computer and use it in GitHub Desktop.
Save Jacobvu84/c02518072c30d48cbba34850968608de to your computer and use it in GitHub Desktop.
Swipe open the notification shade on the device
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