提交 aa795f5c 编写于 作者: W wang-xupeng2

update Beta1 demo

Signed-off-by: Nwang-xupeng2 <wangxupeng2@huawei.com>
上级 12360681
......@@ -17,6 +17,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "
import router from '@system.router';
import events_emitter from '@ohos.events.emitter'
import Utils from './Utils';
import {UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection, WindowMode, PointerMatrix} from '@ohos.UiTest';
export default function buttonJsunit() {
describe('buttonTest', function () {
......@@ -299,6 +300,9 @@ export default function buttonJsunit() {
});
it('testButton12', 0, async function (done) {
let driver = Driver.create();
let density = await driver.getDisplayDensity();
console.info("[testButton12] getDisplayDensity is: " + JSON.stringify(density));
await Utils.sleep(1000);
var callback = (eventData) => {
console.info("[testButton12] get event state result is: " + JSON.stringify(eventData));
......@@ -307,10 +311,17 @@ export default function buttonJsunit() {
console.info("[testButton12] get event state result is: " + Math.trunc(event.screenY));
console.info("[testButton12] get event state result is: " + Math.trunc(event.screenX));
try {
expect(event.screenX).assertEqual(185)
expect(event.screenY).assertEqual(533)
expect(event.x).assertEqual(100)
expect(event.y).assertEqual(50)
if(density.x == 1080){
expect(Math.trunc(event.screenX)).assertEqual(185)
expect(Math.trunc(event.screenY)).assertEqual(533)
expect(Math.trunc(event.x)).assertEqual(100)
expect(Math.trunc(event.y)).assertEqual(50)
}else{
expect(Math.trunc(event.screenX)).assertEqual(185)
expect(Math.trunc(event.screenY)).assertEqual(523)
expect(Math.trunc(event.x)).assertEqual(100)
expect(Math.trunc(event.y)).assertEqual(50)
}
} catch (err) {
console.info("[testButton12_] expection err : " + JSON.stringify(err));
expect().assertFail();
......
......@@ -300,6 +300,7 @@ export default function tabsJsunit() {
console.info("testTabs_1400 click result is: " + JSON.stringify(sendEventByKey('tabContent1', 10, "")));
await Utils.sleep(1000);
console.info('testTabs_1400 END');
done();
});
})
}
\ No newline at end of file
......@@ -206,7 +206,7 @@ struct SliderExample {
Text(this.modeT).fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15).key('modeT')
Row() {
Slider({
value: this.vInSetValueOne1,
value: this.vInSetValueOne,
style: this.style,
direction: this.directionT,
reverse: this.reverse,// 竖向的Slider默认是上端是min值,下端是max值,因此想要从下往上滑动,需要设置reverse为true
......@@ -215,7 +215,7 @@ struct SliderExample {
step:this.step
}).showTips(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.vInSetValueOne1 = value
this.vInSetValueOne = value
console.info('value:' + value + 'm`ode:' + mode.toString())
}).key('sliderConstructor')
......@@ -233,7 +233,7 @@ struct SliderExample {
Slider().showTips(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.vInSetValueOne = value
this.vInSetValueOne1 = value
this.modeT = mode.toString()
console.info('value:' + value + 'm`ode:' + mode.toString())
}).key('sliderConstructor2')
......
......@@ -88,7 +88,7 @@ struct StepperExample {
// 第二个步骤页
StepperItem() {
Column() {
Text('Page Two')
Text('Page Two').key('pageTwo')
.itemTextStyle()
Button('change status:' + this.secondState)
.backgroundColor('#007dFF')
......
......@@ -88,7 +88,7 @@ export default function blankJsunit() {
let obj = JSON.parse(strJson);
console.info("[blankJsunit_0300'] component obj is: " + obj.$attrs.min);
// return not the default value to confirm ?
expect(obj.$attrs.min).assertEqual('0.00px');
expect(obj.$attrs.min).assertEqual('0.00vp');
done();
});
......@@ -162,7 +162,7 @@ export default function blankJsunit() {
let strJson2 = getInspectorByKey('bl2');
let obj2 = JSON.parse(strJson2);
console.info("[blankJsunit_0300'] component obj2 is: " + JSON.stringify(obj2));
expect(obj2.$attrs.min).assertEqual('0.00px');
expect(obj2.$attrs.min).assertEqual('0.00vp');
done();
});
......
......@@ -143,12 +143,9 @@ export default function GridJsunit() {
// Verify onScrollIndex event
let grid2 = CommonFunc.getComponentRect('grid2');
let top = grid2.top
let grid2b = CommonFunc.getComponentRect('grid2');
let bottom = grid2b.bottom
let grid2l = CommonFunc.getComponentRect('grid2');
let left = grid2l.left
let grid2r = CommonFunc.getComponentRect('grid2');
let right = grid2r.right
let bottom = grid2.bottom
let left = grid2.left
let right = grid2.right
let driver = await UiDriver.create()
await driver.swipe(Math.round((right - left) / 2), Math.round(bottom - 10), Math.round((right - left) / 2), Math.round(top + 10));
await driver.swipe(Math.round((right - left) / 2), Math.round(bottom - 10), Math.round((right - left) / 2), Math.round(top + 10));
......@@ -166,9 +163,10 @@ export default function GridJsunit() {
let button = await driver.findComponent(BY.key('button'));
await button.click();
await CommonFunc.sleep(1000);
let button1 = await driver.findComponent(BY.key('button'));
let text3 = await button1.getText();
expect(text3).assertEqual('clicked');
let strJson = getInspectorByKey('button');
let obj = JSON.parse(strJson);
console.info('[GridJsunit_0400] component obj is: ' + obj.$attrs.content);
expect(obj.$attrs.label).assertEqual('clicked');
console.info('[GridJsunit_0400] END');
done();
});
......@@ -241,10 +239,10 @@ export default function GridJsunit() {
await CommonFunc.sleep(1000);
let driver = await UiDriver.create()
let gridItem1 = CommonFunc.getComponentRect('0');
let top1 = gridItem1.top
let gridItem2 = CommonFunc.getComponentRect('4');
let top2 = gridItem2.top
expect(top1).assertEqual(parseInt(top2));
let left1 = gridItem1.left
let gridItem2 = CommonFunc.getComponentRect('1');
let left2 = gridItem2.left
expect(parseInt(left1)).assertEqual(parseInt(left2));
console.info('[GridJsunit_0800] END');
done();
});
......
......@@ -134,18 +134,20 @@ export default function SearchJsunit() {
let textComponent1 = await driver.findComponent(BY.key('search'));
await textComponent1.inputText("hello")
await CommonFunc.sleep(1000);
let change = await driver.findComponent(BY.key('change'));
let text1 = await change.getText();
expect(text1).assertEqual('onChange:hello');
let strJson1 = getInspectorByKey('change');
let obj1 = JSON.parse(strJson1);
console.info("[SearchJsunit_0300] obj1: " + JSON.stringify(obj1));
expect(obj1.$attrs.content).assertEqual('onChange:hello');
await CommonFunc.sleep(1000);
// Verify the onSubmit function of the Search component
let textComponent2 = await driver.findComponent(BY.text('CLICK_SEARCH'));
await textComponent2.click()
await CommonFunc.sleep(1000);
let submit = await driver.findComponent(BY.key('submit'));
let text2 = await submit.getText();
expect(text2).assertEqual('onSubmit:hello');
let strJson2 = getInspectorByKey('submit');
let obj2 = JSON.parse(strJson2);
console.info("[SearchJsunit_0300] obj2: " + JSON.stringify(obj2));
expect(obj2.$attrs.content).assertEqual('onSubmit:hello');
// Verify the onCopy function of the Search component
await textComponent1.longClick()
......@@ -154,9 +156,11 @@ export default function SearchJsunit() {
await textComponent3.click()
let textComponent4 = await driver.findComponent(BY.text('复制'));
await textComponent4.click()
let copy = await driver.findComponent(BY.key('copy'));
let text3 = await copy.getText();
expect(text3).assertEqual('onCopy:hello');
await CommonFunc.sleep(1000);
let strJson3 = getInspectorByKey('copy');
let obj3 = JSON.parse(strJson3);
console.info("[SearchJsunit_0300] obj3: " + JSON.stringify(obj3));
expect(obj3.$attrs.content).assertEqual('onCopy:hello');
// Verify the onCut function of the Search component
await textComponent1.longClick()
......@@ -165,25 +169,29 @@ export default function SearchJsunit() {
await textComponent5.click()
let textComponent6 = await driver.findComponent(BY.text('剪切'));
await textComponent6.click()
let cut = await driver.findComponent(BY.key('cut'));
let text4 = await cut.getText();
expect(text4).assertEqual('onCut:hello');
await CommonFunc.sleep(1000);
let strJson4 = getInspectorByKey('cut');
let obj4 = JSON.parse(strJson4);
console.info("[SearchJsunit_0300] obj4: " + JSON.stringify(obj4));
expect(obj4.$attrs.content).assertEqual('onCut:hello');
// Verify the onPaste function of the Search component
await textComponent1.longClick()
await CommonFunc.sleep(1000);
let textComponent8 = await driver.findComponent(BY.text('粘贴'));
await textComponent8.click()
let paste = await driver.findComponent(BY.key('paste'));
let text5 = await paste.getText();
expect(text5).assertEqual('onPaste:hello');
await CommonFunc.sleep(1000);
let strJson5 = getInspectorByKey('paste');
let obj5 = JSON.parse(strJson5);
console.info("[SearchJsunit_0300] obj5: " + JSON.stringify(obj5));
expect(obj5.$attrs.content).assertEqual('onPaste:hello');
// Verify the caretPosition function of the Search component
let textComponent7 = await driver.findComponent(BY.key('button'));
await textComponent7.click();
await CommonFunc.sleep(1000);
let text6 = await textComponent7.getText();
expect(text6).assertEqual('Set caretPosition 2');
let text = await textComponent7.getText();
expect(text).assertEqual('Set caretPosition 2');
console.info('[SearchJsunit_0300] END');
done();
});
......@@ -227,7 +235,7 @@ export default function SearchJsunit() {
expect(obj.$attrs.icon).assertEqual('resource:///ohos_search.svg');
expect(obj.$attrs.searchButton).assertEqual('CLICK_SEARCH');
expect(obj.$attrs.placeholderColor).assertEqual('#FF00000A');
expect(obj.$attrs.value).assertEqual('hello');
expect(obj.$attrs.value).assertEqual('');
expect(obj.$attrs.placeholderFont).assertEqual('{"style":"FontStyle.Normal","size":"14.00fp","weight":"400","fontFamily":"sans-serif"}');
expect(obj.$attrs.textFont).assertEqual('{"fontSize":"14.00fp","fontStyle":"FontStyle.Normal","fontWeight":"400","fontFamily":"HarmonyOS Sans"}');
expect(obj.$attrs.textAlign).assertEqual('TextAlign.Start');
......
......@@ -71,11 +71,10 @@ export default function SelectJsunit() {
expect(obj.$attrs.optionFont).assertEqual('{"size":"16.00fp","weight":"400","family":"","style":"FontStyle.Normal"}');
expect(obj.$attrs.optionFontColor).assertEqual('#FFFF0000');
await CommonFunc.sleep(1000);
let driver = await UiDriver.create()
let textComponent = await driver.findComponent(BY.key('indexValue'));
let text = await textComponent.getText();
console.info("[SelectJsunit_0100] indexValue: " + JSON.stringify(text));
expect(text).assertEqual('indexValue:0');
let strJson1 = getInspectorByKey('indexValue');
let obj1 = JSON.parse(strJson1);
console.info("[SelectJsunit_0300] component obj1 is: " + JSON.stringify(obj1));
expect(obj1.$attrs.content).assertEqual('indexValue:0');
console.info('[SelectJsunit_0100] END');
done();
});
......@@ -132,16 +131,16 @@ export default function SelectJsunit() {
let textComponent1 = await driver.findComponent(BY.key('select'));
await textComponent1.click()
await CommonFunc.sleep(1000);
let textMenuComponent = await driver.findComponent(BY.text('bbb'));
let textMenu = await textMenuComponent.getText();
expect(textMenu).assertEqual('bbb');
// Verify the onSelect function of the select component
let textMenuComponent = await driver.findComponent(BY.text('bbb'));
await textMenuComponent.click()
await CommonFunc.sleep(1000);
let textComponent2 = await driver.findComponent(BY.key('indexValue'));
let text = await textComponent2.getText();
expect(text).assertEqual('indexValue:1');
let strJson1 = getInspectorByKey('indexValue');
let obj1 = JSON.parse(strJson1);
console.info("[SelectJsunit_0300] component obj1 is: " + JSON.stringify(obj1));
expect(obj1.$attrs.content).assertEqual('indexValue:1');
let strJson = getInspectorByKey('select');
let obj = JSON.parse(strJson);
console.info("[SelectJsunit_0300] component obj is: " + JSON.stringify(obj));
......@@ -196,10 +195,10 @@ export default function SelectJsunit() {
expect(obj.$attrs.optionFont).assertEqual('{"size":"16.00fp","weight":"400","family":"","style":"FontStyle.Normal"}');
expect(obj.$attrs.optionFontColor).assertEqual('#FFFFFF00');
await CommonFunc.sleep(1000);
let driver = await UiDriver.create()
let textComponent = await driver.findComponent(BY.key('indexValue'));
let text = await textComponent.getText();
expect(text).assertEqual('indexValue:1');
let strJson1 = getInspectorByKey('indexValue');
let obj1 = JSON.parse(strJson1);
console.info("[SelectJsunit_0400] component obj1 is: " + JSON.stringify(obj1));
expect(obj1.$attrs.content).assertEqual('indexValue:1');
console.info('[SelectJsunit_0400] END');
done();
});
......
......@@ -101,15 +101,15 @@ export default function TextPickerJsunit() {
it('TextPickerJsunit_0300', 0, async function (done) {
// Verify the functions of TextPicker component
console.info('[TextPickerJsunit_0300] START');
let bottomComponent = CommonFunc.getComponentRect('textPicker');
let bottom = bottomComponent.bottom
let rightComponent = CommonFunc.getComponentRect('textPicker');
let right = rightComponent.right
let component = CommonFunc.getComponentRect('textPicker');
let bottom = component.bottom
let right = component.right
console.info("[TextPickerJsunit_0300] bottom: " + JSON.stringify(bottom));
console.info("[TextPickerJsunit_0300] right: " + JSON.stringify(right));
await CommonFunc.sleep(1000);
let driver = await UiDriver.create()
await driver.swipe(Math.round(right / 2), Math.round(bottom * 2 / 3), Math.round(right / 2), Math.round(bottom / 3));
await CommonFunc.sleep(1000);
let strJson = getInspectorByKey('textContent1');
let obj = JSON.parse(strJson);
console.info("[TextPickerJsunit_0300] obj: " + JSON.stringify(obj));
......@@ -141,7 +141,7 @@ export default function TextPickerJsunit() {
expect(obj.$attrs.range).assertEqual('["icon:,text:banana1","icon:,text:orange2","icon:,text:peach3","icon:,text:grape4"]');
expect(obj.$attrs.selected).assertEqual('1');
//expect(obj.$attrs.value).assertEqual('');
expect(obj.$attrs.defaultPickerItemHeight).assertEqual('25.00fp');
expect(obj.$attrs.defaultPickerItemHeight).assertEqual('0.00fp');
console.info('[TextPickerJsunit_0400] END');
done();
});
......
......@@ -190,7 +190,7 @@ export default function ToggleJsunit() {
console.info("[ToggleJsunit_0600] isOn: " + JSON.stringify(obj.$attrs.isOn));
console.info("[ToggleJsunit_0600] selectedColor: " + JSON.stringify(obj.$attrs.selectedColor));
await CommonFunc.sleep(1000);
expect(obj.$attrs.type).assertEqual('ButtonType.Capsule');
expect(obj.$attrs.type).assertEqual('ToggleType.Switch');
expect(obj.$attrs.isOn).assertEqual('false');
expect(obj.$attrs.selectedColor).assertEqual('#FF00007B');
let strJson1 = getInspectorByKey('toggleSwitch');
......
......@@ -52,7 +52,7 @@ export default function marqueeJsunit() {
// to confirm allowScale
console.info('marqueeJsunit_0100 component obj is: ' + obj.$attrs.allowScale);
expect(obj.$attrs.start).assertEqual('false');
expect(obj.$attrs.step).assertEqual('50.000000');
expect(parseInt(obj.$attrs.step)).assertEqual(vp2px(50));
expect(obj.$attrs.loop).assertEqual('2');
expect(obj.$attrs.fromStart).assertEqual('true');
expect(obj.$attrs.src).assertEqual('Running Marquee starts rolling');
......@@ -107,7 +107,7 @@ export default function marqueeJsunit() {
// check the value of changed attribute
let strJson = getInspectorByKey('marquee');
let obj = JSON.parse(strJson);
expect(obj.$attrs.loop).assertEqual('-30');
expect(obj.$attrs.loop).assertEqual('-1');
done();
});
......@@ -119,7 +119,7 @@ export default function marqueeJsunit() {
// check the value of changed parameter
let strJson = getInspectorByKey('marquee');
let obj = JSON.parse(strJson);
expect(obj.$attrs.step).assertEqual('50.000000');
expect(parseInt(obj.$attrs.step)).assertEqual(vp2px(50));
done();
});
......@@ -131,7 +131,7 @@ export default function marqueeJsunit() {
let strJson = getInspectorByKey('marquee');
let obj = JSON.parse(strJson);
// to confirm
expect(obj.$attrs.step).assertEqual('-30.000000');
expect(parseInt(obj.$attrs.step)).assertEqual(vp2px(6));
done();
});
......
......@@ -120,32 +120,36 @@ export default function stepperJsunit() {
it('stepperJsunit_0600', 0, async function (done) {
console.info('stepperJsunit_0600 START');
// reset the component init status
globalThis.value.message.notify({name:'nextLabel',value:'下一步'});
await CommonFunc.sleep(1000);
globalThis.value.message.notify({name:'prevLabel',value:'返回'});
await CommonFunc.sleep(1000);
globalThis.value.message.notify({name:'status',value:ItemState.Normal});
// test the stepper onChange onNext onPrevious event
await CommonFunc.sleep(1000);
let driver = UiDriver.create();
let button = await driver.findComponent(BY.text('Next'));
await button.click();
console.info('stepperJsunit_0600 button click succ');
await CommonFunc.sleep(1000);
// reset the component init status
globalThis.value.message.notify({name:'nextLabel',value:'下一步'});
await CommonFunc.sleep(1000);
globalThis.value.message.notify({name:'prevLabel',value:'返回'});
await CommonFunc.sleep(1000);
let button2 = await driver.findComponent(BY.text('下一步'));
await button2.click();
console.info('stepperJsunit_0600 button2 click succ');
await CommonFunc.sleep(1000);
let textThree = await driver.findComponent(BY.text('Page Three'));
let txt = await textThree.getText();
console.info('stepperJsunit_0700 component obj is: ' + txt);
expect(txt).assertEqual('Page Three');
let strJson = getInspectorByKey('pageThree');
let obj = JSON.parse(strJson);
console.info('stepperJsunit_0600 component obj is: ' + obj.$attrs.content);
expect(obj.$attrs.content).assertEqual('Page Three');
// test the previous
let button3 = await driver.findComponent(BY.text('返回'));
await button3.click();
let textTwo = await driver.findComponent(BY.text('Page Two'));
let txtT = await textTwo.getText();
console.info('stepperJsunit_0600 component obj is: ' + txtT);
expect(txtT).assertEqual('Page Two');
await CommonFunc.sleep(1000);
console.info('stepperJsunit_0600 button3 click succ');
let strJson1 = getInspectorByKey('pageTwo');
let obj1 = JSON.parse(strJson1);
console.info('stepperJsunit_0600 component obj1 is: ' + obj1.$attrs.content);
expect(obj1.$attrs.content).assertEqual('Page Two');
done();
});
......@@ -157,17 +161,20 @@ export default function stepperJsunit() {
await CommonFunc.sleep(2000);
let button2 = await driver.findComponent(BY.text('下一步'));
await button2.click();
console.info('stepperJsunit_0700 button2 click succ');
await CommonFunc.sleep(2000);
let button3 = await driver.findComponent(BY.text('下一步'));
await button3.click();
console.info('stepperJsunit_0700 button3 click succ');
await CommonFunc.sleep(2000);
let button4 = await driver.findComponent(BY.text('开始'));
await button4.click();
console.info('stepperJsunit_0700 button4 click succ');
await CommonFunc.sleep(2000);
let textTwo = await driver.findComponent(BY.text('Page Four'));
let txtT = await textTwo.getText();
console.info('stepperJsunit_0700 component obj is: ' + txtT);
expect(txtT).assertEqual('Page Four');
let strJson = getInspectorByKey('pageFour');
let obj = JSON.parse(strJson);
console.info('stepperJsunit_0700 component obj is: ' + obj.$attrs.content);
expect(obj.$attrs.content).assertEqual('Page Four');
done();
});
......@@ -179,10 +186,10 @@ export default function stepperJsunit() {
let button = await driver.findComponent(BY.text('返回'));
await button.click();
await CommonFunc.sleep(2000);
let textTwo = await driver.findComponent(BY.text('Page Three'));
let txtT = await textTwo.getText();
console.info('stepperJsunit_0800 component obj is: ' + txtT);
expect(txtT).assertEqual('Page Three');
let strJson = getInspectorByKey('pageThree');
let obj = JSON.parse(strJson);
console.info('stepperJsunit_0800 component obj is: ' + obj.$attrs.content);
expect(obj.$attrs.content).assertEqual('Page Three');
done();
});
})
......
......@@ -158,10 +158,11 @@ export default function textAreaJsunit() {
it('textAreaJsunit_0800', 0, async function (done) {
console.info('textAreaJsunit_0800 START');
globalThis.value.message.notify({name:'placeholder',value:''})
await CommonFunc.sleep(2000);
// test the change event
globalThis.value.message.notify({name:'text',value:''})
await CommonFunc.sleep(1000);
let driver = UiDriver.create();
await CommonFunc.sleep(1000);
// test the change event
let text = await driver.findComponent(BY.key('textArea'));
await text.inputText('123');
await CommonFunc.sleep(2000);
......@@ -205,7 +206,7 @@ export default function textAreaJsunit() {
});
it('textAreaJsunit_1000', 0, async function (done) {
console.info('marqueeJsunit_0900 START');
console.info('textAreaJsunit_1000 START');
await CommonFunc.sleep(1000);
// test the cut event
let driver = UiDriver.create();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册