Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiaocong master #57

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 8 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Purpose
[![Build Status](https://travis-ci.org/openatx/android-uiautomator-server.svg?branch=master)](https://travis-ci.org/openatx/android-uiautomator-server)

[UIAutomator](http://developer.android.com/tools/testing/testing_ui.html) is a
great tool to perform Android UI testing, but to do it, you have to write java
Expand Down Expand Up @@ -83,52 +82,18 @@ $ adb shell am broadcast -a ADB_GET_CLIPBOARD
Broadcasting: Intent { act=ADB_GET_CLIPBOARD flg=0x400000 }
Broadcast completed: result=0

# Get clipboard (with data, base64 encoded)
$ adb shell am broadcast -a ADB_GET_CLIPBOARD
Broadcasting: Intent { act=ADB_GET_CLIPBOARD flg=0x400000 }
Broadcast completed: result=-1, data="5LqG6Kej5Lyg57uf5paH5YyW"
```

- [Editor Code](https://developer.android.com/reference/android/view/inputmethod/EditorInfo)
- [Key Event](https://developer.android.com/reference/android/view/KeyEvent)

# Change GPS mock location
You can change mock location from terminal using adb in order to test GPS on real devices.

```
adb [-s <specific device>] shell am broadcast -a send.mock [-e lat <latitude>] [-e lon <longitude>]
[-e alt <altitude>] [-e accurate <accurate>]
```

For example:

```
adb shell am broadcast -a send.mock -e lat 15.3 -e lon 99
```

## Show toast

```
adb shell am start -n com.github.uiautomator/.ToastActivity -e message hello
```

## Float window

```
adb shell am start -n com.github.uiautomator/.ToastActivity -e showFloatWindow true # show
adb shell am start -n com.github.uiautomator/.ToastActivity -e showFloatWindow false # hide
```

# How to use with Python
# How to use

```python
import uiautomator2 as u2

d = u2.connect()
from uiautomator import device as d

d.info
d.screen.on()
d(text="Settings").click()
d(scrollable=True).scroll.vert.forward()
d().gestureM((100,200),(100,300),(100,400)).to((100,400),(100,400),(100,400),100)

```

Refer to python wrapper library [uiautomator](https://github.com/xiaocong/uiautomator).
Expand All @@ -143,6 +108,7 @@ conventional-changelog -p grunt -i CHANGELOG.md -s -r 0

# Notes

If you have any idea, please email [email protected], [email protected] or [submit tickets](https://github.com/xiaocong/uiautomator/issues/new).
If you have any idea, please email [email protected] or [submit tickets](https://github.com/openatx/android-uiautomator-server/issues/new).

# Dependencies
Expand Down Expand Up @@ -171,3 +137,5 @@ Clipboard, Thanks to @fplust
- https://github.com/willerce/WhatsInput
- https://github.com/senzhk/ADBKeyBoard
- https://github.com/amotzte/android-mock-location-for-development
# TODO
- android O support
115 changes: 74 additions & 41 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

// version code history
// 1: original version
// 2: update all dependencies to latest
// 6: input method, battery,rotation monitor

defaultConfig {
applicationId "com.github.uiautomator"
minSdkVersion 18
Expand All @@ -65,54 +60,92 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}

debug {
minifyEnabled false
signingConfig signingConfigs.release
}
}


android {
lintOptions {
abortOnError false
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
//test.java.srcDirs += 'src/test/kotlin'
//androidTest.java.srcDirs += 'src/androidTest'
}

defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}

// fix try-with-resource warning
// ref: https://stackoverflow.com/questions/40408628/try-with-resources-requires-api-level-19-okhttp
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// server
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'org.nanohttpd:nanohttpd:2.3.1'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'commons-cli:commons-cli:1.3.1'

// test
androidTestImplementation 'androidx.test:runner:1.3.0'

androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.core:core:1.3.0'
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
androidTestImplementation 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.0'

implementation project(':permission')
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.60"
// server
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'org.nanohttpd:nanohttpd:2.3.1'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'commons-cli:commons-cli:1.3.1'
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.1'

// test
androidTestImplementation 'androidx.test:runner:1.3.0'

androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.core:core:1.3.0'
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
androidTestImplementation 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.0'

implementation project(':permission')
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
androidTestImplementation 'com.android.support:support-v4:28.0.0'
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
androidTestImplementation 'com.nanohttpd:nanohttpd:2.1.1'
androidTestImplementation 'com.fasterxml.jackson.core:jackson-core:2.5.3'
androidTestImplementation 'com.fasterxml.jackson.core:jackson-annotations:2.5.3'
androidTestImplementation 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
androidTestImplementation 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.1'
androidTestImplementation 'javax.servlet:servlet-api:2.5'
androidTestImplementation 'javax.portlet:portlet-api:2.0'

// fix try-with-resource warning
// ref: https://stackoverflow.com/questions/40408628/try-with-resources-requires-api-level-19-okhttp
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

buildscript {
repositories {
mavenCentral()
}
}

repositories {
mavenCentral()
}
repositories {
mavenCentral()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@
package com.github.uiautomator.stub;

import android.os.RemoteException;

import androidx.test.uiautomator.UiObjectNotFoundException;

import com.github.uiautomator.stub.exceptions.NotImplementedException;
import com.github.uiautomator.stub.exceptions.UiAutomator2Exception;
import com.googlecode.jsonrpc4j.JsonRpcError;
import com.googlecode.jsonrpc4j.JsonRpcErrors;

import java.util.List;

public interface AutomatorService {
final static int ERROR_CODE_BASE = -32000;

Expand Down Expand Up @@ -167,6 +172,7 @@ public interface AutomatorService {
* @return the absolute path name of dumped file.
*/
@Deprecated
@JsonRpcErrors({@JsonRpcError(exception=UiAutomator2Exception.class, code=ERROR_CODE_BASE)})
String dumpWindowHierarchy(boolean compressed, String filename);

/**
Expand All @@ -175,6 +181,7 @@ public interface AutomatorService {
* @param compressed use compressed layout hierarchy or not using setCompressedLayoutHeirarchy method. Ignore the parameter in case the API level lt 18.
* @return the absolute path name of dumped file.
*/
@JsonRpcErrors({@JsonRpcError(exception=UiAutomator2Exception.class, code=ERROR_CODE_BASE)})
String dumpWindowHierarchy(boolean compressed);

/**
Expand Down Expand Up @@ -541,6 +548,22 @@ public interface AutomatorService {
@JsonRpcErrors({@JsonRpcError(exception = UiObjectNotFoundException.class, code = ERROR_CODE_BASE - 2), @JsonRpcError(exception = NotImplementedException.class, code = ERROR_CODE_BASE - 3)})
boolean gesture(Selector obj, Point startPoint1, Point startPoint2, Point endPoint1, Point endPoint2, int steps) throws UiObjectNotFoundException, NotImplementedException;

//FOR 3
/**
* Generates a 3-pointer gesture with arbitrary starting and ending points.
* @param obj the target ui object. ??
* @param startPoint1 start point of pointer 1
* @param startPoint2 start point of pointer 2
* @param startPoint3 start point of pointer 3
* @param endPoint1 end point of pointer 1
* @param endPoint2 end point of pointer 2
* @param endPoint3 end point of pointer 3
* @param steps the number of steps for the gesture. Steps are injected about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete.
* @return true if all touch events for this gesture are injected successfully, false otherwise
* @throws UiObjectNotFoundException
*/
@JsonRpcErrors({@JsonRpcError(exception=UiObjectNotFoundException.class, code=ERROR_CODE_BASE-2), @JsonRpcError(exception=NotImplementedException.class, code=ERROR_CODE_BASE-3)})
boolean gesture(Selector obj, Point startPoint1, Point startPoint2, Point startPoint3, Point endPoint1, Point endPoint2, Point endPoint3, int steps) throws UiObjectNotFoundException, NotImplementedException;
/**
* Performs a two-pointer gesture, where each pointer moves diagonally toward the other, from the edges to the center of this UiObject .
*
Expand Down Expand Up @@ -1049,4 +1072,20 @@ public interface AutomatorService {
* @return Clipboard data or null
*/
String getClipboard();

/**
* Set Configurator.
* @param obj the configurator information to be set.
* @throws NotImplementedException
*/
@JsonRpcErrors({@JsonRpcError(exception=NotImplementedException.class, code=ERROR_CODE_BASE-3)})
List<ObjInfo> finds(Selector obj) throws NotImplementedException;

/**
* toast.
* @param switchStatus the toast information to be get and stop.
* @throws NotImplementedException
*/
@JsonRpcErrors({@JsonRpcError(exception=NotImplementedException.class, code=ERROR_CODE_BASE)})
String toast(String switchStatus) throws NotImplementedException;
}
Loading