From 4140e33a0f4a8a0ddf7c86735eacbb2865c4674c Mon Sep 17 00:00:00 2001
From: VimalRaj Selvam
Date: Wed, 22 Feb 2017 09:17:16 +0530
Subject: [PATCH 1/5] Simplified the StartsActivity by reducing the number of
parameters through the POJO class.
---
docs/The-starting-of-an-Android-app.md | 6 +-
.../appium/java_client/android/Activity.java | 191 ++++++++++++++++++
.../java_client/android/StartsActivity.java | 103 ++--------
.../AndroidAbilityToUseSupplierTest.java | 9 +-
.../android/AndroidActivityTest.java | 43 ++--
.../android/AndroidContextTest.java | 5 +-
.../android/AndroidElementTest.java | 15 +-
.../android/AndroidFunctionTest.java | 5 +-
.../android/AndroidSearchingTest.java | 5 +-
.../java_client/android/AndroidTouchTest.java | 50 ++++-
.../java_client/android/IntentTest.java | 22 +-
.../java_client/android/UIAutomator2Test.java | 5 +-
.../java_client/appium/AndroidTest.java | 11 +-
.../widgets/AndroidOverrideWidgetTest.java | 6 +-
.../widgets/android/AndroidWidgetTest.java | 6 +-
.../combined/AndroidCombinedWidgetTest.java | 6 +-
16 files changed, 358 insertions(+), 130 deletions(-)
create mode 100644 src/main/java/io/appium/java_client/android/Activity.java
diff --git a/docs/The-starting-of-an-Android-app.md b/docs/The-starting-of-an-Android-app.md
index 3edad343e..ea88cd90d 100644
--- a/docs/The-starting-of-an-Android-app.md
+++ b/docs/The-starting-of-an-Android-app.md
@@ -103,6 +103,7 @@ use Android-specific API eventually.
```java
import io.appium.java_client.android.StartsActivity;
+ import io.appium.java_client.android.Activity;
...
@@ -118,7 +119,10 @@ StartsActivity startsActivity = new StartsActivity() {
}
};
-StartsActivity startsActivity.startActivity("your.package.name", ".ActivityName");
+Activity activity = new Activity();
+activity.setAppPackage("your.package.name");
+activity.setAppActivity(".ActivityName");
+StartsActivity startsActivity.startActivity(activity);
```
_Samples of the searching by AndroidUIAutomator using_ ```io.appium.java_client.AppiumDriver```
diff --git a/src/main/java/io/appium/java_client/android/Activity.java b/src/main/java/io/appium/java_client/android/Activity.java
new file mode 100644
index 000000000..fe460d15b
--- /dev/null
+++ b/src/main/java/io/appium/java_client/android/Activity.java
@@ -0,0 +1,191 @@
+package io.appium.java_client.android;
+
+/**
+ * This is a simple POJO class to support the {@link StartsActivity}.
+ */
+public class Activity {
+ private String appPackage;
+ private String appActivity;
+ private String appWaitPackage;
+ private String appWaitActivity;
+ private String intentAction;
+ private String intentCategory;
+ private String intentFlags;
+ private String optionalIntentArguments;
+ private boolean stopApp;
+
+ public Activity() {
+ this.stopApp = true;
+ }
+
+ /**
+ * Gets the app package value.
+ *
+ * @return The app package value.
+ */
+ public String getAppPackage() {
+ return appPackage;
+ }
+
+ /**
+ * Sets the app package value.
+ *
+ * @param appPackage The app package value.
+ */
+ public void setAppPackage(String appPackage) {
+ this.appPackage = appPackage;
+ }
+
+ /**
+ * Gets the app activity value.
+ *
+ * @return The app activity value.
+ */
+ public String getAppActivity() {
+ return appActivity;
+ }
+
+ /**
+ * Sets the app activity value.
+ *
+ * @param appActivity The app activity value.
+ */
+ public void setAppActivity(String appActivity) {
+ this.appActivity = appActivity;
+ }
+
+ /**
+ * Gets the app wait package value.
+ *
+ * @return The app wait package value.
+ */
+ public String getAppWaitPackage() {
+ return appWaitPackage;
+ }
+
+ /**
+ * Sets the app wait package value.
+ *
+ * @param appWaitPackage The app wait package value.
+ */
+ public void setAppWaitPackage(String appWaitPackage) {
+ this.appWaitPackage = appWaitPackage;
+ }
+
+ /**
+ * Gets the app wait activity value.
+ *
+ * @return The app wait activity value.
+ */
+ public String getAppWaitActivity() {
+ return appWaitActivity;
+ }
+
+ /**
+ * Sets the app wait activity value.
+ *
+ * @param appWaitActivity The app wait activity value.
+ */
+ public void setAppWaitActivity(String appWaitActivity) {
+ this.appWaitActivity = appWaitActivity;
+ }
+
+ /**
+ * Gets the intent action value.
+ *
+ * @return The intent action value.
+ */
+ public String getIntentAction() {
+ return intentAction;
+ }
+
+ /**
+ * Sets the intent action value.
+ *
+ * @param intentAction The intent action value.
+ */
+ public void setIntentAction(String intentAction) {
+ this.intentAction = intentAction;
+ }
+
+ /**
+ * Gets the intent category value.
+ *
+ * @return The intent category value.
+ */
+ public String getIntentCategory() {
+ return intentCategory;
+ }
+
+ /**
+ * Sets the intent category value.
+ *
+ * @param intentCategory The intent category value.
+ */
+ public void setIntentCategory(String intentCategory) {
+ this.intentCategory = intentCategory;
+ }
+
+ /**
+ * Gets the intent flags value.
+ *
+ * @return The intent flags value.
+ */
+ public String getIntentFlags() {
+ return intentFlags;
+ }
+
+ /**
+ * Sets the intent flags value.
+ *
+ * @param intentFlags The intent flags value.
+ */
+ public void setIntentFlags(String intentFlags) {
+ this.intentFlags = intentFlags;
+ }
+
+ /**
+ * Gets the optional intent arguments value.
+ *
+ * @return The optional intent arguments value.
+ */
+ public String getOptionalIntentArguments() {
+ return optionalIntentArguments;
+ }
+
+ /**
+ * Sets the optional intent arguments value.
+ *
+ * @param optionalIntentArguments The optional intent arguments value.
+ */
+ public void setOptionalIntentArguments(String optionalIntentArguments) {
+ this.optionalIntentArguments = optionalIntentArguments;
+ }
+
+ /**
+ * Gets the stop app value.
+ *
+ * @return The stop app value.
+ */
+ public boolean isStopApp() {
+ return stopApp;
+ }
+
+ /**
+ * Sets the stop app value.
+ *
+ * @param stopApp The stop app value.
+ */
+ public void setStopApp(boolean stopApp) {
+ this.stopApp = stopApp;
+ }
+
+ @Override public String toString() {
+ return "Activity{" + "appPackage='" + appPackage + '\'' + ", appActivity='" + appActivity
+ + '\'' + ", appWaitPackage='" + appWaitPackage + '\'' + ", appWaitActivity='"
+ + appWaitActivity + '\'' + ", intentAction='" + intentAction + '\''
+ + ", intentCategory='" + intentCategory + '\'' + ", intentFlags='" + intentFlags + '\''
+ + ", optionalIntentArguments='" + optionalIntentArguments + '\'' + ", stopApp="
+ + stopApp + '}';
+ }
+}
diff --git a/src/main/java/io/appium/java_client/android/StartsActivity.java b/src/main/java/io/appium/java_client/android/StartsActivity.java
index 46ea81f30..4f29b7b8e 100644
--- a/src/main/java/io/appium/java_client/android/StartsActivity.java
+++ b/src/main/java/io/appium/java_client/android/StartsActivity.java
@@ -26,93 +26,26 @@ public interface StartsActivity extends ExecutesMethod {
/**
* This method should start arbitrary activity during a test. If the activity belongs to
* another application, that application is started and the activity is opened.
+ *
+ * Usage:
+ *
+ *
+ * {@code
+ * Activity activity = new Activity();
+ * activity.setAppPackage("com.foo");
+ * activity.setAppActivity(".bar");
+ * driver.startActivity(activity);
+ * }
+ *
*
- * @param appPackage The package containing the activity. [Required]
- * @param appActivity The activity to start. [Required]
- * @param appWaitPackage Automation will begin after this package starts. [Optional]
- * @param appWaitActivity Automation will begin after this activity starts. [Optional]
- * @param stopApp If true, target app will be stopped. [Optional]
+ * @param activity The {@link Activity} object
*/
- default void startActivity(String appPackage, String appActivity, String appWaitPackage,
- String appWaitActivity, boolean stopApp) throws IllegalArgumentException {
- this.startActivity(appPackage,appActivity,appWaitPackage,
- appWaitActivity,null,null,null,null,stopApp);
- }
-
- /**
- * This method should start arbitrary activity during a test. If the activity belongs to
- * another application, that application is started and the activity is opened.
- *
- * @param appPackage The package containing the activity. [Required]
- * @param appActivity The activity to start. [Required]
- * @param appWaitPackage Automation will begin after this package starts. [Optional]
- * @param appWaitActivity Automation will begin after this activity starts. [Optional]
- */
- default void startActivity(String appPackage, String appActivity, String appWaitPackage,
- String appWaitActivity) throws IllegalArgumentException {
- this.startActivity(appPackage, appActivity,
- appWaitPackage, appWaitActivity,null,null,null,null,true);
- }
-
- /**
- * This method should start arbitrary activity during a test. If the activity belongs to
- * another application, that application is started and the activity is opened.
- *
- * @param appPackage The package containing the activity. [Required]
- * @param appActivity The activity to start. [Required]
- */
- default void startActivity(String appPackage, String appActivity) throws IllegalArgumentException {
- this.startActivity(appPackage, appActivity, null, null,
- null,null,null,null,true);
- }
-
- /**
- * This method should start arbitrary activity during a test. If the activity belongs to
- * another application, that application is started and the activity is opened.
- *
- * @param appPackage The package containing the activity. [Required]
- * @param appActivity The activity to start. [Required]
- * @param appWaitPackage Automation will begin after this package starts. [Optional]
- * @param appWaitActivity Automation will begin after this activity starts. [Optional]
- * @param intentAction Intent action which will be used to start activity [Optional]
- * @param intentCategory Intent category which will be used to start activity [Optional]
- * @param intentFlags Flags that will be used to start activity [Optional]
- * @param intentOptionalArgs Additional intent arguments that will be used to
- * start activity [Optional]
- */
- default void startActivity(String appPackage, String appActivity,
- String appWaitPackage, String appWaitActivity,
- String intentAction, String intentCategory,
- String intentFlags, String intentOptionalArgs)
- throws IllegalArgumentException {
- this.startActivity(appPackage,appActivity,
- appWaitPackage,appWaitActivity,
- intentAction,intentCategory,intentFlags,intentOptionalArgs,true);
- }
-
- /**
- * This method should start arbitrary activity during a test. If the activity belongs to
- * another application, that application is started and the activity is opened.
- *
- * @param appPackage The package containing the activity. [Required]
- * @param appActivity The activity to start. [Required]
- * @param appWaitPackage Automation will begin after this package starts. [Optional]
- * @param appWaitActivity Automation will begin after this activity starts. [Optional]
- * @param intentAction Intent action which will be used to start activity [Optional]
- * @param intentCategory Intent category which will be used to start activity [Optional]
- * @param intentFlags Flags that will be used to start activity [Optional]
- * @param optionalIntentArguments Additional intent arguments that will be used to
- * start activity [Optional]
- * @param stopApp If true, target app will be stopped. [Optional]
- */
- default void startActivity(String appPackage, String appActivity, String appWaitPackage,
- String appWaitActivity, String intentAction,
- String intentCategory, String intentFlags,
- String optionalIntentArguments,boolean stopApp )
- throws IllegalArgumentException {
- CommandExecutionHelper.execute(this, startActivityCommand(appPackage, appActivity,
- appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags,
- optionalIntentArguments, stopApp));
+ default void startActivity(Activity activity) {
+ CommandExecutionHelper.execute(this,
+ startActivityCommand(activity.getAppPackage(), activity.getAppActivity(),
+ activity.getAppWaitPackage(), activity.getAppWaitActivity(),
+ activity.getIntentAction(), activity.getIntentCategory(), activity.getIntentFlags(),
+ activity.getOptionalIntentArguments(), activity.isStopApp()));
}
/**
diff --git a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java b/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java
index 685d5d9b6..e6671acb1 100644
--- a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java
@@ -1,7 +1,5 @@
package io.appium.java_client.android;
-import static org.junit.Assert.assertNotEquals;
-
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.functions.ActionSupplier;
@@ -10,6 +8,8 @@
import java.util.List;
+import static org.junit.Assert.assertNotEquals;
+
public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
private final ActionSupplier horizontalSwipe = () -> {
@@ -30,7 +30,10 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
.waitAction(2000).moveTo(driver.findElementByAccessibilityId("Auto Complete")).release();
@Test public void horizontalSwipingWithSupplier() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.Gallery1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.Gallery1");
+ driver.startActivity(activity);
AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery");
List images = gallery
.findElementsByClassName("android.widget.ImageView");
diff --git a/src/test/java/io/appium/java_client/android/AndroidActivityTest.java b/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
index c130e0b65..b598f32b8 100644
--- a/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
@@ -24,40 +24,57 @@
public class AndroidActivityTest extends BaseAndroidTest {
@Before public void setUp() throws Exception {
- driver.startActivity("io.appium.android.apis", ".ApiDemos");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".ApiDemos");
+ driver.startActivity(activity);
}
@Test public void startActivityInThisAppTestCase() {
- driver.startActivity("io.appium.android.apis",
- ".accessibility.AccessibilityNodeProviderActivity");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".accessibility.AccessibilityNodeProviderActivity");
+ driver.startActivity(activity);
assertEquals(driver.currentActivity(),
".accessibility.AccessibilityNodeProviderActivity");
}
@Test public void startActivityWithWaitingAppTestCase() {
- driver.startActivity("io.appium.android.apis",
- ".accessibility.AccessibilityNodeProviderActivity",
- "io.appium.android.apis", ".accessibility.AccessibilityNodeProviderActivity");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".accessibility.AccessibilityNodeProviderActivity");
+ activity.setAppWaitPackage("io.appium.android.apis");
+ activity.setAppWaitActivity(".accessibility.AccessibilityNodeProviderActivity");
+ driver.startActivity(activity);
assertEquals(driver.currentActivity(),
".accessibility.AccessibilityNodeProviderActivity");
}
@Test public void startActivityInNewAppTestCase() {
- driver.startActivity("com.android.contacts", ".ContactsListActivity");
+ Activity activity = new Activity();
+ activity.setAppPackage("com.android.contacts");
+ activity.setAppActivity(".ContactsListActivity");
+ driver.startActivity(activity);
assertEquals(driver.currentActivity(), ".ContactsListActivity");
driver.pressKeyCode(AndroidKeyCode.BACK);
assertEquals(driver.currentActivity(), ".ContactsListActivity");
}
@Test public void startActivityInNewAppTestCaseWithoutClosingApp() {
- driver.startActivity("io.appium.android.apis",
- ".accessibility.AccessibilityNodeProviderActivity");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".accessibility.AccessibilityNodeProviderActivity");
+ driver.startActivity(activity);
assertEquals(driver.currentActivity(), ".accessibility.AccessibilityNodeProviderActivity");
- driver.startActivity("com.android.contacts", ".ContactsListActivity",
- "com.android.contacts", ".ContactsListActivity", false);
+
+ activity.setAppPackage("com.android.contacts");
+ activity.setAppActivity(".ContactsListActivity");
+ activity.setAppWaitPackage("com.android.contacts");
+ activity.setAppWaitActivity(".ContactsListActivity");
+ activity.setStopApp(false);
+ driver.startActivity(activity);
assertEquals(driver.currentActivity(), ".ContactsListActivity");
driver.pressKeyCode(AndroidKeyCode.BACK);
- assertEquals(driver.currentActivity(),
- ".accessibility.AccessibilityNodeProviderActivity");
+ assertEquals(driver.currentActivity(), ".accessibility.AccessibilityNodeProviderActivity");
}
}
diff --git a/src/test/java/io/appium/java_client/android/AndroidContextTest.java b/src/test/java/io/appium/java_client/android/AndroidContextTest.java
index 2002582f4..3b880b13a 100644
--- a/src/test/java/io/appium/java_client/android/AndroidContextTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidContextTest.java
@@ -26,7 +26,10 @@
public class AndroidContextTest extends BaseAndroidTest {
@BeforeClass public static void beforeClass2() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.WebView1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.WebView1");
+ driver.startActivity(activity);
Thread.sleep(20000);
}
diff --git a/src/test/java/io/appium/java_client/android/AndroidElementTest.java b/src/test/java/io/appium/java_client/android/AndroidElementTest.java
index 00281537d..7cab358cd 100644
--- a/src/test/java/io/appium/java_client/android/AndroidElementTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidElementTest.java
@@ -29,7 +29,10 @@
public class AndroidElementTest extends BaseAndroidTest {
@Before public void setup() throws Exception {
- driver.startActivity("io.appium.android.apis", ".ApiDemos");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".ApiDemos");
+ driver.startActivity(activity);
}
@@ -55,7 +58,10 @@ public class AndroidElementTest extends BaseAndroidTest {
@Test public void replaceValueTest() {
String originalValue = "original value";
- driver.startActivity("io.appium.android.apis", ".view.Controls1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.Controls1");
+ driver.startActivity(activity);
AndroidElement editElement = driver
.findElementByAndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")");
editElement.sendKeys(originalValue);
@@ -78,7 +84,10 @@ public class AndroidElementTest extends BaseAndroidTest {
@Test public void setValueTest() {
String value = "new value";
- driver.startActivity("io.appium.android.apis", ".view.Controls1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.Controls1");
+ driver.startActivity(activity);
AndroidElement editElement = driver
.findElementByAndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")");
editElement.setValue(value);
diff --git a/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java b/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java
index 19fdd9041..7828c212b 100644
--- a/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java
@@ -66,7 +66,10 @@ public class AndroidFunctionTest extends BaseAndroidTest {
@BeforeClass public static void startWebViewActivity() throws Exception {
if (driver != null) {
- driver.startActivity("io.appium.android.apis", ".view.WebView1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.WebView1");
+ driver.startActivity(activity);
}
}
diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java
index 6b3dde8e6..7a8207bbe 100644
--- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java
@@ -30,7 +30,10 @@ public class AndroidSearchingTest extends BaseAndroidTest {
@Before
public void setup() throws Exception {
- driver.startActivity("io.appium.android.apis", ".ApiDemos");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".ApiDemos");
+ driver.startActivity(activity);
}
@Test public void findByAccessibilityIdTest() {
diff --git a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java b/src/test/java/io/appium/java_client/android/AndroidTouchTest.java
index d1e88c797..cce801ace 100644
--- a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidTouchTest.java
@@ -22,7 +22,10 @@ public void setUp() throws Exception {
}
@Test public void dragNDropByElementTest() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.DragAndDropDemo");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.DragAndDropDemo");
+ driver.startActivity(activity);
WebElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
WebElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
@@ -36,7 +39,10 @@ public void setUp() throws Exception {
}
@Test public void dragNDropByElementAndDurationTest() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.DragAndDropDemo");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.DragAndDropDemo");
+ driver.startActivity(activity);
WebElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
WebElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
@@ -50,7 +56,10 @@ public void setUp() throws Exception {
}
@Test public void dragNDropByCoordinatesTest() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.DragAndDropDemo");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.DragAndDropDemo");
+ driver.startActivity(activity);
AndroidElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
AndroidElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
@@ -67,7 +76,10 @@ public void setUp() throws Exception {
}
@Test public void dragNDropByCoordinatesAndDurationTest() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.DragAndDropDemo");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.DragAndDropDemo");
+ driver.startActivity(activity);
AndroidElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
AndroidElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
@@ -84,7 +96,10 @@ public void setUp() throws Exception {
}
@Test public void pressByCoordinatesTest() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.Buttons1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.Buttons1");
+ driver.startActivity(activity);
Point point =
driver.findElementById("io.appium.android.apis:id/button_toggle").getLocation();
new TouchAction(driver).press(point.x + 20, point.y + 30).waitAction(1000).release().perform();
@@ -93,7 +108,10 @@ public void setUp() throws Exception {
}
@Test public void pressByElementTest() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.Buttons1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.Buttons1");
+ driver.startActivity(activity);
new TouchAction(driver).press(driver.findElementById("io.appium.android.apis:id/button_toggle"))
.waitAction(1000).release().perform();
assertEquals("ON" ,driver
@@ -101,7 +119,10 @@ public void setUp() throws Exception {
}
@Test public void tapActionTestByElement() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.ChronometerDemo");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.ChronometerDemo");
+ driver.startActivity(activity);
AndroidElement chronometer =
driver.findElementById("io.appium.android.apis:id/chronometer");
@@ -118,7 +139,10 @@ public void setUp() throws Exception {
}
@Test public void tapActionTestByCoordinates() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.ChronometerDemo");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.ChronometerDemo");
+ driver.startActivity(activity);
AndroidElement chronometer =
driver.findElementById("io.appium.android.apis:id/chronometer");
@@ -136,7 +160,10 @@ public void setUp() throws Exception {
}
@Test public void horizontalSwipingTest() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.Gallery1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.Gallery1");
+ driver.startActivity(activity);
AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery");
List images = gallery
@@ -153,7 +180,10 @@ public void setUp() throws Exception {
}
@Test public void multiTouchTest() throws Exception {
- driver.startActivity("io.appium.android.apis", ".view.Buttons1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.Buttons1");
+ driver.startActivity(activity);
TouchAction press = new TouchAction(driver);
press.press(driver.findElementById("io.appium.android.apis:id/button_toggle")).waitAction(1000).release();
new MultiTouchAction(driver).add(press)
diff --git a/src/test/java/io/appium/java_client/android/IntentTest.java b/src/test/java/io/appium/java_client/android/IntentTest.java
index 1e700d6a4..b95134ee3 100644
--- a/src/test/java/io/appium/java_client/android/IntentTest.java
+++ b/src/test/java/io/appium/java_client/android/IntentTest.java
@@ -48,9 +48,14 @@ public class IntentTest {
@Test public void startActivityWithIntent() {
- driver.startActivity("com.android.mms", ".ui.ComposeMessageActivity", null, null,
- "android.intent.action.SEND", "android.intent.category.DEFAULT", "0x4000000",
- "-d \"TestIntent\" -t \"text/plain\"");
+ Activity activity = new Activity();
+ activity.setAppPackage("com.android.mms");
+ activity.setAppActivity(".ui.ComposeMessageActivity");
+ activity.setIntentAction("android.intent.action.SEND");
+ activity.setIntentCategory("android.intent.category.DEFAULT");
+ activity.setIntentFlags("0x4000000");
+ activity.setOptionalIntentArguments("-d \"TestIntent\" -t \"text/plain\"");
+ driver.startActivity(activity);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
@@ -59,9 +64,14 @@ public class IntentTest {
}
@Test public void startActivityWithDefaultIntentAndDefaultCategoryWithOptionalArgs() {
- driver.startActivity("com.prgguru.android", ".GreetingActivity", null, null,
- "android.intent.action.MAIN", "android.intent.category.DEFAULT", "0x4000000",
- "--es \"USERNAME\" \"AppiumIntentTest\" -t \"text/plain\"");
+ Activity activity = new Activity();
+ activity.setAppPackage("com.prgguru.android");
+ activity.setAppActivity(".GreetingActivity");
+ activity.setIntentAction("android.intent.action.MAIN");
+ activity.setIntentCategory("android.intent.category.DEFAULT");
+ activity.setIntentFlags("0x4000000");
+ activity.setOptionalIntentArguments("--es \"USERNAME\" \"AppiumIntentTest\" -t \"text/plain\"");
+ driver.startActivity(activity);
assertEquals(driver.findElementById("com.prgguru.android:id/textView1").getText(),
"Welcome AppiumIntentTest");
}
diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java
index 2ccd67248..6c8cae205 100644
--- a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java
+++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java
@@ -85,7 +85,10 @@ public class UIAutomator2Test {
@Test public void testToastMSGIsDisplayed() throws InterruptedException {
final WebDriverWait wait = new WebDriverWait(driver, 10);
- driver.startActivity("io.appium.android.apis", ".view.PopupMenu1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.PopupMenu1");
+ driver.startActivity(activity);
MobileElement popUpElement = driver.findElement(MobileBy.AccessibilityId("Make a Popup!"));
popUpElement.click();
diff --git a/src/test/java/io/appium/java_client/appium/AndroidTest.java b/src/test/java/io/appium/java_client/appium/AndroidTest.java
index 99f5668ef..b9f6e924b 100644
--- a/src/test/java/io/appium/java_client/appium/AndroidTest.java
+++ b/src/test/java/io/appium/java_client/appium/AndroidTest.java
@@ -7,6 +7,7 @@
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
+import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.android.StartsActivity;
import io.appium.java_client.remote.MobileCapabilityType;
@@ -78,7 +79,10 @@ public Response execute(String driverCommand) {
return driver.execute(driverCommand);
}
};
- startsActivity.startActivity("io.appium.android.apis", ".ApiDemos");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".ApiDemos");
+ startsActivity.startActivity(activity);
}
@Test
@@ -121,7 +125,10 @@ public void findByAccessibilityIdFromDriverTest() {
@Test public void replaceValueTest() {
String originalValue = "original value";
- startsActivity.startActivity("io.appium.android.apis", ".view.Controls1");
+ Activity activity = new Activity();
+ activity.setAppPackage("io.appium.android.apis");
+ activity.setAppActivity(".view.Controls1");
+ startsActivity.startActivity(activity);
AndroidElement editElement = driver
.findElement(MobileBy
.AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java
index ab491514c..fc237e875 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java
@@ -4,6 +4,7 @@
import static org.junit.Assert.assertTrue;
import io.appium.java_client.MobileElement;
+import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.pagefactory.TimeOutDuration;
@@ -70,7 +71,10 @@ public static void afterClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null) {
- driver.startActivity("com.codepath.example.rottentomatoes", "BoxOfficeActivity");
+ Activity activity = new Activity();
+ activity.setAppPackage("com.codepath.example.rottentomatoes");
+ activity.setAppActivity("BoxOfficeActivity");
+ driver.startActivity(activity);
}
}
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java
index 714340caa..1231cfea7 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java
@@ -4,6 +4,7 @@
import static org.junit.Assert.assertTrue;
import io.appium.java_client.MobileElement;
+import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.pagefactory.TimeOutDuration;
@@ -70,7 +71,10 @@ public static void afterClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null) {
- driver.startActivity("com.codepath.example.rottentomatoes", "BoxOfficeActivity");
+ Activity activity = new Activity();
+ activity.setAppPackage("com.codepath.example.rottentomatoes");
+ activity.setAppActivity("BoxOfficeActivity");
+ driver.startActivity(activity);
}
}
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java
index 0a7c5d220..9aba24e60 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java
@@ -4,6 +4,7 @@
import static org.junit.Assert.assertTrue;
import io.appium.java_client.MobileElement;
+import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.pagefactory.TimeOutDuration;
@@ -70,7 +71,10 @@ public static void afterClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null) {
- driver.startActivity("com.codepath.example.rottentomatoes", "BoxOfficeActivity");
+ Activity activity = new Activity();
+ activity.setAppPackage("com.codepath.example.rottentomatoes");
+ activity.setAppActivity("BoxOfficeActivity");
+ driver.startActivity(activity);
}
}
From 9288d3363436406eee3b16e624281b3afde3f51b Mon Sep 17 00:00:00 2001
From: VimalRaj Selvam
Date: Wed, 22 Feb 2017 22:07:59 +0530
Subject: [PATCH 2/5] Addressed review comments
---
.../appium/java_client/android/Activity.java | 4 +-
.../java_client/android/StartsActivity.java | 102 ++++++++++++++++++
.../AndroidAbilityToUseSupplierTest.java | 8 +-
.../android/AndroidActivityTest.java | 23 ++--
.../android/AndroidContextTest.java | 4 +-
.../android/AndroidElementTest.java | 12 +--
.../android/AndroidFunctionTest.java | 4 +-
.../android/AndroidSearchingTest.java | 4 +-
.../java_client/android/AndroidTouchTest.java | 40 ++-----
.../java_client/android/IntentTest.java | 8 +-
.../java_client/android/UIAutomator2Test.java | 4 +-
.../java_client/appium/AndroidTest.java | 8 +-
.../widgets/AndroidOverrideWidgetTest.java | 5 +-
.../widgets/android/AndroidWidgetTest.java | 5 +-
.../combined/AndroidCombinedWidgetTest.java | 5 +-
15 files changed, 143 insertions(+), 93 deletions(-)
diff --git a/src/main/java/io/appium/java_client/android/Activity.java b/src/main/java/io/appium/java_client/android/Activity.java
index fe460d15b..38fb912cb 100644
--- a/src/main/java/io/appium/java_client/android/Activity.java
+++ b/src/main/java/io/appium/java_client/android/Activity.java
@@ -14,7 +14,9 @@ public class Activity {
private String optionalIntentArguments;
private boolean stopApp;
- public Activity() {
+ public Activity(String appPackage, String appActivity) {
+ this.appPackage = appPackage;
+ this.appActivity = appActivity;
this.stopApp = true;
}
diff --git a/src/main/java/io/appium/java_client/android/StartsActivity.java b/src/main/java/io/appium/java_client/android/StartsActivity.java
index 4f29b7b8e..26be67b45 100644
--- a/src/main/java/io/appium/java_client/android/StartsActivity.java
+++ b/src/main/java/io/appium/java_client/android/StartsActivity.java
@@ -48,6 +48,108 @@ default void startActivity(Activity activity) {
activity.getOptionalIntentArguments(), activity.isStopApp()));
}
+ /**
+ * This method should start arbitrary activity during a test. If the activity belongs to
+ * another application, that application is started and the activity is opened.
+ *
+ * @param appPackage The package containing the activity. [Required]
+ * @param appActivity The activity to start. [Required]
+ * @param appWaitPackage Automation will begin after this package starts. [Optional]
+ * @param appWaitActivity Automation will begin after this activity starts. [Optional]
+ * @param stopApp If true, target app will be stopped. [Optional]
+ * @deprecated Instead use {@link #startActivity(Activity)}
+ */
+ @Deprecated
+ default void startActivity(String appPackage, String appActivity, String appWaitPackage,
+ String appWaitActivity, boolean stopApp) throws IllegalArgumentException {
+ this.startActivity(appPackage,appActivity,appWaitPackage,
+ appWaitActivity,null,null,null,null,stopApp);
+ }
+
+ /**
+ * This method should start arbitrary activity during a test. If the activity belongs to
+ * another application, that application is started and the activity is opened.
+ *
+ * @param appPackage The package containing the activity. [Required]
+ * @param appActivity The activity to start. [Required]
+ * @param appWaitPackage Automation will begin after this package starts. [Optional]
+ * @param appWaitActivity Automation will begin after this activity starts. [Optional]
+ * @deprecated Instead use {@link #startActivity(Activity)}
+ */
+ @Deprecated
+ default void startActivity(String appPackage, String appActivity, String appWaitPackage,
+ String appWaitActivity) throws IllegalArgumentException {
+ this.startActivity(appPackage, appActivity,
+ appWaitPackage, appWaitActivity,null,null,null,null,true);
+ }
+
+ /**
+ * This method should start arbitrary activity during a test. If the activity belongs to
+ * another application, that application is started and the activity is opened.
+ *
+ * @param appPackage The package containing the activity. [Required]
+ * @param appActivity The activity to start. [Required]
+ * @deprecated Instead use {@link #startActivity(Activity)}
+ */
+ @Deprecated
+ default void startActivity(String appPackage, String appActivity) throws IllegalArgumentException {
+ this.startActivity(appPackage, appActivity, null, null,
+ null,null,null,null,true);
+ }
+
+ /**
+ * This method should start arbitrary activity during a test. If the activity belongs to
+ * another application, that application is started and the activity is opened.
+ *
+ * @param appPackage The package containing the activity. [Required]
+ * @param appActivity The activity to start. [Required]
+ * @param appWaitPackage Automation will begin after this package starts. [Optional]
+ * @param appWaitActivity Automation will begin after this activity starts. [Optional]
+ * @param intentAction Intent action which will be used to start activity [Optional]
+ * @param intentCategory Intent category which will be used to start activity [Optional]
+ * @param intentFlags Flags that will be used to start activity [Optional]
+ * @param intentOptionalArgs Additional intent arguments that will be used to
+ * start activity [Optional]
+ * @deprecated Instead use {@link #startActivity(Activity)}
+ */
+ @Deprecated
+ default void startActivity(String appPackage, String appActivity,
+ String appWaitPackage, String appWaitActivity,
+ String intentAction, String intentCategory,
+ String intentFlags, String intentOptionalArgs)
+ throws IllegalArgumentException {
+ this.startActivity(appPackage,appActivity,
+ appWaitPackage,appWaitActivity,
+ intentAction,intentCategory,intentFlags,intentOptionalArgs,true);
+ }
+
+ /**
+ * This method should start arbitrary activity during a test. If the activity belongs to
+ * another application, that application is started and the activity is opened.
+ *
+ * @param appPackage The package containing the activity. [Required]
+ * @param appActivity The activity to start. [Required]
+ * @param appWaitPackage Automation will begin after this package starts. [Optional]
+ * @param appWaitActivity Automation will begin after this activity starts. [Optional]
+ * @param intentAction Intent action which will be used to start activity [Optional]
+ * @param intentCategory Intent category which will be used to start activity [Optional]
+ * @param intentFlags Flags that will be used to start activity [Optional]
+ * @param optionalIntentArguments Additional intent arguments that will be used to
+ * start activity [Optional]
+ * @param stopApp If true, target app will be stopped. [Optional]
+ * @deprecated Instead use {@link #startActivity(Activity)}
+ */
+ @Deprecated
+ default void startActivity(String appPackage, String appActivity, String appWaitPackage,
+ String appWaitActivity, String intentAction,
+ String intentCategory, String intentFlags,
+ String optionalIntentArguments,boolean stopApp )
+ throws IllegalArgumentException {
+ CommandExecutionHelper.execute(this, startActivityCommand(appPackage, appActivity,
+ appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags,
+ optionalIntentArguments, stopApp));
+ }
+
/**
* Get the current activity being run on the mobile device.
*
diff --git a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java b/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java
index e6671acb1..b0b2409d5 100644
--- a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java
@@ -1,5 +1,7 @@
package io.appium.java_client.android;
+import static org.junit.Assert.assertNotEquals;
+
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.functions.ActionSupplier;
@@ -8,8 +10,6 @@
import java.util.List;
-import static org.junit.Assert.assertNotEquals;
-
public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
private final ActionSupplier horizontalSwipe = () -> {
@@ -30,9 +30,7 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
.waitAction(2000).moveTo(driver.findElementByAccessibilityId("Auto Complete")).release();
@Test public void horizontalSwipingWithSupplier() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.Gallery1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.Gallery1");
driver.startActivity(activity);
AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery");
List images = gallery
diff --git a/src/test/java/io/appium/java_client/android/AndroidActivityTest.java b/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
index b598f32b8..82cc6684a 100644
--- a/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
@@ -24,25 +24,21 @@
public class AndroidActivityTest extends BaseAndroidTest {
@Before public void setUp() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".ApiDemos");
+ Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
driver.startActivity(activity);
}
@Test public void startActivityInThisAppTestCase() {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".accessibility.AccessibilityNodeProviderActivity");
+ Activity activity = new Activity("io.appium.android.apis",
+ ".accessibility.AccessibilityNodeProviderActivity");
driver.startActivity(activity);
assertEquals(driver.currentActivity(),
".accessibility.AccessibilityNodeProviderActivity");
}
@Test public void startActivityWithWaitingAppTestCase() {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".accessibility.AccessibilityNodeProviderActivity");
+ final Activity activity = new Activity("io.appium.android.apis",
+ ".accessibility.AccessibilityNodeProviderActivity");
activity.setAppWaitPackage("io.appium.android.apis");
activity.setAppWaitActivity(".accessibility.AccessibilityNodeProviderActivity");
driver.startActivity(activity);
@@ -51,9 +47,7 @@ public class AndroidActivityTest extends BaseAndroidTest {
}
@Test public void startActivityInNewAppTestCase() {
- Activity activity = new Activity();
- activity.setAppPackage("com.android.contacts");
- activity.setAppActivity(".ContactsListActivity");
+ Activity activity = new Activity("com.android.contacts", ".ContactsListActivity");
driver.startActivity(activity);
assertEquals(driver.currentActivity(), ".ContactsListActivity");
driver.pressKeyCode(AndroidKeyCode.BACK);
@@ -61,9 +55,8 @@ public class AndroidActivityTest extends BaseAndroidTest {
}
@Test public void startActivityInNewAppTestCaseWithoutClosingApp() {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".accessibility.AccessibilityNodeProviderActivity");
+ final Activity activity = new Activity("io.appium.android.apis",
+ ".accessibility.AccessibilityNodeProviderActivity");
driver.startActivity(activity);
assertEquals(driver.currentActivity(), ".accessibility.AccessibilityNodeProviderActivity");
diff --git a/src/test/java/io/appium/java_client/android/AndroidContextTest.java b/src/test/java/io/appium/java_client/android/AndroidContextTest.java
index 3b880b13a..1ee5280b7 100644
--- a/src/test/java/io/appium/java_client/android/AndroidContextTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidContextTest.java
@@ -26,9 +26,7 @@
public class AndroidContextTest extends BaseAndroidTest {
@BeforeClass public static void beforeClass2() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.WebView1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.WebView1");
driver.startActivity(activity);
Thread.sleep(20000);
}
diff --git a/src/test/java/io/appium/java_client/android/AndroidElementTest.java b/src/test/java/io/appium/java_client/android/AndroidElementTest.java
index 7cab358cd..32cd82d57 100644
--- a/src/test/java/io/appium/java_client/android/AndroidElementTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidElementTest.java
@@ -29,9 +29,7 @@
public class AndroidElementTest extends BaseAndroidTest {
@Before public void setup() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".ApiDemos");
+ Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
driver.startActivity(activity);
}
@@ -58,9 +56,7 @@ public class AndroidElementTest extends BaseAndroidTest {
@Test public void replaceValueTest() {
String originalValue = "original value";
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.Controls1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.Controls1");
driver.startActivity(activity);
AndroidElement editElement = driver
.findElementByAndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")");
@@ -84,9 +80,7 @@ public class AndroidElementTest extends BaseAndroidTest {
@Test public void setValueTest() {
String value = "new value";
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.Controls1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.Controls1");
driver.startActivity(activity);
AndroidElement editElement = driver
.findElementByAndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")");
diff --git a/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java b/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java
index 7828c212b..ab3b5e84f 100644
--- a/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java
@@ -66,9 +66,7 @@ public class AndroidFunctionTest extends BaseAndroidTest {
@BeforeClass public static void startWebViewActivity() throws Exception {
if (driver != null) {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.WebView1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.WebView1");
driver.startActivity(activity);
}
}
diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java
index 7a8207bbe..3b0ef3eb2 100644
--- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java
@@ -30,9 +30,7 @@ public class AndroidSearchingTest extends BaseAndroidTest {
@Before
public void setup() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".ApiDemos");
+ Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
driver.startActivity(activity);
}
diff --git a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java b/src/test/java/io/appium/java_client/android/AndroidTouchTest.java
index cce801ace..305c7936a 100644
--- a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidTouchTest.java
@@ -22,9 +22,7 @@ public void setUp() throws Exception {
}
@Test public void dragNDropByElementTest() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.DragAndDropDemo");
+ Activity activity = new Activity("io.appium.android.apis", ".view.DragAndDropDemo");
driver.startActivity(activity);
WebElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
WebElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
@@ -39,9 +37,7 @@ public void setUp() throws Exception {
}
@Test public void dragNDropByElementAndDurationTest() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.DragAndDropDemo");
+ Activity activity = new Activity("io.appium.android.apis", ".view.DragAndDropDemo");
driver.startActivity(activity);
WebElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
WebElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
@@ -56,9 +52,7 @@ public void setUp() throws Exception {
}
@Test public void dragNDropByCoordinatesTest() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.DragAndDropDemo");
+ Activity activity = new Activity("io.appium.android.apis", ".view.DragAndDropDemo");
driver.startActivity(activity);
AndroidElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
AndroidElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
@@ -76,9 +70,7 @@ public void setUp() throws Exception {
}
@Test public void dragNDropByCoordinatesAndDurationTest() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.DragAndDropDemo");
+ Activity activity = new Activity("io.appium.android.apis", ".view.DragAndDropDemo");
driver.startActivity(activity);
AndroidElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
AndroidElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
@@ -96,9 +88,7 @@ public void setUp() throws Exception {
}
@Test public void pressByCoordinatesTest() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.Buttons1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.Buttons1");
driver.startActivity(activity);
Point point =
driver.findElementById("io.appium.android.apis:id/button_toggle").getLocation();
@@ -108,9 +98,7 @@ public void setUp() throws Exception {
}
@Test public void pressByElementTest() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.Buttons1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.Buttons1");
driver.startActivity(activity);
new TouchAction(driver).press(driver.findElementById("io.appium.android.apis:id/button_toggle"))
.waitAction(1000).release().perform();
@@ -119,9 +107,7 @@ public void setUp() throws Exception {
}
@Test public void tapActionTestByElement() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.ChronometerDemo");
+ Activity activity = new Activity("io.appium.android.apis", ".view.ChronometerDemo");
driver.startActivity(activity);
AndroidElement chronometer =
driver.findElementById("io.appium.android.apis:id/chronometer");
@@ -139,9 +125,7 @@ public void setUp() throws Exception {
}
@Test public void tapActionTestByCoordinates() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.ChronometerDemo");
+ Activity activity = new Activity("io.appium.android.apis", ".view.ChronometerDemo");
driver.startActivity(activity);
AndroidElement chronometer =
driver.findElementById("io.appium.android.apis:id/chronometer");
@@ -160,9 +144,7 @@ public void setUp() throws Exception {
}
@Test public void horizontalSwipingTest() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.Gallery1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.Gallery1");
driver.startActivity(activity);
AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery");
@@ -180,9 +162,7 @@ public void setUp() throws Exception {
}
@Test public void multiTouchTest() throws Exception {
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.Buttons1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.Buttons1");
driver.startActivity(activity);
TouchAction press = new TouchAction(driver);
press.press(driver.findElementById("io.appium.android.apis:id/button_toggle")).waitAction(1000).release();
diff --git a/src/test/java/io/appium/java_client/android/IntentTest.java b/src/test/java/io/appium/java_client/android/IntentTest.java
index b95134ee3..cc1be0f16 100644
--- a/src/test/java/io/appium/java_client/android/IntentTest.java
+++ b/src/test/java/io/appium/java_client/android/IntentTest.java
@@ -48,9 +48,7 @@ public class IntentTest {
@Test public void startActivityWithIntent() {
- Activity activity = new Activity();
- activity.setAppPackage("com.android.mms");
- activity.setAppActivity(".ui.ComposeMessageActivity");
+ final Activity activity = new Activity("com.android.mms", ".ui.ComposeMessageActivity");
activity.setIntentAction("android.intent.action.SEND");
activity.setIntentCategory("android.intent.category.DEFAULT");
activity.setIntentFlags("0x4000000");
@@ -64,9 +62,7 @@ public class IntentTest {
}
@Test public void startActivityWithDefaultIntentAndDefaultCategoryWithOptionalArgs() {
- Activity activity = new Activity();
- activity.setAppPackage("com.prgguru.android");
- activity.setAppActivity(".GreetingActivity");
+ final Activity activity = new Activity("com.prgguru.android", ".GreetingActivity");
activity.setIntentAction("android.intent.action.MAIN");
activity.setIntentCategory("android.intent.category.DEFAULT");
activity.setIntentFlags("0x4000000");
diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java
index 6c8cae205..de480866e 100644
--- a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java
+++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java
@@ -85,9 +85,7 @@ public class UIAutomator2Test {
@Test public void testToastMSGIsDisplayed() throws InterruptedException {
final WebDriverWait wait = new WebDriverWait(driver, 10);
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.PopupMenu1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.PopupMenu1");
driver.startActivity(activity);
MobileElement popUpElement = driver.findElement(MobileBy.AccessibilityId("Make a Popup!"));
diff --git a/src/test/java/io/appium/java_client/appium/AndroidTest.java b/src/test/java/io/appium/java_client/appium/AndroidTest.java
index b9f6e924b..b73645df4 100644
--- a/src/test/java/io/appium/java_client/appium/AndroidTest.java
+++ b/src/test/java/io/appium/java_client/appium/AndroidTest.java
@@ -79,9 +79,7 @@ public Response execute(String driverCommand) {
return driver.execute(driverCommand);
}
};
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".ApiDemos");
+ Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
startsActivity.startActivity(activity);
}
@@ -125,9 +123,7 @@ public void findByAccessibilityIdFromDriverTest() {
@Test public void replaceValueTest() {
String originalValue = "original value";
- Activity activity = new Activity();
- activity.setAppPackage("io.appium.android.apis");
- activity.setAppActivity(".view.Controls1");
+ Activity activity = new Activity("io.appium.android.apis", ".view.Controls1");
startsActivity.startActivity(activity);
AndroidElement editElement = driver
.findElement(MobileBy
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java
index fc237e875..8ac3f6f80 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java
@@ -71,9 +71,8 @@ public static void afterClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null) {
- Activity activity = new Activity();
- activity.setAppPackage("com.codepath.example.rottentomatoes");
- activity.setAppActivity("BoxOfficeActivity");
+ Activity activity = new Activity("com.codepath.example.rottentomatoes",
+ "BoxOfficeActivity");
driver.startActivity(activity);
}
}
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java
index 1231cfea7..d728fba11 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java
@@ -71,9 +71,8 @@ public static void afterClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null) {
- Activity activity = new Activity();
- activity.setAppPackage("com.codepath.example.rottentomatoes");
- activity.setAppActivity("BoxOfficeActivity");
+ Activity activity = new Activity("com.codepath.example.rottentomatoes",
+ "BoxOfficeActivity");
driver.startActivity(activity);
}
}
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java
index 9aba24e60..d547ce82d 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java
@@ -71,9 +71,8 @@ public static void afterClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null) {
- Activity activity = new Activity();
- activity.setAppPackage("com.codepath.example.rottentomatoes");
- activity.setAppActivity("BoxOfficeActivity");
+ Activity activity = new Activity("com.codepath.example.rottentomatoes",
+ "BoxOfficeActivity");
driver.startActivity(activity);
}
}
From bf96700ac7dd2436652578b2b3a1022963543141 Mon Sep 17 00:00:00 2001
From: VimalRaj Selvam
Date: Thu, 23 Feb 2017 07:50:45 +0530
Subject: [PATCH 3/5] Added javadoc for the constructor.
---
src/main/java/io/appium/java_client/android/Activity.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/main/java/io/appium/java_client/android/Activity.java b/src/main/java/io/appium/java_client/android/Activity.java
index 38fb912cb..edc37a110 100644
--- a/src/main/java/io/appium/java_client/android/Activity.java
+++ b/src/main/java/io/appium/java_client/android/Activity.java
@@ -14,6 +14,12 @@ public class Activity {
private String optionalIntentArguments;
private boolean stopApp;
+ /**
+ * A constructor with two mandatory parameters.
+ *
+ * @param appPackage The value for the app package.
+ * @param appActivity The value for the app activity.
+ */
public Activity(String appPackage, String appActivity) {
this.appPackage = appPackage;
this.appActivity = appActivity;
From 869dcde6e26c9af6e21320774b2778fa05ea792f Mon Sep 17 00:00:00 2001
From: VimalRaj Selvam
Date: Fri, 24 Feb 2017 23:37:14 +0530
Subject: [PATCH 4/5] Fixed usage instructions
---
docs/The-starting-of-an-Android-app.md | 8 ++++----
.../io/appium/java_client/android/StartsActivity.java | 6 +++---
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/docs/The-starting-of-an-Android-app.md b/docs/The-starting-of-an-Android-app.md
index ea88cd90d..bca62fc55 100644
--- a/docs/The-starting-of-an-Android-app.md
+++ b/docs/The-starting-of-an-Android-app.md
@@ -119,9 +119,9 @@ StartsActivity startsActivity = new StartsActivity() {
}
};
-Activity activity = new Activity();
-activity.setAppPackage("your.package.name");
-activity.setAppActivity(".ActivityName");
+Activity activity = new Activity("app package goes here", "app activity goes here");
+activity.setWaitAppPackage("app wait package goes here");
+activity.setWaitAppActivity("app wait activity goes here");
StartsActivity startsActivity.startActivity(activity);
```
@@ -153,4 +153,4 @@ findsByAndroidUIAutomator.findElementByAndroidUIAutomator("automatorString");
driver.findElement(MobileBy.AndroidUIAutomator("automatorString"));
```
-All that ```AndroidDriver``` can do by design.
\ No newline at end of file
+All that ```AndroidDriver``` can do by design.
diff --git a/src/main/java/io/appium/java_client/android/StartsActivity.java b/src/main/java/io/appium/java_client/android/StartsActivity.java
index 26be67b45..05b31603c 100644
--- a/src/main/java/io/appium/java_client/android/StartsActivity.java
+++ b/src/main/java/io/appium/java_client/android/StartsActivity.java
@@ -31,9 +31,9 @@ public interface StartsActivity extends ExecutesMethod {
*
*
* {@code
- * Activity activity = new Activity();
- * activity.setAppPackage("com.foo");
- * activity.setAppActivity(".bar");
+ * Activity activity = new Activity("app package goes here", "app activity goes here");
+ * activity.setWaitAppPackage("app wait package goes here");
+ * activity.setWaitAppActivity("app wait activity goes here");
* driver.startActivity(activity);
* }
*
From 42c64d55a69cb79297f6052a3634df5c81084ddd Mon Sep 17 00:00:00 2001
From: VimalRaj Selvam
Date: Sat, 25 Feb 2017 19:46:47 +0530
Subject: [PATCH 5/5] Added a check to prevent Activity parameters not empty
and not null. Also made the mandatory parameters final and removed setters.
---
.../appium/java_client/android/Activity.java | 31 ++++++-------------
.../android/AndroidActivityTest.java | 13 ++++----
2 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/src/main/java/io/appium/java_client/android/Activity.java b/src/main/java/io/appium/java_client/android/Activity.java
index edc37a110..ba7236424 100644
--- a/src/main/java/io/appium/java_client/android/Activity.java
+++ b/src/main/java/io/appium/java_client/android/Activity.java
@@ -1,11 +1,14 @@
package io.appium.java_client.android;
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.commons.lang3.StringUtils.isBlank;
+
/**
* This is a simple POJO class to support the {@link StartsActivity}.
*/
public class Activity {
- private String appPackage;
- private String appActivity;
+ private final String appPackage;
+ private final String appActivity;
private String appWaitPackage;
private String appWaitActivity;
private String intentAction;
@@ -17,10 +20,14 @@ public class Activity {
/**
* A constructor with two mandatory parameters.
*
- * @param appPackage The value for the app package.
+ * @param appPackage The value for the app package.
* @param appActivity The value for the app activity.
*/
public Activity(String appPackage, String appActivity) {
+ checkArgument(!isBlank(appPackage),
+ "App package should be defined as not empty or null string");
+ checkArgument(!isBlank(appActivity),
+ "App activity should be defined as not empty or null string");
this.appPackage = appPackage;
this.appActivity = appActivity;
this.stopApp = true;
@@ -35,15 +42,6 @@ public String getAppPackage() {
return appPackage;
}
- /**
- * Sets the app package value.
- *
- * @param appPackage The app package value.
- */
- public void setAppPackage(String appPackage) {
- this.appPackage = appPackage;
- }
-
/**
* Gets the app activity value.
*
@@ -53,15 +51,6 @@ public String getAppActivity() {
return appActivity;
}
- /**
- * Sets the app activity value.
- *
- * @param appActivity The app activity value.
- */
- public void setAppActivity(String appActivity) {
- this.appActivity = appActivity;
- }
-
/**
* Gets the app wait package value.
*
diff --git a/src/test/java/io/appium/java_client/android/AndroidActivityTest.java b/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
index 82cc6684a..706b282f0 100644
--- a/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidActivityTest.java
@@ -55,17 +55,16 @@ public class AndroidActivityTest extends BaseAndroidTest {
}
@Test public void startActivityInNewAppTestCaseWithoutClosingApp() {
- final Activity activity = new Activity("io.appium.android.apis",
+ Activity activity = new Activity("io.appium.android.apis",
".accessibility.AccessibilityNodeProviderActivity");
driver.startActivity(activity);
assertEquals(driver.currentActivity(), ".accessibility.AccessibilityNodeProviderActivity");
- activity.setAppPackage("com.android.contacts");
- activity.setAppActivity(".ContactsListActivity");
- activity.setAppWaitPackage("com.android.contacts");
- activity.setAppWaitActivity(".ContactsListActivity");
- activity.setStopApp(false);
- driver.startActivity(activity);
+ Activity newActivity = new Activity("com.android.contacts", ".ContactsListActivity");
+ newActivity.setAppWaitPackage("com.android.contacts");
+ newActivity.setAppWaitActivity(".ContactsListActivity");
+ newActivity.setStopApp(false);
+ driver.startActivity(newActivity);
assertEquals(driver.currentActivity(), ".ContactsListActivity");
driver.pressKeyCode(AndroidKeyCode.BACK);
assertEquals(driver.currentActivity(), ".accessibility.AccessibilityNodeProviderActivity");