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

accessibility id locator strategy, app reset, get app strings, send key event #5

Merged
merged 3 commits into from
Apr 15, 2014
Merged
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
34 changes: 34 additions & 0 deletions src/io/appium/java_client/AndroidKeyCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
+Copyright 2014 Appium contributors
+Copyright 2014 Software Freedom Conservancy
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */

package io.appium.java_client;

/**
* Some common key codes for Android Key Events
*/
public interface AndroidKeyCode {

int BACK = 4;
int BACKSPACE = 67;
int DEL = 67;
int ENTER = 66;
int HOME = 3;
int MENU = 82;
int SETTINGS = 176;
int SPACE = 62;

}
42 changes: 42 additions & 0 deletions src/io/appium/java_client/AndroidKeyMetastate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
+Copyright 2014 Appium contributors
+Copyright 2014 Software Freedom Conservancy
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */

package io.appium.java_client;

/**
* Metastates for Android Key Events
*/
public interface AndroidKeyMetastate {

int META_ALT_LEFT_ON = 16;
int META_ALT_ON = 2;
int META_ALT_RIGHT_ON = 32;
int META_CAPS_LOCK_ON = 1048576;
int META_CTRL_LEFT_ON = 8192;
int META_CTRL_ON = 4096;
int META_CTRL_RIGHT_ON = 16384;
int META_FUNCTION_ON = 8;
int META_META_LEFT_ON = 131072;
int META_META_ON = 65536;
int META_META_RIGHT_ON = 262144;
int META_NUM_LOCK_ON = 2097152;
int META_SCROLL_LOCK_ON = 4194304;
int META_SHIFT_LEFT_ON = 64;
int META_SHIFT_ON = 1;
int META_SHIFT_RIGHT_ON = 128;
int META_SYM_ON = 4;
}
56 changes: 53 additions & 3 deletions src/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
+Copyright 2014 Appium contributors
+Copyright 2014 Software Freedom Conservancy
+
+Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,7 +17,6 @@

package io.appium.java_client;


import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
Expand All @@ -27,16 +27,24 @@
import java.util.Map;
import java.util.Set;

import static io.appium.java_client.MobileCommand.*;

public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, FindsByIosUIAutomation,
FindsByAndroidUIAutomator {
FindsByAndroidUIAutomator, FindsByAccessibilityId {

private final MobileErrorHandler errorHandler = new MobileErrorHandler();

public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){

super(remoteAddress, desiredCapabilities);

ImmutableMap<String, CommandInfo> mobileCommands = ImmutableMap.<String, CommandInfo>of();
ImmutableMap.Builder<String, CommandInfo> builder = ImmutableMap.builder();
builder
.put(RESET, postC("/session/:sessionId/appium/app/reset"))
.put(GET_STRINGS, getC("/session/:sessionId/appium/app/strings"))
.put(KEY_EVENT, postC("/session/:sessionId/appium/device/keyevent"))
;
ImmutableMap<String, CommandInfo> mobileCommands = builder.build();

HttpCommandExecutor mobileExecutor = new HttpCommandExecutor(mobileCommands, remoteAddress);
super.setCommandExecutor(mobileExecutor);
Expand All @@ -61,6 +69,26 @@ protected Response execute(String command) {
}


public void resetApp() {
execute(MobileCommand.RESET);
}

public String getAppStrings() {
Response response = execute(GET_STRINGS);
return response.getValue().toString();
}

public void sendKeyEvent(int key) {
sendKeyEvent(key, null);
}

public void sendKeyEvent(int key, Integer metastate) {
ImmutableMap.Builder builder = ImmutableMap.builder();
builder.put("keycode", key);
if (metastate != null) { builder.put("metastate", metastate); }
ImmutableMap<String, Integer> parameters = builder.build();
execute(KEY_EVENT, parameters);
}


@Override
Expand Down Expand Up @@ -114,4 +142,26 @@ public WebElement findElementByAndroidUIAutomator(String using) {
public List<WebElement> findElementsByAndroidUIAutomator(String using) {
return findElements("-android uiautomator", using);
}

@Override
public WebElement findElementByAccessibilityId(String using) {
return findElement("accessibility id", using);
}

@Override
public List<WebElement> findElementsByAccessibilityId(String using) {
return findElements("accessibility id", using);
}

private static CommandInfo getC(String url) {
return new CommandInfo(url, HttpVerb.GET);
}

private static CommandInfo postC(String url) {
return new CommandInfo(url, HttpVerb.POST);
}

private static CommandInfo deleteC(String url) {
return new CommandInfo(url, HttpVerb.DELETE);
}
}
2 changes: 1 addition & 1 deletion src/io/appium/java_client/ErrorCodesMobile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2014 Selenium committers
Copyright 2014 Appium contributors
Copyright 2014 Software Freedom Conservancy

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
27 changes: 27 additions & 0 deletions src/io/appium/java_client/FindsByAccessibilityId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2014 Appium committers

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.appium.java_client;

import org.openqa.selenium.WebElement;

import java.util.List;

public interface FindsByAccessibilityId {
WebElement findElementByAccessibilityId(String using);

List<WebElement> findElementsByAccessibilityId(String using);
}
30 changes: 30 additions & 0 deletions src/io/appium/java_client/IOSKeyCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
+Copyright 2014 Appium contributors
+Copyright 2014 Software Freedom Conservancy
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */

package io.appium.java_client;

/**
* Some common key codes for Android Key Events
*/
public interface IOSKeyCode {

int BACKSPACE = 8;
int ENTER = 13;
int RETURN = 13;
int SPACE = 32;

}
32 changes: 32 additions & 0 deletions src/io/appium/java_client/MobileBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public static By AndroidUIAutomator(final String uiautomatorText) {
return new ByAndroidUIAutomator(uiautomatorText);
}

public static By AccessibilityId(final String id) {
if (id == null) {
throw new IllegalArgumentException("Must supply a uiautomationText");
}

return new ByAccessibilityId(id);
}

public static class ByIosUIAutomation extends By implements Serializable {

private final String automationText;
Expand Down Expand Up @@ -73,6 +81,30 @@ public WebElement findElement(SearchContext context) {
@Override
public String toString() { return "By.AndroidUIAutomator: " + automatorText; }
}

public static class ByAccessibilityId extends By implements Serializable {

private final String id;

public ByAccessibilityId(String id) {
this.id = id;
}

@Override
public List<WebElement> findElements(SearchContext context) {
return ((FindsByAccessibilityId) context).findElementsByAccessibilityId(id);
}

@Override
public WebElement findElement(SearchContext context) {
return ((FindsByAccessibilityId) context).findElementByAccessibilityId(id);
}

@Override
public String toString() {
return "By.AccessibilityId: " + id;
}
}
}


31 changes: 31 additions & 0 deletions src/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
+Copyright 2014 Appium contributors
+Copyright 2014 Software Freedom Conservancy
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */

package io.appium.java_client;

/**
* An empty interface defining constants for the mobile commands defined in the Mobile JSON
* wire protocol.
*
*/
public interface MobileCommand {

String RESET = "reset";
String GET_STRINGS = "getStrings";
String KEY_EVENT = "keyEvent";

}
27 changes: 27 additions & 0 deletions src/io/appium/java_client/MobileDriver.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
+Copyright 2014 Appium contributors
+Copyright 2014 Software Freedom Conservancy
+
+Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,4 +22,30 @@

public interface MobileDriver extends WebDriver {

/**
* Reset the currently running app for this session
*/
void resetApp();

/**
* Get all defined Strings from an Android app
*/
String getAppStrings();

/**
* Send a key event to the device
*
* @param key code for the key pressed on the device
*/
void sendKeyEvent(int key);

/**
* Send a key event along with an Android metastate to an Android device
* Metastates are things like *shift* to get uppercase characters
*
* @param key code for the key pressed on the Android device
* @param metastate metastate for the keypress
*/
void sendKeyEvent(int key, Integer metastate);

}
17 changes: 17 additions & 0 deletions src/io/appium/java_client/MobileErrorHandler.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
+Copyright 2014 Appium contributors
+Copyright 2014 Software Freedom Conservancy
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */

package io.appium.java_client;

import org.openqa.selenium.WebDriverException;
Expand Down
Loading