Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a729d73
New interfaces. The beginning of #105 fix
TikhomirovSergey Sep 12, 2014
59c1486
#105 #108 AndroidDriver. AppiumDriver. Implement & improvement.
TikhomirovSergey Sep 16, 2014
c158b00
#105 & #108 IOSDriver. AppiumDriver. InteractsWithApps.
TikhomirovSergey Sep 21, 2014
5988801
more refactoring. moved tests around, added AppiumDriverTests
Jonahss Sep 23, 2014
cadd0b0
#108 #105 Refactor is going on. AppiumDriver is made abstract.
TikhomirovSergey Sep 24, 2014
8b012e9
Merge pull request #113 from TikhomirovSergey/interfacesRefactor
Jonahss Sep 25, 2014
202d271
#100 Fix
TikhomirovSergey Sep 25, 2014
edbcbee
Merge pull request #114 from TikhomirovSergey/interfacesRefactor
Jonahss Sep 25, 2014
8f2d86e
moved context tests around, added AppiumDriverTest
Jonahss Sep 25, 2014
e6a2790
reimplemented ScrollTo() and ScrollToExact()
Jonahss Sep 25, 2014
0102e91
New interfaces. The beginning of #105 fix
TikhomirovSergey Sep 12, 2014
07c3327
#105 #108 AndroidDriver. AppiumDriver. Implement & improvement.
TikhomirovSergey Sep 16, 2014
dddb062
#105 & #108 IOSDriver. AppiumDriver. InteractsWithApps.
TikhomirovSergey Sep 21, 2014
81be93b
more refactoring. moved tests around, added AppiumDriverTests
Jonahss Sep 23, 2014
15ba3c2
#108 #105 Refactor is going on. AppiumDriver is made abstract.
TikhomirovSergey Sep 24, 2014
3efe96e
#100 Fix
TikhomirovSergey Sep 25, 2014
d9c5ab4
moved context tests around, added AppiumDriverTest
Jonahss Sep 25, 2014
cd5bc3e
Reimplemented ScrollTo() and ScrollToExact()
Jonahss Sep 25, 2014
c8e81b6
v2.0.0
Jonahss Sep 26, 2014
36a63fd
Final improvements before 2.0.
TikhomirovSergey Sep 26, 2014
6a5dcf4
Merge pull request #1 from arachnidium/master
Jonahss Sep 26, 2014
88197f7
removed scrollTo() from AndroidElement
Jonahss Sep 26, 2014
1d45e63
AndroidPageObjectTest improvement.
TikhomirovSergey Sep 27, 2014
f7687da
Merge pull request #2 from arachnidium/master
Jonahss Sep 29, 2014
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
Prev Previous commit
Next Next commit
#105 & #108 IOSDriver. AppiumDriver. InteractsWithApps.
  • Loading branch information
TikhomirovSergey committed Sep 21, 2014
commit c158b009da60c4d3b4fd8d1eff3ebfafe65d5f4f
112 changes: 15 additions & 97 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
public class AppiumDriver extends RemoteWebDriver implements MobileDriver,
ContextAware, Rotatable, FindsByIosUIAutomation,
FindsByAndroidUIAutomator, FindsByAccessibilityId, LocationContext,
DeviceActionShortcuts, TouchShortcuts, InteractsWithFiles {
DeviceActionShortcuts, TouchShortcuts, InteractsWithFiles, InteractsWithApps {

private final static ErrorHandler errorHandler = new ErrorHandler(
new ErrorCodesMobile(), true);
Expand Down Expand Up @@ -231,8 +231,9 @@ public ExecuteMethod getExecuteMethod() {
}

/**
* Reset the currently running app for this session
* @see InteractsWithApps#resetApp()
*/
@Override
public void resetApp() {
execute(MobileCommand.RESET);
}
Expand Down Expand Up @@ -293,48 +294,9 @@ public void hideKeyboard() {
}

/**
* Hides the keyboard if it is showing. Available strategies are PRESS_KEY
* and TAP_OUTSIDE. One taps outside the keyboard, the other presses a key
* of your choosing (probably the 'Done' key). Hiding the keyboard often
* depends on the way an app is implemented, no single strategy always
* works.
*
* These parameters are only for iOS, and ignored by Android.
*
* @param strategy
* HideKeyboardStrategy
* @param keyName
* a String, representing the text displayed on the button of the
* keyboard you want to press. For example: "Done"
*/
//Should be moved to the subclass
public void hideKeyboard(String strategy, String keyName) {
String[] parameters = new String[] { "strategy", "key" };
Object[] values = new Object[] { strategy, keyName };
execute(HIDE_KEYBOARD, getCommandImmutableMap(parameters, values));
}

/**
* Hides the keyboard by pressing the button specified by keyName if it is
* showing. This is an iOS only command.
*
* @param keyName
* The button pressed by the mobile driver to attempt hiding the
* keyboard
*/
//Should be moved to the subclass
public void hideKeyboard(String keyName) {
execute(HIDE_KEYBOARD, ImmutableMap.of("keyName", keyName));
}

/**
* Runs the current app as a background app for the number of seconds
* requested. This is a synchronous method, it returns after the back has
* been returned to the foreground.
*
* @param seconds
* Number of seconds to run App in background
* @see InteractsWithApps#runAppInBackground(int)
*/
@Override
public void runAppInBackground(int seconds) {
execute(RUN_APP_IN_BACKGROUND, ImmutableMap.of("seconds", seconds));
}
Expand Down Expand Up @@ -487,31 +449,9 @@ public void zoom(int x, int y) {
}

/**
* In iOS apps, named TextFields have the same accessibility Id as their
* containing TableElement. This is a convenience method for getting the
* named TextField, rather than its containing element.
*
* @param name
* accessiblity id of TextField
* @return The textfield with the given accessibility id
*/
//Should be moved to the subclass
public WebElement getNamedTextField(String name) {
MobileElement element = (MobileElement) findElementByAccessibilityId(name);
if (element.getTagName() != "TextField") {
return element.findElementByAccessibilityId(name);
}

return element;
}

/**
* Checks if an app is installed on the device
*
* @param bundleId
* bundleId of the app
* @return True if app is installed, false otherwise
* @see InteractsWithApps#isAppInstalled(String)
*/
@Override
public boolean isAppInstalled(String bundleId) {
Response response = execute(IS_APP_INSTALLED,
ImmutableMap.of("bundleId", bundleId));
Expand All @@ -520,59 +460,37 @@ public boolean isAppInstalled(String bundleId) {
}

/**
* Install an app on the mobile device
*
* @param appPath
* path to app to install
* @see InteractsWithApps#installApp(String)
*/
@Override
public void installApp(String appPath) {
execute(INSTALL_APP, ImmutableMap.of("appPath", appPath));
}

/**
* Remove the specified app from the device (uninstall)
*
* @param bundleId
* the bunble identifier (or app id) of the app to remove
* @see InteractsWithApps#removeApp(String)
*/
@Override
public void removeApp(String bundleId) {
execute(REMOVE_APP, ImmutableMap.of("bundleId", bundleId));
}

/**
* Launch the app which was provided in the capabilities at session creation
* @see InteractsWithApps#launchApp()
*/
@Override
public void launchApp() {
execute(LAUNCH_APP);
}

/**
* Close the app which was provided in the capabilities at session creation
* @see InteractsWithApps#closeApp()
*/
@Override
public void closeApp() {
execute(CLOSE_APP);
}

/**
* Lock the device (bring it to the lock screen) for a given number of
* seconds
*
* @param seconds
* number of seconds to lock the screen for
*/
//Should be moved to the subclass (supposed to be in iOS)
public void lockScreen(int seconds) {
execute(LOCK, ImmutableMap.of("seconds", seconds));
}

/**
* Simulate shaking the device This is an iOS-only method
*/
//Should be moved to the subclass
public void shake() {
execute(SHAKE);
}

/**
* Get settings stored for this test session It's probably better to use a
* convenience function, rather than use this function directly. Try finding
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/io/appium/java_client/InteractsWithApps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.appium.java_client;

public interface InteractsWithApps {
/**
* Launch the app which was provided in the capabilities at session creation
*/
public void launchApp();

/**
* Install an app on the mobile device
*
* @param appPath
* path to app to install
*/
public void installApp(String appPath);

/**
* Checks if an app is installed on the device
*
* @param bundleId
* bundleId of the app
* @return True if app is installed, false otherwise
*/
public boolean isAppInstalled(String bundleId);

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

/**
* Runs the current app as a background app for the number of seconds
* requested. This is a synchronous method, it returns after the back has
* been returned to the foreground.
*
* @param seconds
* Number of seconds to run App in background
*/
public void runAppInBackground(int seconds);

/**
* Remove the specified app from the device (uninstall)
*
* @param bundleId
* the bunble identifier (or app id) of the app to remove
*/
public void removeApp(String bundleId);

/**
* Close the app which was provided in the capabilities at session creation
*/
public void closeApp();

}
74 changes: 74 additions & 0 deletions src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package io.appium.java_client.ios;

import static io.appium.java_client.MobileCommand.HIDE_KEYBOARD;
import static io.appium.java_client.MobileCommand.LOCK;
import static io.appium.java_client.MobileCommand.SHAKE;

import java.net.URL;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebElement;

import com.google.common.collect.ImmutableMap;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobilePlatform;

public class IOSDriver extends AppiumDriver implements IOSDeviceActionShortcuts, GetsNamedTextField{
private static final String IOS_PLATFORM = MobilePlatform.IOS;

public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, substituteMobilePlatform(desiredCapabilities,
IOS_PLATFORM));
}

/**
* @see IOSDeviceActionShortcuts#hideKeyboard(String, String)
*/
@Override
public void hideKeyboard(String strategy, String keyName) {
String[] parameters = new String[] { "strategy", "key" };
Object[] values = new Object[] { strategy, keyName };
execute(HIDE_KEYBOARD, getCommandImmutableMap(parameters, values));
}

/**
* @see IOSDeviceActionShortcuts#hideKeyboard(String)
*/
@Override
public void hideKeyboard(String keyName) {
execute(HIDE_KEYBOARD, ImmutableMap.of("keyName", keyName));
}

/**
* @see IOSDeviceActionShortcuts#shake()
*/
@Override
public void shake() {
execute(SHAKE);
}

/**
* @see GetsNamedTextField#getNamedTextField(String)
*/
@Override
public WebElement getNamedTextField(String name) {
MobileElement element = (MobileElement) findElementByAccessibilityId(name);
if (element.getTagName() != "TextField") {
return element.findElementByAccessibilityId(name);
}
return element;
}

/**
* Lock the device (bring it to the lock screen) for a given number of
* seconds
*
* @param seconds
* number of seconds to lock the screen for
*/
public void lockScreen(int seconds) {
execute(LOCK, ImmutableMap.of("seconds", seconds));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

package io.appium.java_client;

import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.HideKeyboardStrategy;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;

import org.junit.After;
import org.junit.Before;
Expand All @@ -38,7 +38,7 @@
*/
public class MobileDriverIOSTest {

private AppiumDriver driver;
private IOSDriver driver;

@Before
public void setup() throws Exception {
Expand All @@ -47,10 +47,10 @@ public void setup() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
//capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@After
Expand Down