Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
b04d07aa
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
b04d07aa
编写于
2月 03, 2024
作者:
fxy060608
提交者:
qiang
2月 28, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uvue): 支持 app-webview 自动化测试
# Conflicts: # packages/uni-automator/dist/index.js
上级
7cd38647
变更
16
展开全部
隐藏空白更改
内联
并排
Showing
16 changed file
with
172 addition
and
7 deletion
+172
-7
packages/shims-node.d.ts
packages/shims-node.d.ts
+2
-0
packages/uni-app-plus/lib/automator.js
packages/uni-app-plus/lib/automator.js
+1
-1
packages/uni-app-uts/src/plugins/android/plugin.ts
packages/uni-app-uts/src/plugins/android/plugin.ts
+5
-3
packages/uni-automator/lib/app-webview/project/App.uvue
packages/uni-automator/lib/app-webview/project/App.uvue
+35
-0
packages/uni-automator/lib/app-webview/project/main.uts
packages/uni-automator/lib/app-webview/project/main.uts
+9
-0
packages/uni-automator/lib/app-webview/project/manifest.json
packages/uni-automator/lib/app-webview/project/manifest.json
+8
-0
packages/uni-automator/lib/app-webview/project/pages.json
packages/uni-automator/lib/app-webview/project/pages.json
+13
-0
packages/uni-automator/lib/app-webview/project/pages/index/index.uvue
...-automator/lib/app-webview/project/pages/index/index.uvue
+79
-0
packages/uni-automator/lib/uni.plugin.js
packages/uni-automator/lib/uni.plugin.js
+4
-0
packages/uni-automator/src/uni.plugin.ts
packages/uni-automator/src/uni.plugin.ts
+4
-0
packages/uni-cli-shared/src/env/define.ts
packages/uni-cli-shared/src/env/define.ts
+3
-0
packages/uni-cli-shared/src/json/manifest.ts
packages/uni-cli-shared/src/json/manifest.ts
+4
-0
packages/uni-h5/lib/automator.js
packages/uni-h5/lib/automator.js
+1
-1
packages/uni-mp-baidu/lib/automator.js
packages/uni-mp-baidu/lib/automator.js
+1
-1
packages/uni-mp-weixin/lib/automator.js
packages/uni-mp-weixin/lib/automator.js
+1
-1
packages/uni-uts-v1/src/uvue/index.ts
packages/uni-uts-v1/src/uvue/index.ts
+2
-0
未找到文件。
packages/shims-node.d.ts
浏览文件 @
b04d07aa
...
...
@@ -29,6 +29,8 @@ declare namespace NodeJS {
UNI_NVUE_STYLE_COMPILER
:
'
uni-app
'
|
'
weex
'
UNI_APP_CODE_SPLITING
?:
'
true
'
UNI_AUTOMATOR_WS_ENDPOINT
?:
string
UNI_AUTOMATOR_APP_WEBVIEW
?:
string
UNI_AUTOMATOR_APP_WEBVIEW_SRC
?:
string
UNI_H5_BASE
?:
string
UNI_H5_BROWSER
?:
'
builtin
'
UNI_CUSTOM_SCRIPT
?:
string
...
...
packages/uni-app-plus/lib/automator.js
浏览文件 @
b04d07aa
此差异已折叠。
点击以展开。
packages/uni-app-uts/src/plugins/android/plugin.ts
浏览文件 @
b04d07aa
...
...
@@ -224,9 +224,11 @@ function normalizeCode(code: string, isMain = false) {
if
(
!
isMain
)
{
return
code
}
const
automatorCode
=
process
.
env
.
UNI_AUTOMATOR_WS_ENDPOINT
?
'
initAutomator();
'
:
''
const
automatorCode
=
process
.
env
.
UNI_AUTOMATOR_WS_ENDPOINT
&&
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
!==
'
true
'
?
'
initAutomator();
'
:
''
return
`
${
code
}
export function main(app: IApp) {
definePageRoutes();
...
...
packages/uni-automator/lib/app-webview/project/App.uvue
0 → 100644
浏览文件 @
b04d07aa
<script>
let firstBackTime = 0
export default {
onLaunch: function () {
console.log('App Launch')
},
onShow: function () {
console.log('App Show')
},
onHide: function () {
console.log('App Hide')
},
// #ifdef APP-ANDROID
onLastPageBackPress: function () {
console.log('App LastPageBackPress')
if (firstBackTime == 0) {
uni.showToast({
title: '再按一次退出应用',
position: 'bottom',
})
firstBackTime = Date.now()
setTimeout(() => {
firstBackTime = 0
}, 2000)
} else if (Date.now() - firstBackTime < 2000) {
firstBackTime = Date.now()
uni.exit()
}
},
// #endif
onExit: function () {
console.log('App Exit')
},
}
</script>
\ No newline at end of file
packages/uni-automator/lib/app-webview/project/main.uts
0 → 100644
浏览文件 @
b04d07aa
import App from './App.uvue'
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
\ No newline at end of file
packages/uni-automator/lib/app-webview/project/manifest.json
0 → 100644
浏览文件 @
b04d07aa
{
"name"
:
"NAME"
,
"appid"
:
"APPID"
,
"description"
:
""
,
"versionName"
:
"1.0.0"
,
"versionCode"
:
"100"
,
"uni-app-x"
:
{}
}
packages/uni-automator/lib/app-webview/project/pages.json
0 → 100644
浏览文件 @
b04d07aa
{
"pages"
:
[
{
"path"
:
"pages/index/index"
,
"style"
:
{
"navigationBarTitleText"
:
"uni-app x"
}
}
],
"globalStyle"
:
{
"navigationStyle"
:
"custom"
}
}
packages/uni-automator/lib/app-webview/project/pages/index/index.uvue
0 → 100644
浏览文件 @
b04d07aa
<template>
<web-view ref="webview" id="webview" style="flex:1" :webview-styles='webviewStyles' :src="src" @message="message"
@error="error" />
</template>
<script>
export default {
data() {
return {
src: process.env.UNI_AUTOMATOR_APP_WEBVIEW_SRC,
webviewElement: null as UniWebViewElement | null,
webviewContext: null as WebviewContext | null,
webviewStyles: {
progress: false
},
}
},
onReady() {
this.webviewElement = this.$refs['webview'] as UniWebViewElement
this.webviewContext = uni.createWebviewContext('webview', this)
},
methods: {
initAutomator() {
const options = {
wsEndpoint: process.env.UNI_AUTOMATOR_WS_ENDPOINT
}
this.webviewContext!.evalJS(`initRuntimeAutomator(${JSON.stringify(options)})`)
console.log('initRuntimeAutomator...')
},
message(msg: UniWebViewMessageEvent) {
const data = msg.detail.data!
const id = data.get("id") as number
const type = data.get("type") as string
const dataObj = data.get("data") as UTSJSONObject
const action = dataObj.getString("action")!
const args = dataObj.get("args")
if (type != 'automator') {
return;
}
if (action == 'ready') {
this.initAutomator()
} else {
console.log(id, action, args)
if (action == 'captureScreenshot') {
// 调用截图
this.webviewElement!.takeSnapshot({
success: (res) => {
const fileManager = uni.getFileSystemManager()
fileManager.readFile({
encoding: 'base64',
filePath: res.tempFilePath,
success: (readFileRes) => {
this.callback(id, { data: readFileRes.data }, '')
},
fail: (error) => {
this.callback(id, '', error.message)
},
} as ReadFileOptions)
},
fail: (res) => {
this.callback(id, '', res.errMsg)
}
})
}
}
},
error(event: WebViewErrorEvent) {
console.log('webview load error', JSON.stringify(event.detail));
},
callback(id: number, res: any | null, error: string) {
this.webviewContext!.evalJS(`onPostMessageFromUniXWebView(${id},${JSON.stringify(res)},${JSON.stringify(error)})`)
}
}
}
</script>
\ No newline at end of file
packages/uni-automator/lib/uni.plugin.js
浏览文件 @
b04d07aa
...
...
@@ -29,6 +29,10 @@ exports.default = [
if
(
opts
.
filter
(
id
))
{
const
platform
=
process
.
env
.
UNI_PLATFORM
;
if
(
platform
===
'
app
'
&&
process
.
env
.
UNI_APP_X
===
'
true
'
)
{
// app-webview,不增加 initAutomator
if
(
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
===
'
true
'
)
{
return
null
;
}
const
automatorPath
=
(
0
,
uni_cli_shared_1
.
normalizePath
)((
0
,
uni_cli_shared_1
.
resolveBuiltIn
)(
`@dcloudio/uni-app-uts/lib/automator/index.uts`
));
return
{
code
:
...
...
packages/uni-automator/src/uni.plugin.ts
浏览文件 @
b04d07aa
...
...
@@ -38,6 +38,10 @@ export default [
if
(
opts
.
filter
(
id
))
{
const
platform
=
process
.
env
.
UNI_PLATFORM
if
(
platform
===
'
app
'
&&
process
.
env
.
UNI_APP_X
===
'
true
'
)
{
// app-webview,不增加 initAutomator
if
(
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
===
'
true
'
)
{
return
null
}
const
automatorPath
=
normalizePath
(
resolveBuiltIn
(
`@dcloudio/uni-app-uts/lib/automator/index.uts`
)
)
...
...
packages/uni-cli-shared/src/env/define.ts
浏览文件 @
b04d07aa
...
...
@@ -40,6 +40,9 @@ export function initDefine(stringifyBoolean: boolean = false) {
'
process.env.UNI_AUTOMATOR_WS_ENDPOINT
'
:
JSON
.
stringify
(
process
.
env
.
UNI_AUTOMATOR_WS_ENDPOINT
||
''
),
'
process.env.UNI_AUTOMATOR_APP_WEBVIEW_SRC
'
:
JSON
.
stringify
(
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW_SRC
||
''
),
'
process.env.UNI_CLOUD_PROVIDER
'
:
JSON
.
stringify
(
process
.
env
.
UNI_CLOUD_PROVIDER
||
''
),
...
...
packages/uni-cli-shared/src/json/manifest.ts
浏览文件 @
b04d07aa
...
...
@@ -126,6 +126,10 @@ export function getRouterOptions(manifestJson: Record<string, any>): {
}
export
function
isEnableTreeShaking
(
manifestJson
:
Record
<
string
,
any
>
)
{
// 自动化测试时,一定不摇树
if
(
process
.
env
.
UNI_AUTOMATOR_WS_ENDPOINT
)
{
return
false
}
return
manifestJson
.
h5
?.
optimization
?.
treeShaking
?.
enable
!==
false
}
...
...
packages/uni-h5/lib/automator.js
浏览文件 @
b04d07aa
此差异已折叠。
点击以展开。
packages/uni-mp-baidu/lib/automator.js
浏览文件 @
b04d07aa
此差异已折叠。
点击以展开。
packages/uni-mp-weixin/lib/automator.js
浏览文件 @
b04d07aa
此差异已折叠。
点击以展开。
packages/uni-uts-v1/src/uvue/index.ts
浏览文件 @
b04d07aa
...
...
@@ -101,6 +101,8 @@ export async function compileApp(entry: string, options: CompileAppOptions) {
// 自动化测试
NODE_ENV
:
process
.
env
.
NODE_ENV
,
UNI_AUTOMATOR_WS_ENDPOINT
:
process
.
env
.
UNI_AUTOMATOR_WS_ENDPOINT
||
''
,
UNI_AUTOMATOR_APP_WEBVIEW_SRC
:
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW_SRC
||
''
,
},
},
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录