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

#315 fix #318

Merged
merged 1 commit into from
Feb 12, 2016
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ More can be found in the docs, but here's a quick list of features which this pr
- launchApp()
- closeApp()
- endTestCoverage()
- lockScreen()
- isLocked()
- shake()
- scrollTo()
Expand All @@ -95,6 +94,8 @@ More can be found in the docs, but here's a quick list of features which this pr
- getNetworkConnection(), setNetworkConnection()
- ignoreUnimportantViews(), getSettings()
- toggleLocationServices()
- lockDevice()
- unlockDevice()

Locators:
- findElementByAccessibilityId()
Expand All @@ -121,6 +122,9 @@ instead of a string. Thanks to [@rgonalo](https://github.com/rgonalo) for the co
- FIXED `longPressKeyCode()` methods. Now they use the convenient JSONWP command.Thanks to [@kirillbilchenko](https://github.com/kirillbilchenko) for the proposed fix.
- FIXED javadoc.
- Page object tools were updated. Details read here: [#311](https://github.com/appium/java-client/issues/311), [#313](https://github.com/appium/java-client/pull/313), [#317](https://github.com/appium/java-client/pull/317). By.name locator strategy is deprecated for Android and iOS. It is still valid for the Selendroid mode. Thanks to [@SrinivasanTarget](https://github.com/SrinivasanTarget) for the helping.
- The method `lockScreen(seconds)` is deprecated and it is going to be removed in the next release. Since Appium node server v1.5.x it is recommended to use
`AndroidDriver.lockDevice()...AndroidDriver.unlockDevice()` or `IOSDriver.lockDevice(int seconds)` instead. Thanks to [@namannigam](https://github.com/namannigam) for
the catching. Read [#315](https://github.com/appium/java-client/issues/315)

*3.3.0*
- updated the dependency on Selenium to version 2.48.2
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,18 +536,20 @@ protected void setSetting(AppiumSetting setting, Object value) {
setSettings(getCommandImmutableMap(setting.toString(), value));
}


@Deprecated
/**
* Lock the device (bring it to the lock screen) for a given number of
* seconds
* This method works incorrectly. It is deprecated and it is going to be removed further.
* Be careful.
*
* @param seconds
* number of seconds to lock the screen for
* Since Appium node 1.5.x you are free to use
* IOSDriver.lockDevice(int seconds) or AndroidDriver.lockDevice()...AndroidDriver.unlockDevice() instead
*/
public void lockScreen(int seconds) {
execute(LOCK, ImmutableMap.of("seconds", seconds));
}

@Override
@Override
public WebDriver context(String name) {
if (!_isNotNullOrEmpty(name)) {
throw new IllegalArgumentException("Must supply a context name");
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class MobileCommand {
public final static String START_ACTIVITY = "startActivity";
public final static String TOGGLE_LOCATION_SERVICES = "toggleLocationServices";
public final static String GET_DEVICE_TIME = "getDeviceTime";
public final static String UNLOCK = "unlock";

static CommandInfo getC(String url) {
return new CommandInfo(url, HttpMethod.GET);
Expand Down Expand Up @@ -133,7 +134,8 @@ private static Map<String, CommandInfo> getMobileCommands(){
.put(START_ACTIVITY,
postC("/session/:sessionId/appium/device/start_activity"))
.put(TOGGLE_LOCATION_SERVICES, postC("/session/:sessionId/appium/device/toggle_location_services"))
.put(GET_DEVICE_TIME,getC("/session/:sessionId/appium/device/system_time"));
.put(GET_DEVICE_TIME,getC("/session/:sessionId/appium/device/system_time"))
.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock"));

return builder.build();
}
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/io/appium/java_client/android/AndroidDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@
import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static io.appium.java_client.MobileCommand.CURRENT_ACTIVITY;
import static io.appium.java_client.MobileCommand.END_TEST_COVERAGE;
import static io.appium.java_client.MobileCommand.GET_NETWORK_CONNECTION;
import static io.appium.java_client.MobileCommand.IS_LOCKED;
import static io.appium.java_client.MobileCommand.OPEN_NOTIFICATIONS;
import static io.appium.java_client.MobileCommand.PRESS_KEY_CODE;
import static io.appium.java_client.MobileCommand.LONG_PRESS_KEY_CODE;
import static io.appium.java_client.MobileCommand.PUSH_FILE;
import static io.appium.java_client.MobileCommand.SET_NETWORK_CONNECTION;
import static io.appium.java_client.MobileCommand.START_ACTIVITY;
import static io.appium.java_client.MobileCommand.TOGGLE_LOCATION_SERVICES;
import static io.appium.java_client.MobileCommand.*;
import static io.appium.java_client.remote.MobileCapabilityType.APP_ACTIVITY;
import static io.appium.java_client.remote.MobileCapabilityType.APP_PACKAGE;
import static io.appium.java_client.remote.MobileCapabilityType.APP_WAIT_ACTIVITY;
Expand Down Expand Up @@ -388,4 +378,17 @@ public List<RequiredElementType> findElementsByAndroidUIAutomator(String using)
return (List<RequiredElementType>) findElements("-android uiautomator", using);
}

/**
* This method locks a device.
*/
public void lockDevice() {
execute(LOCK, ImmutableMap.of("seconds", 0));
}

/**
* This method unlocks a device.
*/
public void unlockDevice() {
execute(UNLOCK);
}
}
11 changes: 11 additions & 0 deletions src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,15 @@ public RequiredElementType findElementByIosUIAutomation(String using) throws Web
public List<RequiredElementType> findElementsByIosUIAutomation(String using) throws WebDriverException {
return (List<RequiredElementType>) findElements("-ios uiautomation", using);
}

/**
* 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 lockDevice(int seconds) {
execute(LOCK, ImmutableMap.of("seconds", seconds));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ public void networkConnectionTest() {

}

@Test
public void isLockedTest() {
assertEquals(false, driver.isLocked());
}

@Test
public void ignoreUnimportantViews() {
driver.ignoreUnimportantViews(true);
Expand Down Expand Up @@ -248,7 +243,10 @@ public void orientationTest() {

@Test
public void lockTest() {
driver.lockScreen(20);
driver.lockDevice();
assertEquals(true, driver.isLocked());
driver.unlockDevice();
assertEquals(false, driver.isLocked());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void orientationTest() {

@Test
public void lockTest() {
driver.lockScreen(20);
driver.lockDevice(20);
}

@Test
Expand Down