Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/The-starting-of-an-Android-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ use Android-specific API eventually.

```java
import io.appium.java_client.android.StartsActivity;
import io.appium.java_client.android.Activity;

...

Expand All @@ -118,7 +119,10 @@ StartsActivity startsActivity = new StartsActivity() {
}
};

StartsActivity startsActivity.startActivity("your.package.name", ".ActivityName");
Activity activity = new Activity();
activity.setAppPackage("your.package.name");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@email2vimalraj Can you update here too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activity.setAppActivity(".ActivityName");
StartsActivity startsActivity.startActivity(activity);
```

_Samples of the searching by AndroidUIAutomator using_ ```io.appium.java_client.AppiumDriver```
Expand Down
191 changes: 191 additions & 0 deletions src/main/java/io/appium/java_client/android/Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package io.appium.java_client.android;

/**
* This is a simple POJO class to support the {@link StartsActivity}.
*/
public class Activity {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this this POJO should have 2 mandatory parameteres: package and activity. Please add the constructor with these parameters.

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) {
Copy link
Member

@SrinivasanTarget SrinivasanTarget Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea behind this but have few things to be discussed here,

Is there a way to remove getters & setters? May be we need to come up with either custom annotation or something like https://github.com/rzwitserloot/lombok. May be not necessarily in this PR but subjective to discussion if there is any scope of improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the user review who was using the lombok for more than a year: http://stackoverflow.com/a/12807937/1505987

I would recommend to stay away from lombok, even though I never used it personally. My justification would be obviously a javadoc and everytime we will have to generate the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't recommend lombock. But i liked their way of using annotations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it is necessary to keep this method. Maybe it is more senseful to keep only getter for package and make this field final. @SrinivasanTarget What is your opinion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 - Making this final would be a better option 👍

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it is necessary to keep this method. Maybe it is more senseful to keep only getter for activity and make this field final. @SrinivasanTarget What is your opinion?

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 + '}';
}
}
103 changes: 18 additions & 85 deletions src/main/java/io/appium/java_client/android/StartsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* Usage:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@email2vimalraj I'm against this change as it is. Please mark these methods Deprecated and with the description to use new ones

* </p>
* <pre>
* {@code
* Activity activity = new Activity();
* activity.setAppPackage("com.foo");
* activity.setAppActivity(".bar");
* driver.startActivity(activity);
* }
* </pre>
*
* @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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +8,8 @@

import java.util.List;

import static org.junit.Assert.assertNotEquals;

public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {

private final ActionSupplier<TouchAction> horizontalSwipe = () -> {
Expand All @@ -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<MobileElement> images = gallery
.findElementsByClassName("android.widget.ImageView");
Expand Down
Loading