Skip to content
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
9 changes: 8 additions & 1 deletion src/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){
.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"))
.put(CURRENT_ACTIVITY, getC("/session/:sessionId/appium/device/current_activity"))
.put(SET_VALUE, postC("/session/:sessionId/appium/element/:id/value"))
;
ImmutableMap<String, CommandInfo> mobileCommands = builder.build();

Expand All @@ -52,7 +54,7 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){
}

@Override
protected Response execute(String driverCommand, Map<String, ?> parameters) {
public Response execute(String driverCommand, Map<String, ?> parameters) {
try {
return super.execute(driverCommand, parameters);
} catch (WebDriverException ex) {
Expand Down Expand Up @@ -90,6 +92,11 @@ public void sendKeyEvent(int key, Integer metastate) {
execute(KEY_EVENT, parameters);
}

public String currentActivity() {
Response response = execute(CURRENT_ACTIVITY);
return response.getValue().toString();
}


@Override
public WebDriver context(String name) {
Expand Down
3 changes: 3 additions & 0 deletions src/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ public interface MobileCommand {
String RESET = "reset";
String GET_STRINGS = "getStrings";
String KEY_EVENT = "keyEvent";
String CURRENT_ACTIVITY = "currentActivity";
String SET_VALUE = "setValue";


}
11 changes: 11 additions & 0 deletions src/io/appium/java_client/MobileDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Response;

import java.util.Map;

public interface MobileDriver extends WebDriver {


public Response execute(String driverCommand, Map<String, ?> parameters);

/**
* Reset the currently running app for this session
*/
Expand All @@ -48,4 +54,9 @@ public interface MobileDriver extends WebDriver {
*/
void sendKeyEvent(int key, Integer metastate);

/**
* Get the current activity being run on the mobile device
*/
String currentActivity();

}
80 changes: 80 additions & 0 deletions src/io/appium/java_client/MobileElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
+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 com.google.common.collect.ImmutableMap;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.*;

import java.util.List;
import java.util.Map;

public class MobileElement extends RemoteWebElement {

private String foundBy;
protected FileDetector fileDetector;

private WebElement webElement;
private MobileDriver parent;

public MobileElement(RemoteWebElement originalElement, MobileDriver parentDriver) {

webElement = originalElement;
this.id = originalElement.getId();
this.parent = parentDriver;
//The super doesn't need the parent object at ALL, it's terrible that it asks for one, when it only needs it for setFoundBy()
super.setParent(new FakeRemoteWebDriver());
}

public List<WebElement> findElements(By by) {
return by.findElements(this);
}

public WebElement findElement(By by) {
return by.findElement(this);
}

public WebElement findElementByIosUIAutomation(String using) { return findElement("-ios uiautomation", using); }

public List<WebElement> findElementsByIosUIAutomation(String using) { return findElements("-ios uiautomation", using); }

public WebElement findElementByAndroidUIAutomator(String using) { return findElement("-android uiautomator", using); }

public List<WebElement> findElementsByAndroidUIAutomator(String using) { return findElements("-android uiautomator", using); }

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

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

public void setValue(String value) {
ImmutableMap.Builder builder = ImmutableMap.builder();
builder.put("id", id).put("value", value);
execute(MobileCommand.SET_VALUE, builder.build());
}

protected Response execute(String command, Map<String, ?> parameters) {
return parent.execute(command, parameters);
}

private class FakeRemoteWebDriver extends RemoteWebDriver {
public FakeRemoteWebDriver() {
//hahaha do NOTHING!
}
}
}
1 change: 0 additions & 1 deletion test/io/appium/java_client/AccessibilityIdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ public void MobileElementsByTest() {
List<WebElement> elements = driver.findElements(MobileBy.AccessibilityId("UICatalog"));
assertEquals(1, elements.size());
}

}
14 changes: 11 additions & 3 deletions test/io/appium/java_client/MobileDriverAndroidTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.File;
import java.net.URL;

import static org.junit.Assert.assertEquals;

/**
* Test Mobile Driver features
*/
Expand All @@ -50,18 +52,24 @@ public void tearDown() throws Exception {
}

@Test
public void getStrings() {
public void getStringsTest() {
String strings = driver.getAppStrings();
assert(strings.length() > 100);
}

@Test
public void keyEvent() {
public void keyEventTest() {
driver.sendKeyEvent(AndroidKeyCode.HOME);
}

@Test
public void keyEventWithMetastate() {
public void keyEventWithMetastateTest() {
driver.sendKeyEvent(AndroidKeyCode.SPACE, AndroidKeyMetastate.META_SHIFT_ON);
}

@Test
public void currentActivityTest() {
String activity = driver.currentActivity();
assertEquals(".ApiDemos", activity);
}
}
9 changes: 9 additions & 0 deletions test/io/appium/java_client/MobileDriverIOSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.Test;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebElement;

import java.io.File;
import java.net.URL;
Expand Down Expand Up @@ -56,4 +57,12 @@ public void resetTest() {
driver.resetApp();
}

@Test
public void setValueTest() {
MobileElement element = new MobileElement((RemoteWebElement)driver.findElementByAccessibilityId("TextFields, Uses of UITextField"), driver);
element.click();
element = new MobileElement((RemoteWebElement)driver.findElementByAccessibilityId("Normal"), driver);
element.setValue("Grace Hopper");
}

}