add testcase for inputmethod

Signed-off-by: zhaojunxia <zhaojunxia@kaihong.com>
This commit is contained in:
zhaojunxia 2024-06-04 16:36:06 +08:00
parent 084895a451
commit 99c0a68948
2 changed files with 99 additions and 123 deletions

View File

@ -62,6 +62,7 @@ export struct ReturnItem {
.width(this.returnWidth)
.borderRadius(4)
.height('100%')
.id('returnItem')
.shadow({ radius: 1, color: $r('app.color.shadow'), offsetY: 3 })
.onClick(() => {
InputHandler.getInstance().sendKeyFunction();

View File

@ -132,106 +132,106 @@ export default function abilityTest() {
done();
})
// // 进入菜单
// it('EditModel_001', TestType.FUNCTION, async (done: Function) => {
// logger.info(TAG, `${BUNDLE}EditModel_001 begin`);
// let driver: Driver = Driver.create();
// await driver.delayMs(1000);
// await driver.assertComponentExist(ON.id('keyboardMenu'));
// let keyboardMenu = await driver.findComponent(ON.id('keyboardMenu'));
// await keyboardMenu.click();
// await driver.delayMs(1000);
// await driver.assertComponentExist(ON.id('btnEdit'));
// let btnEdit = await driver.findComponent(ON.id('btnEdit'));
// await btnEdit.click();
// await driver.delayMs(1000);
// await driver.assertComponentExist(ON.id('btn_selection'));
// logger.info(TAG, `${BUNDLE}EditModel_001 end`);
// done();
// })
//
// // 编辑界面,向左移动光标
// it('MoveCursor_001', TestType.FUNCTION, async (done: Function) => {
// logger.info(TAG, `${BUNDLE}MoveCursor_001 begin`);
// let driver: Driver = Driver.create();
// await driver.delayMs(1000);
// let inputContent = await driver.findComponent(ON.id('inputText'));
// let inputString = await inputContent.getText();
// await driver.assertComponentExist(ON.id('arrow_left'));
// let arrow_left = await driver.findComponent(ON.id('arrow_left'));
// await arrow_left.click();
// await driver.delayMs(1000);
// let inputContent1 = await driver.findComponent(ON.id('inputText'));
// let inputString1 = await inputContent1.getText();
// expect((inputString.length - 1) === inputString1.length).assertTrue();
// logger.info(TAG, `${BUNDLE}MoveCursor_001 end`);
// done();
// })
//
// // 编辑界面,向右移动光标
// it('MoveCursor_002', TestType.FUNCTION, async (done: Function) => {
// logger.info(TAG, `${BUNDLE}MoveCursor_002 begin`);
// let driver: Driver = Driver.create();
// await driver.delayMs(1000);
// let inputContent = await driver.findComponent(ON.id('inputText'));
// let inputString = await inputContent.getText();
// await driver.assertComponentExist(ON.id('arrow_right'));
// let arrow_right = await driver.findComponent(ON.id('arrow_right'));
// await arrow_right.click();
// await driver.delayMs(1000);
// let inputContent1 = await driver.findComponent(ON.id('inputText'));
// let inputString1 = await inputContent1.getText();
// expect((inputString.length + 1) === inputString1.length).assertTrue();
// logger.info(TAG, `${BUNDLE}MoveCursor_002 end`);
// done();
// })
//
// // 编辑界面,文本选中
// it('Selection_001', TestType.FUNCTION, async (done: Function) => {
// logger.info(TAG, `${BUNDLE}Selection_001 begin`);
// let driver: Driver = Driver.create();
// await driver.delayMs(1000);
// let btn_selection = await driver.findComponent(ON.id('btn_selection'));
// await btn_selection.click();
// await driver.assertComponentExist(ON.id('arrow_left'));
// let arrow_left = await driver.findComponent(ON.id('arrow_left'));
// await arrow_left.click();
// await driver.delayMs(1000);
// let selectInput = await driver.findComponent(ON.id('selectInput'));
// let selectString = await selectInput.getText();
// expect(selectString.length === 1).assertTrue();
//
// await driver.assertComponentExist(ON.id('arrow_right'));
// let arrow_right = await driver.findComponent(ON.id('arrow_right'));
// await arrow_right.click();
// await driver.delayMs(1000);
// // let selectInput1 = await driver.findComponent(ON.id('selectInput'));
// // expect(selectInput1).assertNull();
// logger.info(TAG, `${BUNDLE}Selection_001 end`);
// done();
// })
//
// // 隐藏软键盘
// it('HideKeyboard_001', TestType.FUNCTION, async (done: Function) => {
// logger.info(TAG, `${BUNDLE}HideKeyboard_001 begin`);
// let driver: Driver = Driver.create();
// await driver.delayMs(1000);
// await driver.assertComponentExist(ON.id('kikaInputDown'));
// let kikaInputDown = await driver.findComponent(ON.id('kikaInputDown'));
// await kikaInputDown.click();
// await driver.delayMs(1000);
// let down = await driver.findComponent(ON.id('kikaInputDown'));
// expect(down).assertNull();
// logger.info(TAG, `${BUNDLE}HideKeyboard_001 end`);
// done();
// })
// 进入菜单
it('EditModel_001', TestType.FUNCTION, async (done: Function) => {
logger.info(TAG, `${BUNDLE}EditModel_001 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(1000);
await driver.assertComponentExist(ON.id('keyboardMenu'));
let keyboardMenu = await driver.findComponent(ON.id('keyboardMenu'));
await keyboardMenu.click();
await driver.delayMs(1000);
await driver.assertComponentExist(ON.id('btnEdit'));
let btnEdit = await driver.findComponent(ON.id('btnEdit'));
await btnEdit.click();
await driver.delayMs(1000);
await driver.assertComponentExist(ON.id('btn_selection'));
logger.info(TAG, `${BUNDLE}EditModel_001 end`);
done();
})
// 编辑界面,向左移动光标
it('MoveCursor_001', TestType.FUNCTION, async (done: Function) => {
logger.info(TAG, `${BUNDLE}MoveCursor_001 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(1000);
let inputContent = await driver.findComponent(ON.id('inputText'));
let inputString = await inputContent.getText();
await driver.assertComponentExist(ON.id('arrow_left'));
let arrow_left = await driver.findComponent(ON.id('arrow_left'));
await arrow_left.click();
await driver.delayMs(1000);
let inputContent1 = await driver.findComponent(ON.id('inputText'));
let inputString1 = await inputContent1.getText();
expect((inputString.length - 1) === inputString1.length).assertTrue();
logger.info(TAG, `${BUNDLE}MoveCursor_001 end`);
done();
})
// 编辑界面,向右移动光标
it('MoveCursor_002', TestType.FUNCTION, async (done: Function) => {
logger.info(TAG, `${BUNDLE}MoveCursor_002 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(1000);
let inputContent = await driver.findComponent(ON.id('inputText'));
let inputString = await inputContent.getText();
await driver.assertComponentExist(ON.id('arrow_right'));
let arrow_right = await driver.findComponent(ON.id('arrow_right'));
await arrow_right.click();
await driver.delayMs(1000);
let inputContent1 = await driver.findComponent(ON.id('inputText'));
let inputString1 = await inputContent1.getText();
expect((inputString.length + 1) === inputString1.length).assertTrue();
logger.info(TAG, `${BUNDLE}MoveCursor_002 end`);
done();
})
// 编辑界面,文本选中
it('Selection_001', TestType.FUNCTION, async (done: Function) => {
logger.info(TAG, `${BUNDLE}Selection_001 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(1000);
let btn_selection = await driver.findComponent(ON.id('btn_selection'));
await btn_selection.click();
await driver.assertComponentExist(ON.id('arrow_left'));
let arrow_left = await driver.findComponent(ON.id('arrow_left'));
await arrow_left.click();
await driver.delayMs(1000);
let selectInput = await driver.findComponent(ON.id('selectInput'));
let selectString = await selectInput.getText();
expect(selectString.length === 1).assertTrue();
await driver.assertComponentExist(ON.id('arrow_right'));
let arrow_right = await driver.findComponent(ON.id('arrow_right'));
await arrow_right.click();
await driver.delayMs(1000);
// let selectInput1 = await driver.findComponent(ON.id('selectInput'));
// expect(selectInput1).assertNull();
logger.info(TAG, `${BUNDLE}Selection_001 end`);
done();
})
// 隐藏软键盘
it('HideKeyboard_001', TestType.FUNCTION, async (done: Function) => {
logger.info(TAG, `${BUNDLE}HideKeyboard_001 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(1000);
await driver.assertComponentExist(ON.id('kikaInputDown'));
let kikaInputDown = await driver.findComponent(ON.id('kikaInputDown'));
await kikaInputDown.click();
await driver.delayMs(1000);
let down = await driver.findComponent(ON.id('kikaInputDown'));
expect(down).assertNull();
logger.info(TAG, `${BUNDLE}HideKeyboard_001 end`);
done();
})
// 预上屏
it('PreviewText_001', TestType.FUNCTION, async (done: Function) => {
logger.info(TAG, `${BUNDLE}PreviewText_001 begin`);
let driver: Driver = Driver.create();
let delegator = AbilityDelegatorRegistry.getAbilityDelegator();
// -a ServiceExtAbility -b com.samples.kikainput
// -a InputMethod -b cn.openharmony.inputmethodchoosedialog
await delegator.executeShellCommand('aa start ability -a EntryAbility -b com.samples.kikainput')
.then(result => {
@ -243,13 +243,9 @@ export default function abilityTest() {
logger.info(TAG, `${BUNDLE}PreviewText_001 11`);
await driver.delayMs(1000);
await driver.delayMs(1000);
// await driver.assertComponentExist(ON.id('kikaInputDown'));
let kikaInputDown = await driver.findComponent(ON.text('kikainput', MatchPattern.CONTAINS));
await kikaInputDown.click();
await driver.delayMs(1000);
// let down = await driver.findComponent(ON.type('TextInput'));
// expect(down).assertNull();
logger.info(TAG, `${BUNDLE}PreviewText_001 end`);
done();
})
@ -257,18 +253,7 @@ export default function abilityTest() {
it('PreviewText_002', TestType.FUNCTION, async (done: Function) => {
logger.info(TAG, `${BUNDLE}PreviewText_002 begin`);
let driver: Driver = Driver.create();
// let delegator = AbilityDelegatorRegistry.getAbilityDelegator();
// // -a ServiceExtAbility -b com.samples.kikainput
// // -a InputMethod -b cn.openharmony.inputmethodchoosedialog
// await delegator.executeShellCommand('aa start ability -a EntryAbility -b com.samples.kikainput')
// .then(result => {
// logger.info(TAG, `${BUNDLE}start ability finished, result = ${JSON.stringify(result)}`);
// })
// .catch((err: Error) => {
// logger.info(TAG, `${BUNDLE}start ability failed, err = ${JSON.stringify(err)}`);
// })
// logger.info(TAG, `${BUNDLE}PreviewText_001 11`);
// await driver.delayMs(1000);
await driver.delayMs(1000);
// 输入hel'触发预上屏'hello world'
await driver.assertComponentExist(ON.type('TextInput'));
@ -300,25 +285,13 @@ export default function abilityTest() {
let inputString = await textInput.getText();
expect(inputString === 'hello world').assertTrue();
logger.info(TAG, `${BUNDLE}PreviewText_001 end`);
logger.info(TAG, `${BUNDLE}PreviewText_002 end`);
done();
})
it('PreviewText_003', TestType.FUNCTION, async (done: Function) => {
logger.info(TAG, `${BUNDLE}PreviewText_003 begin`);
let driver: Driver = Driver.create();
// let delegator = AbilityDelegatorRegistry.getAbilityDelegator();
// // -a ServiceExtAbility -b com.samples.kikainput
// // -a InputMethod -b cn.openharmony.inputmethodchoosedialog
// await delegator.executeShellCommand('aa start ability -a EntryAbility -b com.samples.kikainput')
// .then(result => {
// logger.info(TAG, `${BUNDLE}start ability finished, result = ${JSON.stringify(result)}`);
// })
// .catch((err: Error) => {
// logger.info(TAG, `${BUNDLE}start ability failed, err = ${JSON.stringify(err)}`);
// })
// logger.info(TAG, `${BUNDLE}PreviewText_001 11`);
// await driver.delayMs(1000);
// 输入abhel'触发预上屏'hello world'
await driver.assertComponentExist(ON.type('TextInput'));
@ -348,6 +321,8 @@ export default function abilityTest() {
await inputTextL.click();
await driver.delayMs(2000);
logger.info(TAG, `${BUNDLE}PreviewText_003 11`);
// 点击回车键触发预上屏内容到编辑框
await driver.assertComponentExist(ON.id('returnItem')); // ON.type('ReturnItem')
let enterKey = await driver.findComponent(ON.id('returnItem')); // ON.type('ReturnItem')