提交 a889ec1e 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test: 调整测试例兼容 web 端

上级 a9bbe02f
......@@ -14,6 +14,6 @@ describe('$forceUpdate', () => {
await triggerForceUpdateBtn.tap()
const timeText2 = (await timeEl.text()).replace('Date.now(): ', '')
expect(parseInt(timeText2)).toBeGreaterThan(parseInt(timeText1))
expect(parseInt(timeText2)).toBeGreaterThanOrEqual(parseInt(timeText1))
})
})
......@@ -15,9 +15,9 @@ describe('$props', () => {
const arrayLiteralBool = await page.$('#array-literal-bool')
expect(await arrayLiteralBool.text()).toBe('true')
const arrayLiteralObj = await page.$('#array-literal-obj')
expect((await arrayLiteralObj.text()).replaceAll('\n', '').replaceAll(' ', '')).toBe('{"count":1}')
expect((await arrayLiteralObj.text()).replaceAll(' ', '')).toBe('{"count":1}')
const arrayLiteralArr = await page.$('#array-literal-arr')
expect((await arrayLiteralArr.text()).replaceAll('\n', '')).toBe('[1,2,3]')
expect(await arrayLiteralArr.text()).toBe('[1,2,3]')
const string = await page.$('.string')
const number = await page.$('.number')
......@@ -32,8 +32,8 @@ describe('$props', () => {
expect(await object.text()).toBe('1')
const checkTypeArr = await page.$('#check-type-arr')
expect((await checkTypeArr.text()).replaceAll('\n', '')).toBe('arr: ["a","b","c"]')
expect(await checkTypeArr.text()).toBe('arr: ["a","b","c"]')
const fooArr = await page.$('#foo-arr')
expect((await fooArr.text()).replaceAll('\n', '')).toBe('arr: [1,2,3]')
expect(await fooArr.text()).toBe('arr: [1,2,3]')
})
})
......@@ -14,6 +14,6 @@ describe('defineSlots', () => {
expect(await slotContent.text()).toBe('default slot num: 0')
const slotFooter = await page.$('#slot-footer')
expect((await slotFooter.text()).replaceAll('\n', '')).toBe('footer slot arr: ["a","b","c"]')
expect(await slotFooter.text()).toBe('footer slot arr: ["a","b","c"]')
})
})
\ No newline at end of file
......@@ -15,11 +15,11 @@ describe('provide-inject-hasInjectionContext', () => {
expect(await num.text()).toBe('num: 0')
const obj = await page.$('.obj')
expect(await obj.text()).toBe(isWeb ? 'obj: {\n"a": 1\n}' : 'obj: {"a":1}')
expect(await obj.text()).toBe(isWeb ? 'obj: {"a": 1}' : 'obj: {"a":1}')
const arr = await page.$('.arr')
expect(await arr.text()).toBe(isWeb ? 'arr: [\n1,\n2,\n3\n]' : 'arr: [1,2,3]')
expect(await arr.text()).toBe('arr: [1,2,3]')
const fn = await page.$('.fn')
expect(await fn.text()).toBe('fn: hello')
......
......@@ -2,13 +2,6 @@ const PAGE_PATH = '/pages/composition-api/lifecycle/component-lifecycle/componen
const HOME_PATH = '/pages/tab-bar/options-api'
describe('component-lifecycle', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
// TODO: 自动化测试暂不能调用web端setup内defineExpose导出的方法,待自动化测试兼容后开放此测试例
it('web', async () => {
expect(1).toBe(1)
})
return
}
let page
let lifeCycleNum
beforeAll(async () => {
......
......@@ -6,7 +6,7 @@ let lifeCycleNum
describe('page-lifecycle', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
// TODO: 自动化测试暂不能调用web端setup内defineExpose导出的方法,待自动化测试兼容后开放此测试例
// TODO: onPageShow onPageHide 别名暂不支持
it('web', async () => {
expect(1).toBe(1)
})
......@@ -28,7 +28,7 @@ describe('page-lifecycle', () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(130)
expect(lifeCycleNum).toBe(120)
await page.callMethod('pageSetlifeCycleNum', 0)
})
it('onPullDownRefresh', async () => {
......@@ -67,7 +67,7 @@ describe('page-lifecycle', () => {
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(130)
expect(lifeCycleNum).toBe(120)
page = await program.navigateBack()
await page.waitFor('view')
lifeCycleNum = await page.callMethod('getLifeCycleNum')
......
......@@ -13,16 +13,16 @@ describe('computed', () => {
expect(await doubleCount.text()).toBe('computed double count: 0')
const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [1,2,3]')
expect(await objArr.text()).toBe('obj.arr: [1,2,3]')
const objArrLen = await page.$('#obj-arr-len')
expect(await objArrLen.text()).toBe('computed obj.arr.length: 3')
const updateBtn = await page.$('.update-btn')
const updateBtn = await page.$('#update-btn')
await updateBtn.tap()
expect(await count.text()).toBe('count: 1')
expect(await doubleCount.text()).toBe('computed double count: 2')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [1,2,3,4]')
expect(await objArr.text()).toBe('obj.arr: [1,2,3,4]')
expect(await objArrLen.text()).toBe('computed obj.arr.length: 4')
})
......
......@@ -4,7 +4,7 @@
<text id="double-count" class="uni-common-mb">computed double count: {{ doubleCount }}</text>
<text id="obj-arr" class="uni-common-mb">obj.arr: {{ obj.arr }}</text>
<text id="obj-arr-len" class="uni-common-mb">computed obj.arr.length: {{ objArrLen }}</text>
<button class="update-btn" @click="update">update</button>
<button id="update-btn" @click="update">update</button>
</view>
</template>
......
......@@ -17,7 +17,7 @@ describe('reactive', () => {
expect(await objNum.text()).toBe('obj.num: 0')
const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: ["a","b","c"]')
expect(await objArr.text()).toBe('obj.arr: ["a","b","c"]')
const updateBtn = await page.$('.update-btn')
await updateBtn.tap()
......@@ -25,6 +25,6 @@ describe('reactive', () => {
expect(await count.text()).toBe('count: 2')
expect(await objStr.text()).toBe('obj.str: new str')
expect(await objNum.text()).toBe('obj.num: 2')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: ["a","b","c","d"]')
expect(await objArr.text()).toBe('obj.arr: ["a","b","c","d"]')
})
})
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/reactivity/readonly/readonly'
describe('ref', () => {
const isWeb = process.env.uniTestPlatformInfo.startsWith('web')
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
......@@ -13,33 +12,33 @@ describe('ref', () => {
const dataNum = await page.$('#data-num')
expect(await dataNum.text()).toBe('data.num: 0')
const dataArr = await page.$('#data-arr')
expect(await dataArr.text()).toBe(isWeb ? 'data.arr: [\n"a",\n"b",\n"c"\n]' : 'data.arr: ["a","b","c"]')
expect(await dataArr.text()).toBe('data.arr: ["a","b","c"]')
const readonlyDataStr = await page.$('#readonly-data-str')
expect(await readonlyDataStr.text()).toBe('readonly data.str: default str')
const readonlyDataNum = await page.$('#readonly-data-num')
expect(await readonlyDataNum.text()).toBe('readonly data.num: 0')
const readonlyDataArr = await page.$('#readonly-data-arr')
expect(await readonlyDataArr.text()).toBe(isWeb ? 'readonly data.arr: [\n"a",\n"b",\n"c"\n]' : 'readonly data.arr: ["a","b","c"]')
expect(await readonlyDataArr.text()).toBe('readonly data.arr: ["a","b","c"]')
const updateDataBtn = await page.$('#update-data-btn')
await updateDataBtn.tap()
expect(await dataStr.text()).toBe('data.str: new str')
expect(await dataNum.text()).toBe('data.num: 1')
expect(await dataArr.text()).toBe(isWeb ? 'data.arr: [\n"a",\n"b",\n"c",\n"d"\n]' : 'data.arr: ["a","b","c","d"]')
expect(await dataArr.text()).toBe('data.arr: ["a","b","c","d"]')
expect(await readonlyDataStr.text()).toBe('readonly data.str: new str')
expect(await readonlyDataNum.text()).toBe('readonly data.num: 1')
expect(await readonlyDataArr.text()).toBe(isWeb ? 'readonly data.arr: [\n"a",\n"b",\n"c",\n"d"\n]' : 'readonly data.arr: ["a","b","c","d"]')
expect(await readonlyDataArr.text()).toBe('readonly data.arr: ["a","b","c","d"]')
const updateReadonlyDataBtn = await page.$('#update-readonly-data-btn')
await updateReadonlyDataBtn.tap()
expect(await dataStr.text()).toBe('data.str: new str')
expect(await dataNum.text()).toBe('data.num: 1')
expect(await dataArr.text()).toBe(isWeb ? 'data.arr: [\n"a",\n"b",\n"c",\n"d"\n]' : 'data.arr: ["a","b","c","d"]')
expect(await dataArr.text()).toBe('data.arr: ["a","b","c","d"]')
expect(await readonlyDataStr.text()).toBe('readonly data.str: new str')
expect(await readonlyDataNum.text()).toBe('readonly data.num: 1')
expect(await readonlyDataArr.text()).toBe(isWeb ? 'readonly data.arr: [\n"a",\n"b",\n"c",\n"d"\n]' : 'readonly data.arr: ["a","b","c","d"]')
expect(await readonlyDataArr.text()).toBe('readonly data.arr: ["a","b","c","d"]')
})
})
\ No newline at end of file
......@@ -76,7 +76,7 @@ describe('watchEffect', () => {
const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0]')
expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
......@@ -104,7 +104,7 @@ describe('watchEffect', () => {
expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0,1]')
expect(await objArr.text()).toBe('obj.arr: [0,1]')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjRes.text()).toBe(
......
......@@ -78,7 +78,7 @@ describe('watchPostEffect', () => {
const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr')
expect(await objArr.text()).toBe(isWeb ? 'obj.arr: [\n0\n]' : 'obj.arr: [0]')
expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res')
// TODO web端和安卓端JSON.stringify对属性的排序不一致
......@@ -99,16 +99,16 @@ describe('watchPostEffect', () => {
expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true')
expect(await objArr.text()).toBe(isWeb ? 'obj.arr: [\n0,\n1\n]' : 'obj.arr: [0,1]')
expect(await objArr.text()).toBe('obj.arr: [0,1]')
expect(await watchObjRes.text()).toBe(
isWeb ?
'watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}' :
'watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' :
'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}'
)
expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 1')
expect(await watchObjArrRes.text()).toBe(isWeb ? 'watch obj.arr result: arr: [\n0,\n1\n]' :
expect(await watchObjArrRes.text()).toBe(
'watch obj.arr result: arr: [0,1]')
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res')
......
......@@ -76,7 +76,7 @@ describe('watchSyncEffect', () => {
const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr')
expect(await objArr.text()).toBe(isWeb ? 'obj.arr: [\n0\n]' : 'obj.arr: [0]')
expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res')
expect(await watchObjRes.text()).toBe(
......@@ -96,7 +96,7 @@ describe('watchSyncEffect', () => {
expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true')
expect(await objArr.text()).toBe(isWeb ? 'obj.arr: [\n0,\n1\n]' : 'obj.arr: [0,1]')
expect(await objArr.text()).toBe('obj.arr: [0,1]')
expect(await watchObjRes.text()).toBe(
isWeb ?
......
......@@ -81,7 +81,7 @@ describe('watch', () => {
const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0]')
expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
......@@ -107,7 +107,7 @@ describe('watch', () => {
expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0,1]')
expect(await objArr.text()).toBe('obj.arr: [0,1]')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjRes.text()).toBe(
......
......@@ -51,21 +51,21 @@ describe('函数方式创建 provide', () => {
const providePageArrEl = await page.$('.provide-page-arr')
const providePageArrText = await providePageArrEl.text()
expect(providePageArrText).toBe(
isWeb ? 'providePageArr: [\n"函数方式定义 provide page arr"\n]' : 'providePageArr: ["函数方式定义 provide page arr"]'
'providePageArr: ["函数方式定义 provide page arr"]'
)
})
it('map', async () => {
const providePageMapEl = await page.$('.provide-page-map')
const providePageMapText = await providePageMapEl.text()
expect(providePageMapText).toBe(
isWeb ? 'providePageMap: {\n"key": "函数方式定义 provide page map"\n}' : 'providePageMap: {"key":"函数方式定义 provide page map"}'
isWeb ? 'providePageMap: {"key": "函数方式定义 provide page map"}' : 'providePageMap: {"key":"函数方式定义 provide page map"}'
)
})
it('set', async () => {
const providePageSetEl = await page.$('.provide-page-set')
const providePageSetText = await providePageSetEl.text()
expect(providePageSetText).toBe(
isWeb ? 'providePageSet: [\n"函数方式定义 provide page set"\n]' : 'providePageSet: ["函数方式定义 provide page set"]'
'providePageSet: ["函数方式定义 provide page set"]'
)
})
})
......@@ -51,21 +51,21 @@ describe('字面量方式创建 provide', () => {
const providePageArrEl = await page.$('.provide-page-arr')
const providePageArrText = await providePageArrEl.text()
expect(providePageArrText).toBe(
isWeb ? 'providePageArr: [\n"字面量方式定义 provide page arr"\n]' : 'providePageArr: ["字面量方式定义 provide page arr"]'
'providePageArr: ["字面量方式定义 provide page arr"]'
)
})
it('map', async () => {
const providePageMapEl = await page.$('.provide-page-map')
const providePageMapText = await providePageMapEl.text()
expect(providePageMapText).toBe(
isWeb ? 'providePageMap: {\n"key": "字面量方式定义 provide page map"\n}' : 'providePageMap: {"key":"字面量方式定义 provide page map"}'
isWeb ? 'providePageMap: {"key": "字面量方式定义 provide page map"}' : 'providePageMap: {"key":"字面量方式定义 provide page map"}'
)
})
it('set', async () => {
const providePageSetEl = await page.$('.provide-page-set')
const providePageSetText = await providePageSetEl.text()
expect(providePageSetText).toBe(
isWeb ? 'providePageSet: [\n"字面量方式定义 provide page set"\n]' : 'providePageSet: ["字面量方式定义 provide page set"]'
'providePageSet: ["字面量方式定义 provide page set"]'
)
})
it('string default value', async () => {
......
const PAGE_PATH = '/pages/directive/v-model/v-model'
describe('v-model', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
// TODO: web 自动化测试InputElement input方法报错
it('web', async () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
......@@ -17,10 +10,14 @@ describe('v-model', () => {
it('input', async () => {
const value = Date.now() + ''
// TODO: 自动化测试web端存在问题
// 1. 直接获取 input 由于 web 端 input 为框架封装的自定义组件,所以被自动化测试框架识别为组定义组件,而不是 input element
// 2. 通过 class 获取标准 input element,自动化测试框架 isValidEl 限制只允许获取 uni element
if (process.env.uniTestPlatformInfo.startsWith('android')) {
const inputElement = await page.$('.input')
await inputElement.input(value)
const inputValueElement = await page.$('.input-value')
expect(await inputValueElement.text()).toBe(value)
}
})
})
\ No newline at end of file
......@@ -36,12 +36,7 @@ describe('page-lifecycle', () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
// TODO 安卓端调整页面加载不触发onResize后调整此测试例
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(lifeCycleNum).toBe(130)
} else if(process.env.uniTestPlatformInfo.startsWith('web')){
expect(lifeCycleNum).toBe(120)
}
await page.callMethod('setLifeCycleNum', 0)
})
it('onPullDownRefresh', async () => {
......@@ -80,17 +75,13 @@ describe('page-lifecycle', () => {
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(lifeCycleNum).toBe(130)
} else if(process.env.uniTestPlatformInfo.startsWith('web')){
expect(lifeCycleNum).toBe(120)
}
page = await program.navigateBack()
await page.waitFor('view')
lifeCycleNum = await page.callMethod('getLifeCycleNum')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(lifeCycleNum).toBe(20)
} else if(process.env.uniTestPlatformInfo.startsWith('web')){
} else if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(lifeCycleNum).toBe(10)
}
await page.callMethod('setLifeCycleNum', 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册