From 3a9cf94c2cbce434953d7a7ab8f23ce2d690695d Mon Sep 17 00:00:00 2001 From: phx1986 Date: Tue, 13 Aug 2024 10:56:48 +0800 Subject: [PATCH 1/3] createcolor Signed-off-by: phx1986 --- .../entry/src/ohosTest/ets/test/List.test.ets | 2 + .../UIComponentCreateColor.test.ets | 222 ++++++++++++++++++ .../UIComponentCreateColor005.ets | 110 +++++++++ .../UIComponentCreateColor010.ets | 109 +++++++++ .../UIComponentCreateColor014.ets | 109 +++++++++ .../resources/base/profile/test_pages.json | 5 +- 6 files changed, 556 insertions(+), 1 deletion(-) create mode 100644 function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets create mode 100644 function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor005.ets create mode 100644 function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor010.ets create mode 100644 function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor014.ets diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/List.test.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/List.test.ets index 2646f9a82..3d3898097 100644 --- a/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/List.test.ets +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/List.test.ets @@ -31,6 +31,7 @@ import UiComponentTextCommonTextstyle from './UiComponentTextCommonTextstyleTest import UiComponentTextTextareaInterface from './UiComponentTextTextareaInterfaceTest/UiComponentTextTextareaInterface.test' import UIAttributePositionSizeLayoutTest from './UIAttributePositionSizeLayoutTest/UIAttributePositionSizeLayoutTest.test' import UIAttributePositionInterfaceTest from './UIAttributePositionInterfaceTest/UIAttributePositionInterfaceTest.test' +import UIComponentCreateColor from './UIComponentCreateColorTest/UIComponentCreateColor.test' export default function testsuite() { demoTest(); UIAttributeFontInterface001(); @@ -50,4 +51,5 @@ export default function testsuite() { UiComponentTextTextareaInterface(); UIAttributePositionSizeLayoutTest(); UIAttributePositionInterfaceTest(); + UIComponentCreateColor(); } \ No newline at end of file diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets new file mode 100644 index 000000000..191180692 --- /dev/null +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import Settings from '../model/Settings' +import windowSnap from '../model/snapShot' +import Logger from '../model/Logger' +import Utils from '../model/Utils' +import { Component, Driver ,ON } from '@ohos.UiTest' + +export default function UIComponentCreateColor() { + + describe('UIComponentCreateColor', () => { + afterEach(async (done: Function) => { + if (Settings.windowClass == undefined) { + return + } + + Settings.windowClass.destroyWindow((err) => { + if (err.code) { + Logger.error('TEST', `Failed to destroy the window. Cause : ${JSON.stringify(err)}`) + return; + } + Logger.info('TEST', `Succeeded in destroy the window.`); + }) + await Utils.sleep(1000); + done() + }) + /* + * @tc.number SUB_ACE_UI_COMPONENT_CREATE_COLOR_0050 + * @tc.name SUB_ACE_UI_COMPONENT_CREATE_COLOR_0050 + * @tc.desc switch the color and set background color to the default color-textinput + */ + it('SUB_ACE_UI_COMPONENT_CREATE_COLOR_0050', 0, async (done: Function) => { + Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0050 start.`); + Settings.createWindow("testability/pages/UIComponentCreateColor/UIComponentCreateColor005") + await Utils.sleep(1000) + //await Driver.create + let driver : Driver = Driver.create(); + await driver.delayMs(1000) + await Utils.sleep(1000) + //red + //dr.findComponent and click and snap + let button1:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button1.click() + await Utils.sleep(100) + let ch2:Component = await driver.findComponent(ON.id('red')); + await driver.delayMs(100) + await ch2.click() + await Utils.sleep(100) + //end + //green + let button2:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button2.click() + await Utils.sleep(100) + let ch3:Component = await driver.findComponent(ON.id('green')); + await driver.delayMs(100) + await ch3.click() + await Utils.sleep(100) + //blue + let button3:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button3.click() + await Utils.sleep(100) + let ch4:Component = await driver.findComponent(ON.id('blue')); + await driver.delayMs(100) + await ch4.click() + await Utils.sleep(100) + //setTextSelection + let btn:Component = await driver.findComponent(ON.id('setTextSelection')); + await driver.delayMs(100) + await btn.click() + await Utils.sleep(100) + let ch1:Component = await driver.findComponent(ON.id('rgb')); + await driver.delayMs(100) + await ch1.click() + await Utils.sleep(100) + windowSnap.snapShot() + await Utils.sleep(100) + Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0050 finish.`); + done() + }) + /* + * @tc.number SUB_ACE_UI_COMPONENT_CREATE_COLOR_0100 + * @tc.name SUB_ACE_UI_COMPONENT_CREATE_COLOR_0100 + * @tc.desc switch the color and set background color to the default color-textarea + */ + it('SUB_ACE_UI_COMPONENT_CREATE_COLOR_0100', 0, async (done: Function) => { + Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0100 start.`); + Settings.createWindow("testability/pages/UIComponentCreateColor/UIComponentCreateColor010") + await Utils.sleep(1000) + //await Driver.create + let driver : Driver = Driver.create(); + await driver.delayMs(1000) + await Utils.sleep(1000) + //red + //dr.findComponent and click and snap + let button1:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button1.click() + await Utils.sleep(100) + let ch2:Component = await driver.findComponent(ON.id('red')); + await driver.delayMs(100) + await ch2.click() + await Utils.sleep(100) + //end + //green + let button2:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button2.click() + await Utils.sleep(100) + let ch3:Component = await driver.findComponent(ON.id('green')); + await driver.delayMs(100) + await ch3.click() + await Utils.sleep(100) + //blue + let button3:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button3.click() + await Utils.sleep(100) + let ch4:Component = await driver.findComponent(ON.id('blue')); + await driver.delayMs(100) + await ch4.click() + await Utils.sleep(100) + //setTextSelection + let btn:Component = await driver.findComponent(ON.id('setTextSelection')); + await driver.delayMs(100) + await btn.click() + await Utils.sleep(100) + let ch1:Component = await driver.findComponent(ON.id('rgb')); + await driver.delayMs(100) + await ch1.click() + await Utils.sleep(100) + windowSnap.snapShot() + await Utils.sleep(1000) + Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0100 finish.`); + done() + }) + /* + * @tc.number SUB_ACE_UI_COMPONENT_CREATE_COLOR_0140 + * @tc.name SUB_ACE_UI_COMPONENT_CREATE_COLOR_0140 + * @tc.desc switch the color and set background color to the default color-search + */ + it('SUB_ACE_UI_COMPONENT_CREATE_COLOR_0140', 0, async (done: Function) => { + Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0140 start.`); + Settings.createWindow("testability/pages/UIComponentCreateColor/UIComponentCreateColor014") + await Utils.sleep(1000) + //await Driver.create + let driver : Driver = Driver.create(); + await driver.delayMs(1000) + await Utils.sleep(1000) + //red + //dr.findComponent and click and snap + let button1:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button1.click() + await Utils.sleep(100) + //click text + let ch2:Component = await driver.findComponent(ON.id('red')); + await driver.delayMs(100) + await ch2.click() + await Utils.sleep(100) + //end + //green + let button2:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button2.click() + await Utils.sleep(100) + //click text + let ch3:Component = await driver.findComponent(ON.id('green')); + await driver.delayMs(100) + await ch3.click() + await Utils.sleep(100) + //blue + let button3:Component = await driver.findComponent(ON.id('caretColor')); + await driver.delayMs(100) + await Utils.sleep(100) + await button3.click() + await Utils.sleep(100) + //click text + let ch4:Component = await driver.findComponent(ON.id('blue')); + await driver.delayMs(100) + await ch4.click() + await Utils.sleep(100) + //setTextSelection + let btn:Component = await driver.findComponent(ON.id('setTextSelection')); + await driver.delayMs(100) + await btn.click() + await Utils.sleep(100) + //click text + let ch1:Component = await driver.findComponent(ON.id('rgb')); + await driver.delayMs(100) + await ch1.click() + await Utils.sleep(100) + windowSnap.snapShot() + await Utils.sleep(1000) + Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0140 finish.`); + done() + }) + }) +} diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor005.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor005.ets new file mode 100644 index 000000000..ecd464502 --- /dev/null +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor005.ets @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct UIComponentCreateColor005 { + @State colorcount:number = 0 + @State booltext:boolean = false + @State boolred:boolean = false + @State boolblue:boolean = false + @State boolgreen:boolean = false + controller:TextInputController = new TextInputController() + + build() { + Column() { + //change selection + Button('setTextSelection') + .width('90%') + .margin({top:20}) + .id('setTextSelection') + .onClick(()=>{ + this.booltext=true + }) + //change caret color + Button('caretColor') + .width('90%') + .margin(20) + .id('caretColor') + .onClick(()=>{ + this.colorcount=this.colorcount+1 + if(this.colorcount % 3===1){ + this.boolred=true + this.boolgreen=false + this.boolblue=false + } + else if(this.colorcount % 3===2){ + this.boolgreen=true + this.boolred=false + this.boolblue=false + } + else if(this.colorcount % 3===0){ + this.boolblue=true + this.boolred=false + this.boolgreen=false + } + }) + //setTextSelection + if(this.booltext){ + TextInput({ + text: 'rgbcolorrgb', + controller: this.controller + }) + .caretColor('#007DFF') + .width(300) + .defaultFocus(true) + .onFocus(() => { + this.controller.setTextSelection(0, 5) + }) + .id('rgb') + } + //caretcolor=red + if(this.boolred){ + TextInput({ + text: 'red', + controller: this.controller + }) + .caretColor(Color.Red) + .width(300) + .margin(20) + .id('red') + } + //caretcolor=blue + if(this.boolblue){ + TextInput({ + text: 'blue', + controller: this.controller + }) + .caretColor(Color.Blue) + .width(300) + .margin(20) + .id('blue') + } + //caretcolor=green + if(this.boolgreen){ + TextInput({ + text: 'green', + controller: this.controller + }) + .caretColor(Color.Green) + .width(300) + .margin(20) + .id('green') + } + } + .width('100%') + .height('100%') + } +} diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor010.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor010.ets new file mode 100644 index 000000000..ba0d48d64 --- /dev/null +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor010.ets @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct UIComponentCreateColor010 { + @State colorcount:number = 0 + @State booltext:boolean = false + @State boolred:boolean = false + @State boolblue:boolean = false + @State boolgreen:boolean = false + controller:TextAreaController = new TextAreaController() + + build() { + Column() { + //change selection + Button('setTextSelection') + .width('90%') + .margin(20) + .id('setTextSelection') + .onClick(()=>{ + this.booltext=true + }) + //change caretcolor + Button('caretColor') + .width('90%') + .margin(20) + .backgroundColor(Color.Orange) + .id('caretColor') + .onClick(()=>{ + this.colorcount=this.colorcount+1 + if(this.colorcount % 3===1){ + this.boolred=true + this.boolgreen=false + this.boolblue=false + } else if(this.colorcount % 3===2){ + this.boolgreen=true + this.boolred=false + this.boolblue=false + } else if(this.colorcount % 3===0){ + this.boolblue=true + this.boolred=false + this.boolgreen=false + } + }) + //select(0,5) + if(this.booltext){ + TextArea({ + text: 'rgbcolorrgb', + controller: this.controller + }) + .caretColor('#007DFF') + .width(300) + .defaultFocus(true) + .id('rgb') + .onFocus(() => { + this.controller.setTextSelection(0, 5) + }) + } + //caretcolor=red + if(this.boolred){ + TextArea({ + text: 'red', + controller: this.controller + }) + .caretColor(Color.Red) + .width(300) + .margin(20) + .id('red') + } + //caretcolor=blue + if(this.boolblue){ + TextArea({ + text: 'blue', + controller: this.controller + }) + .caretColor(Color.Blue) + .width(300) + .margin(20) + .id('blue') + } + //caretcolor=green + if(this.boolgreen){ + TextArea({ + text: 'green', + controller: this.controller + }) + .caretColor(Color.Green) + .width(300) + .margin(20) + .id('green') + } + } + .width('100%') + .height('100%') + } +} diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor014.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor014.ets new file mode 100644 index 000000000..a9ca9d4ae --- /dev/null +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor014.ets @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import prompt from '@system.prompt'; + +@Entry +@Component + +struct UIComponentCreateColor014 { + @State colorcount:number = 0 + @State booltext:boolean = false + @State boolred:boolean = false + @State boolblue:boolean = false + @State boolgreen:boolean = false + controller:SearchController = new SearchController() + + build() { + Column() { + //change selection + Button('setTextSelection') + .width('90%') + .margin(50) + .id('setTextSelection') + .onClick(()=>{ + this.booltext=true + }) + //change caretcolor + Button('caretColor') + .width('90%') + .margin(50) + .backgroundColor(Color.Orange) + .id('caretColor') + .onClick(()=>{ + this.colorcount=this.colorcount+1 + if(this.colorcount % 3===1){ + this.boolred=true + this.boolgreen=false + this.boolblue=false + } else if(this.colorcount % 3===2){ + this.boolgreen=true + this.boolred=false + this.boolblue=false + } else if(this.colorcount % 3===0){ + this.boolblue=true + this.boolred=false + this.boolgreen=false + } + }) + //select(0,5) + if(this.booltext){ + Search({ + value: 'rgbcolorrgb', + controller: this.controller + }) + .caretStyle({color:'#007DFF'}) + .width(300) + .defaultFocus(true) + .onFocus(() => { + this.controller.setTextSelection(0, 5) + }) + .id('rgb') + } + //caretcolor=red + if(this.boolred){ + Search({ + controller: this.controller + }) + .caretStyle({color:Color.Red}) + .width(300) + .margin(20) + .id('red') + } + //caretcolor=blue + if(this.boolblue){ + Search({ + controller: this.controller + }) + .caretStyle({color:Color.Blue}) + .width(300) + .margin(20) + .id('blue') + } + //caretcolor=green + if(this.boolgreen){ + Search({ + controller: this.controller + }) + .caretStyle({color:Color.Green}) + .width(300) + .margin(20) + .id('green') + } + } + .width('100%') + .height('100%') + } +} diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/resources/base/profile/test_pages.json b/function/ui_compare/uicompare/entry/src/ohosTest/resources/base/profile/test_pages.json index 42f75e417..25455cc67 100644 --- a/function/ui_compare/uicompare/entry/src/ohosTest/resources/base/profile/test_pages.json +++ b/function/ui_compare/uicompare/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -251,6 +251,9 @@ "testability/pages/UIAttributePositionInterface/UIAttributePositionInterface003", "testability/pages/UIAttributePositionInterface/UIAttributePositionInterface004", "testability/pages/UIAttributePositionInterface/UIAttributePositionInterface005", - "testability/pages/UIAttributePositionInterface/UIAttributePositionInterface006" + "testability/pages/UIAttributePositionInterface/UIAttributePositionInterface006", + "testability/pages/UIComponentCreateColor/UIComponentCreateColor005", + "testability/pages/UIComponentCreateColor/UIComponentCreateColor010", + "testability/pages/UIComponentCreateColor/UIComponentCreateColor014" ] } -- Gitee From 1eef94d34a5e763cfe356693448e0d6fa388d8c3 Mon Sep 17 00:00:00 2001 From: phx1986 Date: Tue, 13 Aug 2024 12:03:41 +0800 Subject: [PATCH 2/3] color Signed-off-by: phx1986 --- .../UIComponentCreateColor.test.ets | 55 +-------------- .../UIComponentCreateColor005.ets | 69 +++++-------------- .../UIComponentCreateColor010.ets | 66 ++++-------------- .../UIComponentCreateColor014.ets | 61 ++++------------ 4 files changed, 48 insertions(+), 203 deletions(-) diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets index 191180692..962f282b4 100644 --- a/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets @@ -46,43 +46,28 @@ export default function UIComponentCreateColor() { Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0050 start.`); Settings.createWindow("testability/pages/UIComponentCreateColor/UIComponentCreateColor005") await Utils.sleep(1000) - //await Driver.create let driver : Driver = Driver.create(); await driver.delayMs(1000) await Utils.sleep(1000) - //red - //dr.findComponent and click and snap let button1:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button1.click() await Utils.sleep(100) - let ch2:Component = await driver.findComponent(ON.id('red')); + let ch2:Component = await driver.findComponent(ON.id('colorstr')); await driver.delayMs(100) await ch2.click() await Utils.sleep(100) - //end - //green let button2:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button2.click() await Utils.sleep(100) - let ch3:Component = await driver.findComponent(ON.id('green')); - await driver.delayMs(100) - await ch3.click() - await Utils.sleep(100) - //blue let button3:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button3.click() await Utils.sleep(100) - let ch4:Component = await driver.findComponent(ON.id('blue')); - await driver.delayMs(100) - await ch4.click() - await Utils.sleep(100) - //setTextSelection let btn:Component = await driver.findComponent(ON.id('setTextSelection')); await driver.delayMs(100) await btn.click() @@ -105,43 +90,28 @@ export default function UIComponentCreateColor() { Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0100 start.`); Settings.createWindow("testability/pages/UIComponentCreateColor/UIComponentCreateColor010") await Utils.sleep(1000) - //await Driver.create let driver : Driver = Driver.create(); await driver.delayMs(1000) await Utils.sleep(1000) - //red - //dr.findComponent and click and snap let button1:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button1.click() await Utils.sleep(100) - let ch2:Component = await driver.findComponent(ON.id('red')); + let ch2:Component = await driver.findComponent(ON.id('colorstr')); await driver.delayMs(100) await ch2.click() await Utils.sleep(100) - //end - //green let button2:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button2.click() await Utils.sleep(100) - let ch3:Component = await driver.findComponent(ON.id('green')); - await driver.delayMs(100) - await ch3.click() - await Utils.sleep(100) - //blue let button3:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button3.click() await Utils.sleep(100) - let ch4:Component = await driver.findComponent(ON.id('blue')); - await driver.delayMs(100) - await ch4.click() - await Utils.sleep(100) - //setTextSelection let btn:Component = await driver.findComponent(ON.id('setTextSelection')); await driver.delayMs(100) await btn.click() @@ -164,51 +134,32 @@ export default function UIComponentCreateColor() { Logger.info('TEST', `SUB_ACE_UI_COMPONENT_CREATE_COLOR_0140 start.`); Settings.createWindow("testability/pages/UIComponentCreateColor/UIComponentCreateColor014") await Utils.sleep(1000) - //await Driver.create let driver : Driver = Driver.create(); await driver.delayMs(1000) await Utils.sleep(1000) - //red - //dr.findComponent and click and snap let button1:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button1.click() await Utils.sleep(100) - //click text - let ch2:Component = await driver.findComponent(ON.id('red')); + let ch2:Component = await driver.findComponent(ON.id('colorstr')); await driver.delayMs(100) await ch2.click() await Utils.sleep(100) - //end - //green let button2:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button2.click() await Utils.sleep(100) - //click text - let ch3:Component = await driver.findComponent(ON.id('green')); - await driver.delayMs(100) - await ch3.click() - await Utils.sleep(100) - //blue let button3:Component = await driver.findComponent(ON.id('caretColor')); await driver.delayMs(100) await Utils.sleep(100) await button3.click() await Utils.sleep(100) - //click text - let ch4:Component = await driver.findComponent(ON.id('blue')); - await driver.delayMs(100) - await ch4.click() - await Utils.sleep(100) - //setTextSelection let btn:Component = await driver.findComponent(ON.id('setTextSelection')); await driver.delayMs(100) await btn.click() await Utils.sleep(100) - //click text let ch1:Component = await driver.findComponent(ON.id('rgb')); await driver.delayMs(100) await ch1.click() diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor005.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor005.ets index ecd464502..cb7df4293 100644 --- a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor005.ets +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor005.ets @@ -16,11 +16,10 @@ @Entry @Component struct UIComponentCreateColor005 { - @State colorcount:number = 0 @State booltext:boolean = false - @State boolred:boolean = false - @State boolblue:boolean = false - @State boolgreen:boolean = false + @State caretcolorIndex: number = 0; + @State caretcolor: Color[] = [Color.Red, Color.Green, Color.Blue] + @State caretcolorStr: string[] = ['Red', 'Green', 'Blue'] controller:TextInputController = new TextInputController() build() { @@ -39,22 +38,10 @@ struct UIComponentCreateColor005 { .margin(20) .id('caretColor') .onClick(()=>{ - this.colorcount=this.colorcount+1 - if(this.colorcount % 3===1){ - this.boolred=true - this.boolgreen=false - this.boolblue=false - } - else if(this.colorcount % 3===2){ - this.boolgreen=true - this.boolred=false - this.boolblue=false - } - else if(this.colorcount % 3===0){ - this.boolblue=true - this.boolred=false - this.boolgreen=false - } + this.caretcolorIndex++ + if (this.caretcolorIndex > (this.caretcolorStr.length - 1)) { + this.caretcolorIndex = 0 + } }) //setTextSelection if(this.booltext){ @@ -70,39 +57,15 @@ struct UIComponentCreateColor005 { }) .id('rgb') } - //caretcolor=red - if(this.boolred){ - TextInput({ - text: 'red', - controller: this.controller - }) - .caretColor(Color.Red) - .width(300) - .margin(20) - .id('red') - } - //caretcolor=blue - if(this.boolblue){ - TextInput({ - text: 'blue', - controller: this.controller - }) - .caretColor(Color.Blue) - .width(300) - .margin(20) - .id('blue') - } - //caretcolor=green - if(this.boolgreen){ - TextInput({ - text: 'green', - controller: this.controller - }) - .caretColor(Color.Green) - .width(300) - .margin(20) - .id('green') - } + //caretcolor + TextInput({ + text: this.caretcolorStr[this.caretcolorIndex], + controller: this.controller + }) + .caretColor(this.caretcolor[this.caretcolorIndex]) + .width(300) + .margin(20) + .id('colorstr') } .width('100%') .height('100%') diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor010.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor010.ets index ba0d48d64..94207854b 100644 --- a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor010.ets +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor010.ets @@ -16,11 +16,10 @@ @Entry @Component struct UIComponentCreateColor010 { - @State colorcount:number = 0 @State booltext:boolean = false - @State boolred:boolean = false - @State boolblue:boolean = false - @State boolgreen:boolean = false + @State caretcolorIndex: number = 0; + @State caretcolor: Color[] = [Color.Red, Color.Green, Color.Blue] + @State caretcolorStr: string[] = ['Red', 'Green', 'Blue'] controller:TextAreaController = new TextAreaController() build() { @@ -37,22 +36,11 @@ struct UIComponentCreateColor010 { Button('caretColor') .width('90%') .margin(20) - .backgroundColor(Color.Orange) .id('caretColor') .onClick(()=>{ - this.colorcount=this.colorcount+1 - if(this.colorcount % 3===1){ - this.boolred=true - this.boolgreen=false - this.boolblue=false - } else if(this.colorcount % 3===2){ - this.boolgreen=true - this.boolred=false - this.boolblue=false - } else if(this.colorcount % 3===0){ - this.boolblue=true - this.boolred=false - this.boolgreen=false + this.caretcolorIndex++ + if (this.caretcolorIndex > (this.caretcolorStr.length - 1)) { + this.caretcolorIndex = 0 } }) //select(0,5) @@ -69,39 +57,15 @@ struct UIComponentCreateColor010 { this.controller.setTextSelection(0, 5) }) } - //caretcolor=red - if(this.boolred){ - TextArea({ - text: 'red', - controller: this.controller - }) - .caretColor(Color.Red) - .width(300) - .margin(20) - .id('red') - } - //caretcolor=blue - if(this.boolblue){ - TextArea({ - text: 'blue', - controller: this.controller - }) - .caretColor(Color.Blue) - .width(300) - .margin(20) - .id('blue') - } - //caretcolor=green - if(this.boolgreen){ - TextArea({ - text: 'green', - controller: this.controller - }) - .caretColor(Color.Green) - .width(300) - .margin(20) - .id('green') - } + //caretcolor + TextArea({ + text: this.caretcolorStr[this.caretcolorIndex], + controller: this.controller + }) + .caretColor(this.caretcolor[this.caretcolorIndex]) + .width(300) + .margin(20) + .id('colorstr') } .width('100%') .height('100%') diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor014.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor014.ets index a9ca9d4ae..66cd54635 100644 --- a/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor014.ets +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/testability/pages/UIComponentCreateColor/UIComponentCreateColor014.ets @@ -19,11 +19,10 @@ import prompt from '@system.prompt'; @Component struct UIComponentCreateColor014 { - @State colorcount:number = 0 @State booltext:boolean = false - @State boolred:boolean = false - @State boolblue:boolean = false - @State boolgreen:boolean = false + @State caretcolorIndex: number = 0; + @State caretcolor: Color[] = [Color.Red, Color.Green, Color.Blue] + @State caretcolorStr: string[] = ['Red', 'Green', 'Blue'] controller:SearchController = new SearchController() build() { @@ -43,19 +42,9 @@ struct UIComponentCreateColor014 { .backgroundColor(Color.Orange) .id('caretColor') .onClick(()=>{ - this.colorcount=this.colorcount+1 - if(this.colorcount % 3===1){ - this.boolred=true - this.boolgreen=false - this.boolblue=false - } else if(this.colorcount % 3===2){ - this.boolgreen=true - this.boolred=false - this.boolblue=false - } else if(this.colorcount % 3===0){ - this.boolblue=true - this.boolred=false - this.boolgreen=false + this.caretcolorIndex++ + if (this.caretcolorIndex > (this.caretcolorStr.length - 1)) { + this.caretcolorIndex = 0 } }) //select(0,5) @@ -72,36 +61,14 @@ struct UIComponentCreateColor014 { }) .id('rgb') } - //caretcolor=red - if(this.boolred){ - Search({ - controller: this.controller - }) - .caretStyle({color:Color.Red}) - .width(300) - .margin(20) - .id('red') - } - //caretcolor=blue - if(this.boolblue){ - Search({ - controller: this.controller - }) - .caretStyle({color:Color.Blue}) - .width(300) - .margin(20) - .id('blue') - } - //caretcolor=green - if(this.boolgreen){ - Search({ - controller: this.controller - }) - .caretStyle({color:Color.Green}) - .width(300) - .margin(20) - .id('green') - } + //caretcolor + Search({ + controller: this.controller + }) + .caretStyle({color:this.caretcolor[this.caretcolorIndex]}) + .width(300) + .margin(20) + .id('colorstr') } .width('100%') .height('100%') -- Gitee From 03c248be9f1076abd1173102f34c0c27e9ab4b3d Mon Sep 17 00:00:00 2001 From: phx1986 Date: Tue, 13 Aug 2024 15:12:48 +0800 Subject: [PATCH 3/3] color Signed-off-by: phx1986 --- .../UIComponentCreateColor.test.ets | 42 ++++++------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets b/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets index 962f282b4..ca7e6dcc6 100644 --- a/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets +++ b/function/ui_compare/uicompare/entry/src/ohosTest/ets/test/UIComponentCreateColorTest/UIComponentCreateColor.test.ets @@ -58,15 +58,9 @@ export default function UIComponentCreateColor() { await driver.delayMs(100) await ch2.click() await Utils.sleep(100) - let button2:Component = await driver.findComponent(ON.id('caretColor')); - await driver.delayMs(100) - await Utils.sleep(100) - await button2.click() - await Utils.sleep(100) - let button3:Component = await driver.findComponent(ON.id('caretColor')); - await driver.delayMs(100) + await button1.click() await Utils.sleep(100) - await button3.click() + await button1.click() await Utils.sleep(100) let btn:Component = await driver.findComponent(ON.id('setTextSelection')); await driver.delayMs(100) @@ -102,15 +96,9 @@ export default function UIComponentCreateColor() { await driver.delayMs(100) await ch2.click() await Utils.sleep(100) - let button2:Component = await driver.findComponent(ON.id('caretColor')); - await driver.delayMs(100) - await Utils.sleep(100) - await button2.click() - await Utils.sleep(100) - let button3:Component = await driver.findComponent(ON.id('caretColor')); - await driver.delayMs(100) + await button1.click() await Utils.sleep(100) - await button3.click() + await button1.click() await Utils.sleep(100) let btn:Component = await driver.findComponent(ON.id('setTextSelection')); await driver.delayMs(100) @@ -138,23 +126,17 @@ export default function UIComponentCreateColor() { await driver.delayMs(1000) await Utils.sleep(1000) let button1:Component = await driver.findComponent(ON.id('caretColor')); - await driver.delayMs(100) - await Utils.sleep(100) - await button1.click() + await driver.delayMs(1000) await Utils.sleep(100) let ch2:Component = await driver.findComponent(ON.id('colorstr')); - await driver.delayMs(100) + await driver.delayMs(1000) await ch2.click() - await Utils.sleep(100) - let button2:Component = await driver.findComponent(ON.id('caretColor')); - await driver.delayMs(100) - await Utils.sleep(100) - await button2.click() - await Utils.sleep(100) - let button3:Component = await driver.findComponent(ON.id('caretColor')); - await driver.delayMs(100) - await Utils.sleep(100) - await button3.click() + await Utils.sleep(1000) + await button1.click() + await Utils.sleep(1500) + await button1.click() + await Utils.sleep(1500) + await button1.click() await Utils.sleep(100) let btn:Component = await driver.findComponent(ON.id('setTextSelection')); await driver.delayMs(100) -- Gitee