Skip to content

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaocong committed Feb 19, 2014
1 parent 59ffbf5 commit d2a5577
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 1,407 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "nanohttpd"]
path = nanohttpd
url = https://github.com/NanoHttpd/nanohttpd.git
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ that we can just write PC side script to write UIAutomator tests.
- Install Ant if you have not.
- Run command:


$ ant build # compile
$ ant install # install jar file to device via adb
$ git submodule init
$ git submodule update
$ ant build # compile
$ ant install # install jar file to device via adb

# Run the jsonrcp server on Android device

$ adb shell uiautomator runtest uiautomator-stub.jar bundle.jar -c com.github.uiautomatorstub.Stub
$ adb forward tcp:9008 tcp:9008 # tcp forward
$ adb shell uiautomator runtest uiautomator-stub.jar bundle.jar -c com.github.uiautomatorstub.Stub
$ adb forward tcp:9008 tcp:9008 # tcp forward

# How to use

Expand Down
1 change: 1 addition & 0 deletions ant.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source.dir=src;nanohttpd/core/src/main/java
1 change: 1 addition & 0 deletions nanohttpd
Submodule nanohttpd added at 852318
16 changes: 16 additions & 0 deletions src/com/github/uiautomatorstub/AutomatorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,4 +805,20 @@ public interface AutomatorService {
*/
@JsonRpcErrors({@JsonRpcError(exception=UiObjectNotFoundException.class, code=ERROR_CODE_BASE-2)})
boolean waitUntilGone (String obj, long timeout) throws UiObjectNotFoundException;

/**
* Get Configurator
* @return Configurator information.
* @throws NotImplementedException
*/
@JsonRpcErrors({@JsonRpcError(exception=NotImplementedException.class, code=ERROR_CODE_BASE-3)})
ConfiguratorInfo getConfigurator() throws NotImplementedException;

/**
* Set Configurator.
* @param info the configurator information to be set.
* @throws NotImplementedException
*/
@JsonRpcErrors({@JsonRpcError(exception=NotImplementedException.class, code=ERROR_CODE_BASE-3)})
ConfiguratorInfo setConfigurator(ConfiguratorInfo info) throws NotImplementedException;
}
31 changes: 30 additions & 1 deletion src/com/github/uiautomatorstub/AutomatorServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void setAsVerticalList(UiScrollable obj) {
*/
@Override
public String ping() {
new UiObject(new UiSelector()).exists(); // here we call the method just for checking if the UiAutomationService is ok, else it will throw IllegalStateException.
//new UiObject(new UiSelector()).exists(); // here we call the method just for checking if the UiAutomationService is ok, else it will throw IllegalStateException.
return "pong";
}

Expand Down Expand Up @@ -1530,4 +1530,33 @@ public boolean waitForExists(String obj, long timeout) throws UiObjectNotFoundEx
public boolean waitUntilGone(String obj, long timeout) throws UiObjectNotFoundException {
return getUiObject(obj).waitUntilGone(timeout);
}

/**
* Get Configurator
*
* @return Configurator information.
* @throws com.github.uiautomatorstub.NotImplementedException
*/
@Override
public ConfiguratorInfo getConfigurator() throws NotImplementedException {
if (Build.VERSION.SDK_INT < 18)
throw new NotImplementedException();

return new ConfiguratorInfo();
}

/**
* Set Configurator.
*
* @param info the configurator information to be set.
* @throws com.github.uiautomatorstub.NotImplementedException
*/
@Override
public ConfiguratorInfo setConfigurator(ConfiguratorInfo info) throws NotImplementedException {
if (Build.VERSION.SDK_INT < 18)
throw new NotImplementedException();

ConfiguratorInfo.setConfigurator(info);
return new ConfiguratorInfo();
}
}
95 changes: 95 additions & 0 deletions src/com/github/uiautomatorstub/ConfiguratorInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.github.uiautomatorstub;

import java.lang.reflect.InvocationTargetException;

/**
* Created by b036 on 12/26/13.
*/
public class ConfiguratorInfo {

public ConfiguratorInfo() {
try {
Class clz = Class.forName("com.android.uiautomator.core.Configurator");
Object conf = clz.getMethod("getInstance").invoke(null);
this._actionAcknowledgmentTimeout = (Long)clz.getMethod("getActionAcknowledgmentTimeout").invoke(conf);
this._keyInjectionDelay = (Long)clz.getMethod("getKeyInjectionDelay").invoke(conf);
this._scrollAcknowledgmentTimeout = (Long)clz.getMethod("getScrollAcknowledgmentTimeout").invoke(conf);
this._waitForIdleTimeout = (Long)clz.getMethod("getWaitForIdleTimeout").invoke(conf);
this._waitForSelectorTimeout = (Long)clz.getMethod("getWaitForSelectorTimeout").invoke(conf);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

public long getActionAcknowledgmentTimeout() {
return _actionAcknowledgmentTimeout;
}

public void setActionAcknowledgmentTimeout(long _actionAcknowledgmentTimeout) {
this._actionAcknowledgmentTimeout = _actionAcknowledgmentTimeout;
}

public long getKeyInjectionDelay() {
return _keyInjectionDelay;
}

public void setKeyInjectionDelay(long _keyInjectionDelay) {
this._keyInjectionDelay = _keyInjectionDelay;
}

public long getScrollAcknowledgmentTimeout() {
return _scrollAcknowledgmentTimeout;
}

public void setScrollAcknowledgmentTimeout(long _scrollAcknowledgmentTimeout) {
this._scrollAcknowledgmentTimeout = _scrollAcknowledgmentTimeout;
}

public long getWaitForIdleTimeout() {
return _waitForIdleTimeout;
}

public void setWaitForIdleTimeout(long _waitForIdleTimeout) {
this._waitForIdleTimeout = _waitForIdleTimeout;
}

public long getWaitForSelectorTimeout() {
return _waitForSelectorTimeout;
}

public void setWaitForSelectorTimeout(long _waitForSelectorTimeout) {
this._waitForSelectorTimeout = _waitForSelectorTimeout;
}

public static void setConfigurator(ConfiguratorInfo info) {
try {
Class clz = Class.forName("com.android.uiautomator.core.Configurator");
Object conf = clz.getMethod("getInstance").invoke(null);
clz.getMethod("setActionAcknowledgmentTimeout", Long.TYPE).invoke(conf, info.getActionAcknowledgmentTimeout());
clz.getMethod("setKeyInjectionDelay", Long.TYPE).invoke(conf, info.getKeyInjectionDelay());
clz.getMethod("setScrollAcknowledgmentTimeout", Long.TYPE).invoke(conf, info.getScrollAcknowledgmentTimeout());
clz.getMethod("setWaitForIdleTimeout", Long.TYPE).invoke(conf, info.getWaitForIdleTimeout());
clz.getMethod("setWaitForSelectorTimeout", Long.TYPE).invoke(conf, info.getWaitForSelectorTimeout());
} catch (IllegalAccessException e) {
Log.d(e.getMessage());
} catch (InvocationTargetException e) {
Log.d(e.getMessage());
} catch (NoSuchMethodException e) {
Log.d(e.getMessage());
} catch (ClassNotFoundException e) {
Log.d(e.getMessage());
}
}

private long _actionAcknowledgmentTimeout;
private long _keyInjectionDelay;
private long _scrollAcknowledgmentTimeout;
private long _waitForIdleTimeout;
private long _waitForSelectorTimeout;
}
Loading

0 comments on commit d2a5577

Please sign in to comment.