Skip to content

Commit

Permalink
1. Updated README
Browse files Browse the repository at this point in the history
2. Skip closing and terminating the app when running in pCloudy
  • Loading branch information
anandbagmar committed Mar 18, 2021
1 parent 7ce1db0 commit e8b95dd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 37 deletions.
44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,61 @@ variable: `REPORT_PORTAL_FILE`

## Prerequisites

* Install JDK and set JAVA_HOME environment variable
* Setup Android Command-line tools and SDK and set ANDROID_HOME environment variable
* Install appium - https://applitools.com/blog/automatic-appium-setup/
* JDK
* **Minimum JDK version: 11**
* **Set JAVA_HOME environment variable**
* You can install JDK from here: https://adoptopenjdk.net/
* Setup the Android environment for test execution:
* **Set ANDROID_HOME environment variable**
* **Refer to this post for instructions how to automatically setup your environment - https://applitools.com/blog/automatic-appium-setup/**
* Additional References:
* Setup Android Command-line tools and SDK - https://developer.android.com/studio#command-tools
* Install appium - https://appium.io
* Appium Desktop App is a great way to identify locators, and the recorder is quite helpful to quickly identify multiple
locators for your tests - https://github.com/appium/appium-desktop/releases/tag/v1.20.2. You can also use Katalon
Studio for locator identification (especially helpful for Windows platform)
* To verify appium installation is successful, run
`appium-doctor` - it should not report any errors
* Install reportportal (Docker setup is the easiest way to proceed: https://reportportal.io/installation)
* Set `APPLITOOLS_API_KEY` as an environment variable
* To install reportportal on local machine, refer to https://reportportal.io/installation. (Docker setup is the easiest way to proceed).

## Running the tests

### Run on Android

To run all the tests against the Android platform, run the following command:

Platform=android ./gradlew clean cucumber
Platform=android ./gradlew run

#### Run on Local devices:

The framework, by default, automatically figures out if there are multiple devices connected to the machine, and if so,
will run the tests in parallel

#### Run on Device Farm:
#### Run on pCloudy's Device Farm:

To enable running the tests on pCloudy's Mobilab, the following additional environment variables need to be provided:
**To enable running the tests on pCloudy's Device Farm, the following additional environment variables need to be provided:**

* `RunOnCloud=true` - Default is `false`
* `CLOUD_USER` - Mobilab username
* `CLOUD_KEY` - Mobilab password

Sample command:

Platform=android RunOnCloud=true CLOUD_USER=myusername CLOUD_KEY=abcd1234abcd ./gradlew clean cucumber
Platform=android RunOnCloud=true CLOUD_USER=myusername CLOUD_KEY=abcd1234abcd ./gradlew run

For other cloud configurations, refer here: https://github.com/AppiumTestDistribution/AppiumTestDistribution

### Run on iOS

Platform=windows ./gradlew clean cucumber
Platform=windows ./gradlew run

### Run on Windows

Platform=windows ./gradlew clean cucumber
Platform=windows ./gradlew run

### Run on Web

Platform=web ./gradlew clean cucumber
Platform=web ./gradlew run

### Running Real Meeting simulations

Expand All @@ -102,10 +108,10 @@ You can run these tests as below:

### Running the tests with Applitools Visual AI

To enable Applitools Visual Testing in your test execution, the following additional environment variables need to be
provided:
**To enable Applitools Visual Testing in your test execution, the following additional environment variables need to be
provided:**

* `Visual=true` - to enable Visual Testing using Applitools
* `IsVisual=true` - to enable Visual Testing using Applitools
* `APPLITOOLS_API_KEY=<API_KEY>` - Sets the API key as provided by Applitools

### Running a subset of tests:
Expand All @@ -120,11 +126,11 @@ To run a subset of tests, for a given platform, the following additional environ

Sample commands:

Platform=android Tag=@schedule ./gradlew clean cucumber`
Platform=android Tag=@schedule ./gradlew run`

Platform=android Tag="@schedule and @signup" ./gradlew clean cucumber`
Platform=android Tag="@schedule and @signup" ./gradlew run`

Platform=android Tag="@schedule or @signup" ./gradlew clean cucumber`
Platform=android Tag="@schedule or @signup" ./gradlew run`

### Using a different apk for execution (Android):

Expand All @@ -135,7 +141,7 @@ caps/mobilab_capabilties.json, the following additional environment variable nee

Sample command:

AppPath=~/Downloads/MyLatestApp.apk Platform=android ./gradlew clean cucumber
AppPath=~/Downloads/MyLatestApp.apk Platform=android ./gradlew run

## Troubleshooting / FAQs

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/znsio/e2e/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class Runner {
private static final String BRANCH_NAME = NOT_SET;
private static final String LOG_PROPERTIES_FILE = "logPropertiesFile";
private static final String DEFAULT_LOG_DIR = "target";
private static final String APP_PATH = "APP_PATH";
private static final String APP_PATH = "AppPath";
private static final String BROWSER = "Browser";
private static final String CAPS = "CAPS";
private static final String CONFIG_FILE = "CONFIG_FILE";
Expand Down
41 changes: 24 additions & 17 deletions src/main/java/com/znsio/e2e/tools/Drivers.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private void disableNotificationsAndToastsOnDevice (Driver currentDriver) {
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"};
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);
Expand Down Expand Up @@ -252,7 +252,7 @@ public void attachLogsAndCloseAllWebDrivers (TestExecutionContext context) {
userPersonaDrivers.keySet().forEach(key -> {
System.out.println("\tUser Persona: " + key);
validateVisualTestResults(key);
attachLogsAndCloseWebDriver(key);
attachLogsAndCloseDriver(key);
});
}

Expand All @@ -261,7 +261,7 @@ private void validateVisualTestResults (String key) {
driver.getVisual().handleTestResults(key);
}

private void attachLogsAndCloseWebDriver (String key) {
private void attachLogsAndCloseDriver (String key) {
Driver driver = userPersonaDrivers.get(key);
if (driver.getType().equals(Driver.WEB_DRIVER)) {
closeWebDriver(key, driver);
Expand All @@ -272,20 +272,27 @@ private void attachLogsAndCloseWebDriver (String key) {

private void closeAppOnDevice (Driver driver) {
String appPackageName = Runner.getAppPackageName();
System.out.println("Terminate app: " + appPackageName);
AppiumDriver appiumDriver = (AppiumDriver) driver.getInnerDriver();
boolean isAppTerminated = appiumDriver.terminateApp(appPackageName);
System.out.println("App terminated? " + isAppTerminated);
ApplicationState applicationState = appiumDriver.queryAppState(appPackageName);
System.out.println("Application State: " + applicationState);
appiumDriver.closeApp();
ReportPortal.emitLog(
String.format("App: '%s' termiated? '%s'. Current application state: '%s'%n",
appPackageName,
isAppTerminated,
applicationState),
"DEBUG",
new Date());
if (Runner.isRunningInPCloudy()) {
String message = "Skip terminating & closing app on Cloud device";
System.out.println(message);
ReportPortal.emitLog(message, "DEBUG", new Date());
} else {

System.out.println("Terminate app: " + appPackageName);
boolean isAppTerminated = appiumDriver.terminateApp(appPackageName);
System.out.println("App terminated? " + isAppTerminated);
ApplicationState applicationState = appiumDriver.queryAppState(appPackageName);
System.out.println("Application State: " + applicationState);
appiumDriver.closeApp();
ReportPortal.emitLog(
String.format("App: '%s' termiated? '%s'. Current application state: '%s'%n",
appPackageName,
isAppTerminated,
applicationState),
"DEBUG",
new Date());
}
}

private void closeWebDriver (String key, Driver driver) {
Expand Down

0 comments on commit e8b95dd

Please sign in to comment.