Skip to content

Commit a6f582b

Browse files
committed
Press harder on enabling on-screen kbd
1 parent 930a7b6 commit a6f582b

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

e2e/Keyboard.test.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { default as TestIDs, default as testIDs } from '../playground/src/testID
22
import { device } from 'detox';
33
import Utils from './Utils';
44

5-
const { elementByLabel, elementById } = Utils;
5+
const { elementByLabel, elementById, retry, sleep } = Utils;
66

77
const KBD_OBSCURED_TEXT = 'Keyboard Demo';
88

@@ -34,16 +34,29 @@ const androidDriver = {
3434
// Not initialized
3535
return;
3636
}
37-
await this.adb.shell(this.adbName, 'settings put Secure show_ime_with_hard_keyboard 1');
37+
38+
await this._setOnscreenKeyboard(true);
3839
},
3940

4041
async restoreOnScreenKeyboard() {
4142
if (!this.adb) {
4243
// Not initialized
4344
return;
4445
}
45-
await this.adb.shell(this.adbName, `settings put Secure show_ime_with_hard_keyboard ${this.kbdEnabled}`);
46+
await this._setOnscreenKeyboard(this.kbdEnabled);
4647
},
48+
49+
async _setOnscreenKeyboard(_value) {
50+
const value = (!!Number(_value) ? '1' : '0');
51+
52+
await retry( { retries: 9 }, async () => {
53+
await this.adb.shell(this.adbName, `settings put Secure show_ime_with_hard_keyboard ${value}`);
54+
await sleep(1000);
55+
56+
const result = await this.adb.shell(this.adbName, 'settings get Secure show_ime_with_hard_keyboard');
57+
return result === value;
58+
});
59+
}
4760
}
4861

4962
describe.e2e('Keyboard', () => {

e2e/Utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ function bitmapDiff(imagePath, expectedImagePath, ssimThreshold = SSIM_SCORE_THR
3434
}
3535
}
3636

37+
async function retry({ retries = 3, delay = 1000 }, func) {
38+
let tries = 0;
39+
let result;
40+
do {
41+
result = await func();
42+
} while (!result && ++tries < retries);
43+
44+
if (!result) {
45+
throw new Error(`Failed even after ${retries} retries`);
46+
}
47+
}
48+
3749
const utils = {
3850
elementByLabel: (label) => {
3951
// uncomment for running tests with rn's new arch
@@ -59,6 +71,7 @@ const utils = {
5971
}
6072
},
6173
sleep: (ms) => new Promise((res) => setTimeout(res, ms)),
74+
retry,
6275
expectImagesToBeEqual: (imagePath, expectedImagePath) => {
6376
bitmapDiff(imagePath, expectedImagePath);
6477

0 commit comments

Comments
 (0)