Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
ab631bd2
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6048
Star
92
Fork
165
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ab631bd2
编写于
11月 26, 2024
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: test: 测试与示例适配小程序
上级
8e9b079d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
103 addition
and
80 deletion
+103
-80
pages/component/form/form.test.js
pages/component/form/form.test.js
+8
-2
pages/component/global-events/global-events.test.js
pages/component/global-events/global-events.test.js
+9
-4
pages/component/global-events/touch-events.test.js
pages/component/global-events/touch-events.test.js
+5
-1
pages/component/image/image.test.js
pages/component/image/image.test.js
+8
-22
pages/component/input/input.test.js
pages/component/input/input.test.js
+73
-51
未找到文件。
pages/component/form/form.test.js
浏览文件 @
ab631bd2
...
...
@@ -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
)
...
...
pages/component/global-events/global-events.test.js
浏览文件 @
ab631bd2
...
...
@@ -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
'
)
...
...
pages/component/global-events/touch-events.test.js
浏览文件 @
ab631bd2
...
...
@@ -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
)
})
...
...
pages/component/image/image.test.js
浏览文件 @
ab631bd2
// 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
...
...
pages/component/input/input.test.js
浏览文件 @
ab631bd2
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
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录