diff --git a/pages/component/form/form.test.js b/pages/component/form/form.test.js index faa9024b25d3c5d4ea861e6c97a919ac0ce8798a..543e5555e29ea7fcb4e7913d1313c7443cc4ccff 100644 --- a/pages/component/form/form.test.js +++ b/pages/component/form/form.test.js @@ -15,6 +15,7 @@ const CHANGE_SWITCH = false const CHANGE_COMMENT = '备注' describe('form', () => { + const isMP = process.env.uniTestPlatformInfo.startsWith('mp') let page beforeAll(async () => { page = await program.reLaunch(PAGE_PATH) @@ -39,9 +40,14 @@ describe('form', () => { expect(formData['age']).toBe(CHANGE_AGE) expect(formData['switch']).toBe(CHANGE_SWITCH) expect(formData['comment']).toBe(CHANGE_COMMENT) - - expect(testVerifySubmit).toBe(true) + if(!isMP) { + expect(testVerifySubmit).toBe(true) + } }) + if(isMP) { + // 微信小程序reset和app、web表现不一致。暂时屏蔽reset测试例,后续如果拉齐再放开 + return + } it('reset', async () => { await changeData(page) diff --git a/pages/component/global-events/global-events.test.js b/pages/component/global-events/global-events.test.js index 0198554f859314f7a3d69ca11d8bb16b0c0439b9..0b1fd9b793a5d34554ed0b295bce7e22d828f16b 100644 --- a/pages/component/global-events/global-events.test.js +++ b/pages/component/global-events/global-events.test.js @@ -41,7 +41,8 @@ describe('event trigger', () => { screenX: 101, screenY: 101 }, ], - }) + }) + await page.waitFor(100) const touchStartTouchTargetIdentifier = '1' const touchStartTouchTargetValue = '101' const touchStartTouchIdentifier = await page.$('#touch-start-touch-identifier') @@ -93,7 +94,8 @@ describe('event trigger', () => { screenX: 102, screenY: 102 }, ], - }) + }) + await page.waitFor(100) const touchMoveTouchTargetIdentifier = '1' const touchMoveTouchTargetValue = '102' @@ -145,7 +147,8 @@ describe('event trigger', () => { screenX: 103, screenY: 103 }, ], - }) + }) + await page.waitFor(100) const touchEndTouchTargetIdentifier = '1' const touchEndTouchTargetValue = '103' const touchEndTouchIdentifier = await page.$('#touch-end-touch-identifier') @@ -193,6 +196,7 @@ describe('event trigger', () => { } else { const el = await page.$('#longpress-target') await el.tap() + await page.waitFor(100) const targetX = '0' const targetY = '0' const tapEventX = await page.$('#tap-event-x') @@ -209,7 +213,8 @@ describe('event trigger', () => { it('longPress', async () => { if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) { const el = await page.$('#longpress-target') - await el.longpress() + await el.longpress() + await page.waitFor(100) if (isMP) { const longPressTouchIdentifier = await page.$('#long-press-touch-identifier') expect(await longPressTouchIdentifier.text()).toBe('0') diff --git a/pages/component/global-events/touch-events.test.js b/pages/component/global-events/touch-events.test.js index 83c574fcd7a10e0b5cf3c30b08e46e1d6e1be82d..a822c179f3a38c8ea6e401d2c7eac136998abb4b 100644 --- a/pages/component/global-events/touch-events.test.js +++ b/pages/component/global-events/touch-events.test.js @@ -3,7 +3,11 @@ const PAGE_PATH = '/pages/component/global-events/touch-events' describe('touch-events-test', () => { // 先屏蔽 android 及 web 平台 - if (process.env.uniTestPlatformInfo.startsWith('android') || process.env.uniTestPlatformInfo.startsWith('web')) { + if ( + process.env.uniTestPlatformInfo.startsWith('android') || + process.env.uniTestPlatformInfo.startsWith('web') || + process.env.uniTestPlatformInfo.startsWith('mp') + ) { it('other platform', () => { expect(1).toBe(1) }) diff --git a/pages/component/image/image.test.js b/pages/component/image/image.test.js index 39845564e9dc8a754c6dc93bbd39dcb6265790ae..0a4b385a4d6138389652aa29a88fac26ed758351 100644 --- a/pages/component/image/image.test.js +++ b/pages/component/image/image.test.js @@ -1,6 +1,8 @@ // uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ -describe('component-native-image', () => { +describe('component-native-image', () => { + const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() + const isMP = platformInfo.startsWith('mp') let page; let start = 0; async function getWindowInfo() { @@ -79,17 +81,8 @@ describe('component-native-image', () => { await page.waitFor(async () => { return (await page.data('eventLoad')) || (Date.now() - start > 1000); }); - if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { - expect(await page.data('eventLoad')).toEqual({ - tagName: 'IMAGE', - type: 'load', - width: 10, - height: 10 - }); - return - } expect(await page.data('eventLoad')).toEqual({ - tagName: 'IMAGE', + tagName: isMP ? undefined : 'IMAGE', type: 'load', width: 10, height: 10 @@ -104,17 +97,10 @@ describe('component-native-image', () => { await page.waitFor(async () => { return (await page.data('eventError')) || (Date.now() - start > 1000); }); - if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { - expect(await page.data('eventError')).toEqual({ - tagName: 'IMAGE', - type: 'error' - }); - }else { - expect(await page.data('eventError')).toEqual({ - tagName: 'IMAGE', - type: 'error' - }); - } + expect(await page.data('eventError')).toEqual({ + tagName: isMP ? undefined : 'IMAGE', + type: 'error' + }); await page.setData({ autoTest: false diff --git a/pages/component/input/input.test.js b/pages/component/input/input.test.js index 23113f64de76e8f483c78bed507549ed277fe45f..ada82a47c2ee6b63e4baecef7353bd28e98ab301 100644 --- a/pages/component/input/input.test.js +++ b/pages/component/input/input.test.js @@ -1,7 +1,9 @@ describe('component-native-input', () => { const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const isAndroid = platformInfo.startsWith('android') - const isIos = platformInfo.startsWith('ios') + const isIOS = platformInfo.startsWith('ios') + const isMP = platformInfo.startsWith('mp') + const isWeb = platformInfo.startsWith('web') let page; beforeAll(async () => { page = await program.reLaunch('/pages/component/input/input') @@ -14,31 +16,33 @@ describe('component-native-input', () => { // }) // expect(image).toSaveImageSnapshot() // }) - // 测试焦点及键盘弹起 - it('focus', async () => { - const input = await page.$('#uni-input-focus'); - expect(await input.attribute('focus')).toBe("true") - // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true) - await page.setData({ - focus: false, - }) - expect(await input.attribute('focus')).toBe("false") - // await page.waitFor(1000) - // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false) - // await page.setData({ - // focus: true, - // }) - // expect(await input.attribute('focus')).toBe(true) - // await page.waitFor(1000) - // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true) - // await page.setData({ - // focus: false, - // }) - // expect(await input.attribute('focus')).toBe(false) - // await page.waitFor(1000) - // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false) - // await page.waitFor(1000) - }); + // 测试焦点及键盘弹起 + if(!isMP) { + it('focus', async () => { + const input = await page.$('#uni-input-focus'); + expect(await input.attribute('focus')).toBe("true") + // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true) + await page.setData({ + focus: false, + }) + expect(await input.attribute('focus')).toBe("false") + // await page.waitFor(1000) + // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false) + // await page.setData({ + // focus: true, + // }) + // expect(await input.attribute('focus')).toBe(true) + // await page.waitFor(1000) + // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true) + // await page.setData({ + // focus: false, + // }) + // expect(await input.attribute('focus')).toBe(false) + // await page.waitFor(1000) + // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false) + // await page.waitFor(1000) + }); + } // 测试修改value属性 it("value", async () => { @@ -116,20 +120,49 @@ describe('component-native-input', () => { // "backgroundColor": "#FFA500" // }) // expect(await placeholder2.attribute("placeholder")).toEqual("占位符背景色为绿色") - // }) - - it("disable", async () => { - const input = await page.$('#uni-input-disable'); - expect(await input.attribute("disabled")).toBe("true") - }) + // }) + + if(isMP) { + it("disable", async () => { + const input = await page.$('#uni-input-disable'); + expect(await input.property("disabled")).toBe(true) + }) + // 如下属性在自动化测试通过property、attribute + confirmType、confirm-type均无法获取 + // it("confirm-type", async () => { + // expect(await (await page.$('#uni-input-confirm-send')).attribute("confirm-type")).toEqual("send") + // expect(await (await page.$('#uni-input-confirm-search')).property("confirmType")).toEqual("search") + // expect(await (await page.$('#uni-input-confirm-next')).property("confirmType")).toEqual("next") + // expect(await (await page.$('#uni-input-confirm-go')).property("confirmType")).toEqual("go") + // expect(await (await page.$('#uni-input-confirm-done')).property("confirmType")).toEqual("done") + // }) + // it("cursor-color", async () => { + // await page.setData({ + // cursor_color: "red", + // }) + // await page.waitFor(500) + // expect(await (await page.$('#uni-input-cursor-color')).property("cursor-color")).toBe("red") + // }) + } else { + it("disable", async () => { + const input = await page.$('#uni-input-disable'); + expect(await input.attribute("disabled")).toBe("true") + }) + it("confirm-type", async () => { + expect(await (await page.$('#uni-input-confirm-send')).attribute("confirmType")).toEqual("send") + expect(await (await page.$('#uni-input-confirm-search')).attribute("confirmType")).toEqual("search") + expect(await (await page.$('#uni-input-confirm-next')).attribute("confirmType")).toEqual("next") + expect(await (await page.$('#uni-input-confirm-go')).attribute("confirmType")).toEqual("go") + expect(await (await page.$('#uni-input-confirm-done')).attribute("confirmType")).toEqual("done") + }) + it("cursor-color", async () => { + await page.setData({ + cursor_color: "red", + }) + await page.waitFor(500) + expect(await (await page.$('#uni-input-cursor-color')).attribute("cursor-color")).toBe("red") + }) + } - it("confirm-type", async () => { - expect(await (await page.$('#uni-input-confirm-send')).attribute("confirmType")).toEqual("send") - expect(await (await page.$('#uni-input-confirm-search')).attribute("confirmType")).toEqual("search") - expect(await (await page.$('#uni-input-confirm-next')).attribute("confirmType")).toEqual("next") - expect(await (await page.$('#uni-input-confirm-go')).attribute("confirmType")).toEqual("go") - expect(await (await page.$('#uni-input-confirm-done')).attribute("confirmType")).toEqual("done") - }) // it("maxlength", async () => { // const input = await page.$('.uni-input-maxlength'); @@ -139,13 +172,6 @@ describe('component-native-input', () => { // await page.waitFor(500) // }) - it("cursor-color", async () => { - await page.setData({ - cursor_color: "red", - }) - await page.waitFor(500) - expect(await (await page.$('#uni-input-cursor-color')).attribute("cursor-color")).toBe("red") - }) it("maxlength", async () => { const input = await page.$('#uni-input-maxlength'); @@ -173,11 +199,7 @@ describe('component-native-input', () => { }) it("keyboard height changed after page back", async () => { - if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('web')) { - expect(1).toBe(1) - return - } - if (process.env.uniTestPlatformInfo.startsWith('ios')) { + if (isWeb || isMP || isIOS) { expect(1).toBe(1) return }