提交 77988399 编写于 作者: Anne_LXM's avatar Anne_LXM

新增swiper事件自动化测试例

上级 03c33a03
jest.setTimeout(20000); jest.setTimeout(30000);
function getData(key = '') { function getData(key = '') {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
...@@ -74,4 +74,61 @@ describe('test swiper', () => { ...@@ -74,4 +74,61 @@ describe('test swiper', () => {
expect(await getData('currentValChange')).toEqual(0) expect(await getData('currentValChange')).toEqual(0)
}); });
it('Trigger Event', async () => {
await page.setData({
swiperChangeSelect: true,
swiperTransitionSelect: true,
swiperAnimationfinishSelect: true,
autoplaySelect:true
})
await page.waitFor(2000)
console.log('currentValChange',await getData('currentValChange'))
if(await getData('currentValChange') == 1){
await page.setData({
autoplaySelect:false
})
}
});
it('Event change-transitiont-animationfinish', async () => {
const webResult = {
current: 1,
currentItemId: 'B',//web端多了currentItemId
source: 'autoplay' ,
}
const appResult = {
current: 1,
source: 'autoplay' ,
}
const changeInfo = await page.data('swiperChangeEventTest')
// console.log('change',changeInfo)
expect(changeInfo.type).toBe('change')
if(process.env.uniTestPlatformInfo.startsWith('web')){
expect(changeInfo.detail).toEqual(webResult)
}else{
expect(changeInfo.detail).toEqual(appResult)
}
expect(changeInfo.currentTarget).not.toBeFalsy();
expect(changeInfo.target).not.toBeFalsy();
const transitionInfo = await page.data('swiperTransitionTest')
// console.log('transitiont',transitionInfo,detail)
expect(transitionInfo.type).toBe('transition')
expect(transitionInfo.detail.dy).toBe(0)
expect(transitionInfo.detail.dx).toBeGreaterThan(0)
expect(transitionInfo.currentTarget).not.toBeFalsy();
expect(transitionInfo.target).not.toBeFalsy();
await page.waitFor(1000)
// bug:在android端第一次触发@animationfinish 得到detail中的source为空,第二次触发时正常得到source: 'autoplay'
const animationfinishInfo = await page.data('swiperAnimationfinishTest')
// console.log('animationfinish',animationfinishInfo.detail)
expect(animationfinishInfo.type).toBe('animationfinish')
if(process.env.uniTestPlatformInfo.startsWith('web')){
expect(animationfinishInfo.detail).toEqual(webResult)
}else if(!process.env.uniTestPlatformInfo.startsWith('android')){
expect(animationfinishInfo.detail).toEqual(appResult)
}
expect(animationfinishInfo.currentTarget).not.toBeFalsy();
expect(animationfinishInfo.target).not.toBeFalsy();
});
}); });
...@@ -110,12 +110,17 @@ ...@@ -110,12 +110,17 @@
swiperTransitionSelect: false, swiperTransitionSelect: false,
swiperAnimationfinishSelect: false, swiperAnimationfinishSelect: false,
swiperChangeSelect: false, swiperChangeSelect: false,
currentValChange: 0 currentValChange: 0,
// 自动化测试
swiperChangeEventTest:null as SwiperChangeEvent | null,
swiperTransitionTest:null as SwiperTransitionEvent | null,
swiperAnimationfinishTest:null as SwiperAnimationFinishEvent | null
} }
}, },
methods: { methods: {
swiperChange: function (e : SwiperChangeEvent) { swiperChange: function (e : SwiperChangeEvent) {
this.swiperChangeEventTest = e
this.currentValChange = e.detail.current this.currentValChange = e.detail.current
console.log(this.currentValChange) console.log(this.currentValChange)
if (this.swiperChangeSelect) { if (this.swiperChangeSelect) {
...@@ -124,12 +129,14 @@ ...@@ -124,12 +129,14 @@
} }
}, },
swiperTransition: function (e : SwiperTransitionEvent) { swiperTransition: function (e : SwiperTransitionEvent) {
this.swiperTransitionTest = e
if (this.swiperTransitionSelect) { if (this.swiperTransitionSelect) {
console.log("swiperTransition") console.log("swiperTransition")
console.log(e) console.log(e)
} }
}, },
swiperAnimationfinish: function (e : SwiperAnimationFinishEvent) { swiperAnimationfinish: function (e : SwiperAnimationFinishEvent) {
this.swiperAnimationfinishTest = e
if (this.swiperAnimationfinishSelect) { if (this.swiperAnimationfinishSelect) {
console.log("swiperAnimationfinish") console.log("swiperAnimationfinish")
console.log(e) console.log(e)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册