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

Update Enter button locator for Samsung devices #458

Merged
merged 2 commits into from
Nov 1, 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
23 changes: 11 additions & 12 deletions lib/unlock-helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logger from './logger';
import { sleep } from 'asyncbox';
import _ from 'lodash';
import { util } from 'appium-support';

const PIN_UNLOCK = "pin";
const PASSWORD_UNLOCK = "password";
Expand Down Expand Up @@ -97,27 +98,25 @@ helpers.pinUnlock = async function (adb, driver, capabilities) {
throw new Error("Error finding unlock pin buttons!");
}
let pins = {};
for (let e of els) {
let text = await driver.getAttribute("text", e.ELEMENT);
pins[text] = e;
for (let el of els) {
let text = await driver.getAttribute("text", util.unwrapElement(el));
pins[text] = el;
}
for (let pin of keys) {
let el = pins[pin];
await driver.click(el.ELEMENT);
await driver.click(util.unwrapElement(el));
}
let el = await driver.findElOrEls("id", "com.android.systemui:id/key_enter", false);
await driver.click(el.ELEMENT);
} else {
for (let pin of keys) {
let el = await driver.findElOrEls("id", `com.android.keyguard:id/key${pin}`, false);
let el = await driver.findElOrEls('id', `com.android.keyguard:id/key${pin}`, false);
if (el === null) {
throw new Error(`Error finding unlock pin '${pin}' button!`);
}
await driver.click(el.ELEMENT);
await driver.click(util.unwrapElement(el));
}
let el = await driver.findElOrEls("id", "com.android.keyguard:id/key_enter", false);
await driver.click(el.ELEMENT);
}
const el = await driver.findElOrEls('xpath', "//*[contains(@resource-id, 'id/key_enter')]", false);
await driver.click(util.unwrapElement(el));
// Waits a bit for the device to be unlocked
await sleep(UNLOCK_WAIT_TIME);
};
Expand Down Expand Up @@ -215,8 +214,8 @@ helpers.patternUnlock = async function (adb, driver, capabilities) {
`com.android.${apiLevel >= 21 ? 'systemui' : 'keyguard'}:id/lockPatternView`,
false
);
let initPos = await driver.getLocation(el.ELEMENT);
let size = await driver.getSize(el.ELEMENT);
let initPos = await driver.getLocation(util.unwrapElement(el));
let size = await driver.getSize(util.unwrapElement(el));
// Get actions to perform
let actions = helpers.getPatternActions(keys, initPos, size.width / 3);
// Perform gesture
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"appium-adb": "^6.19.0",
"appium-base-driver": "^3.0.0",
"appium-chromedriver": "^4.0.0",
"appium-support": "^2.13.0",
"appium-support": "^2.24.1",
"asyncbox": "^2.0.4",
"bluebird": "^3.4.7",
"io.appium.settings": "^2.8.0",
Expand Down
4 changes: 2 additions & 2 deletions test/unit/unlock-helper-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('Unlock Helpers', function () {
.withExactArgs("id", "com.android.systemui:id/digit_text", true)
.returns(els);
mocks.driver.expects('findElOrEls')
.withExactArgs("id", "com.android.systemui:id/key_enter", false)
.withExactArgs('xpath', "//*[contains(@resource-id, 'id/key_enter')]", false)
.returns({ELEMENT: 100});
for (let e of els) {
mocks.driver.expects('getAttribute').withExactArgs('text', e.ELEMENT)
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('Unlock Helpers', function () {
.returns({ELEMENT: parseInt(pin, 10)});
}
mocks.driver.expects('findElOrEls')
.withExactArgs("id", "com.android.keyguard:id/key_enter", false)
.withExactArgs('xpath', "//*[contains(@resource-id, 'id/key_enter')]", false)
.returns({ELEMENT: 100});
mocks.asyncbox.expects('sleep').withExactArgs(UNLOCK_WAIT_TIME).once();
sandbox.stub(driver, 'click');
Expand Down