Skip to content

Commit

Permalink
disable notifications and toasts on device - in pCloudy device lab or…
Browse files Browse the repository at this point in the history
… for local
  • Loading branch information
anandbagmar committed Mar 17, 2021
1 parent b490463 commit 4b8433d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/znsio/e2e/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ public static String getAppPackageName () {
return configs.get(APP_PACKAGE_NAME);
}

public static boolean isRunningInPCloudy () {
return configsBoolean.get(IS_RUN_ON_CLOUD);
}

private void setBranchName () {
String[] listOfDevices = new String[]{"git", "rev-parse", "--abbrev-ref", "HEAD"};
CommandLineResponse response = CommandLineExecutor.execCommand(listOfDevices);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/znsio/e2e/tools/Drivers.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.znsio.e2e.entities.TEST_CONTEXT;
import com.znsio.e2e.exceptions.InvalidTestDataException;
import com.znsio.e2e.runner.Runner;
import com.znsio.e2e.tools.cmd.CommandLineExecutor;
import com.znsio.e2e.tools.cmd.CommandLineResponse;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.appmanagement.ApplicationState;
import io.github.bonigarcia.wdm.WebDriverManager;
Expand Down Expand Up @@ -104,9 +106,27 @@ private Driver createAndroidDriverForUser (String userPersona, Platform forPlatf
userPersona,
forPlatform.name(),
numberOfAndroidDriversUsed);
disableNotificationsAndToastsOnDevice(currentDriver);
return currentDriver;
}

private void disableNotificationsAndToastsOnDevice (Driver currentDriver) {
if (Runner.isRunningInPCloudy()) {
Object disableToasts = ((AppiumDriver) currentDriver.getInnerDriver()).executeScript("pCloudy_executeAdbCommand", "adb shell appops set " + Runner.getAppPackageName() + " TOAST_WINDOW deny");
System.out.println("@disableToastsCommandResponse: " + disableToasts);
Object disableNotifications = ((AppiumDriver) currentDriver.getInnerDriver()).executeScript("pCloudy_executeAdbCommand", "adb shell settings put global heads_up_notifications_enabled 0");
System.out.println("@disableNotificationsCommandResponse: " + disableNotifications);
} else {
String[] disableToastsCommand = new String[] {"adb", "-s", "${device.SERIAL}", "shell", "appops", "set", Runner.getAppPackageName(), "TOAST_WINDOW", "deny"};
String[] disableNotificationsCommand = new String[] {"adb", "-s", "${device.SERIAL}", "shell", "settings", "put", "global", "heads_up_notifications_enabled", "0"};

CommandLineResponse disableToastsCommandResponse = CommandLineExecutor.execCommand(disableToastsCommand);
System.out.println("disableToastsCommandResponse: " + disableToastsCommandResponse);
CommandLineResponse disableNotificationsCommandResponse = CommandLineExecutor.execCommand(disableNotificationsCommand);
System.out.println("disableNotificationsCommandResponse: " + disableNotificationsCommandResponse);
}
}

@NotNull
private Driver createWebDriverForUser (String userPersona, Platform forPlatform, TestExecutionContext context) {
System.out.printf("getWebDriverForUser: begin: userPersona: '%s', Platform: '%s', Number of webdrivers: '%d'%n",
Expand Down

0 comments on commit 4b8433d

Please sign in to comment.