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

Implement handlers for lock/unlock API #612

Merged
merged 1 commit into from
Jan 30, 2018
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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@

## Missing functionality

* Setting geo location (https://github.com/appium/appium/issues/6856)
* Auto accepting/dismissing alerts (https://github.com/appium/appium/issues/6863)
* Touch Actions support is limited. Only basic actions, like drag-n-drop, long tap, double tap and tap are supported. Gestures, which are natively supported by XCTest, are implemented via the corresponding ["mobile:" endpoints](https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios-xctest-mobile-gestures.md)


## Known issues

* `shake` is implemented via AppleScript and works only on Simulator due to lack of support from Apple
* `lock` and lock-screen interaction in general is not implemented due to lack of support from Apple
* Setting geo-location is implemented via AppleScript and works only on Simulator due to lack of support from Apple
* Setting geo-location is implemented via AppleScript and works only on Simulator due to lack of support from Apple. In order to make it work on real devices one should have `idevicelocation` tool available.
* Through multi action API, `zoom` works but `pinch` does not, due to Apple issue.


Expand Down
3 changes: 2 additions & 1 deletion lib/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import screenshotExtensions from './screenshots';
import pasteboardExtensions from './pasteboard';
import locationExtensions from './location';
import recordscreenExtensions from './recordscreen';
import lockExtensions from './lock';

let commands = {};

Expand All @@ -25,7 +26,7 @@ Object.assign(commands, actionsCommands, contextCommands, executeExtensions,
generalExtensions, logExtensions, webExtensions, timeoutExtensions,
navigationExtensions, elementExtensions, fileMovementExtensions,
alertExtensions, screenshotExtensions, pasteboardExtensions, locationExtensions,
recordscreenExtensions
recordscreenExtensions, lockExtensions
);

export default commands;
29 changes: 29 additions & 0 deletions lib/commands/lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import B from 'bluebird';

let commands = {};

commands.lock = async function (seconds) {
await this.proxyCommand('/wda/lock', 'POST');
if (isNaN(seconds)) {
return;
}

const floatSeconds = parseFloat(seconds);
if (floatSeconds <= 0) {
return;
}

await B.delay(floatSeconds * 1000);
await this.proxyCommand('/wda/unlock', 'POST');
};

commands.unlock = async function () {
await this.proxyCommand('/wda/unlock', 'POST');
};

commands.isLocked = async function () {
return await this.proxyCommand('/wda/locked', 'GET');
};

export { commands };
export default commands;
2 changes: 2 additions & 0 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const NO_PROXY_NATIVE_LIST = [
['POST', /back/],
['POST', /session\/[^\/]+\/location/], // geo location, but not element location
['POST', /appium\/device\/lock/],
['POST', /appium\/device\/unlock/],
['POST', /appium\/device\/is_locked/],
['POST', /shake/],
['POST', /clear/],
];
Expand Down
10 changes: 8 additions & 2 deletions test/functional/basic/basic-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,14 @@ describe('XCUITestDriver - basics', function () {
});

describe('lock', function () {
it('should throw a not-yet-implemented error', async function () {
await driver.lock().should.be.rejectedWith(/Method has not yet been implemented/);
it('should properly lock and unlock the device', async function () {
try {
await driver.lock();
(await driver.isLocked()).should.be.true;
} finally {
await driver.unlock();
}
(await driver.isLocked()).should.be.false;
});
});

Expand Down