单纯做网站的公司,如何设计一个有趣的网页,旅游圈wordpress主题,北京网站seo优化排名公司如果你有很多手机#xff0c;然后需要在这些手机上同时执行相同的操作#xff0c;这个时候如果能有一种办法批量操作#xff0c;将会大大提高效率#xff0c;节省很多时间。本文将介绍基于uiautomator2实现的群控手机方案。
uiautomator2 是 一种 Android 自动化测试框架然后需要在这些手机上同时执行相同的操作这个时候如果能有一种办法批量操作将会大大提高效率节省很多时间。本文将介绍基于uiautomator2实现的群控手机方案。
uiautomator2 是 一种 Android 自动化测试框架提供了点击、长按、输入文本、滑动、拖拽、截屏等方法能够模拟用户的各种动作。
本方案采用python的web端框架djangovue前端框架实现支持在页面选择手机执行配置的命令多部手机会同时执行操作页面做的比较简陋见谅。
大致的流程也比较简单基于在页面配置的命令调用uiautomator2的相关api实现有兴趣的朋友也可以了解下uiautomator2相关的接口动手来实现一遍
这里贴上前端的实现代码
templatediv classcommon-layoutel-containerel-headerdiv stylefont-weight: bolder;text-align: center;font-size: 30px手机群控/div/el-headerel-mainel-rowel-col :span12el-card classbox-carddiv styledisplay: flex;justify-content: space-between;align-items:centerdiv stylefont-weight: bolder;设备列表/divel-button link typetext clickgetDeviceList刷新/el-button/divel-table :datadeviceListData stylewidth: 100%; height75vh selection-changeselectDevices refdeviceTableel-table-column typeselection width55/el-table-column propsn label设备编号/el-table-column propname label设备名称/el-table-column propstatus label状态/el-table-column label操作template slot-scopescopeel-button link typetext sizesmall clickeditDevice(scope.row)编辑/el-button!--el-button link typeprimary sizesmall删除/el-button--/template/el-table-column/el-table/el-card/el-colel-col :span12el-card classbox-carddiv styledisplay: flex;justify-content: space-between;align-items:centerdiv stylefont-weight: bolder;命令列表/divel-button link typetext clickaddCommandVisible true添加/el-button/divel-table :datacommandListData stylewidth: 100% height75vh el-table-column width55/el-table-column propname label名称/el-table-column propcreatTime label创建时间/el-table-column label操作template slot-scopescopeel-button link typeprimary sizesmall clickupdateCommand(scope.row)编辑/el-buttonel-button link typeprimary sizesmall clickdeleteCommand(scope.row.name)删除/el-buttonel-button link typeprimary sizesmall clickexecuteCommand(scope.row.name)执行/el-button/template/el-table-column/el-table/el-card/el-col/el-row/el-main/el-containerel-dialog :visible.syncaddCommandVisible title添加/编辑命令el-input v-modelcommandInfo.name autocompleteoff placeholder请输入命令名称/el-inputel-table :row-class-nametableRowClassName :datacommandInfo.commands border stylewidth: 100%el-table-column aligncenter width100px typeindex label序号/el-table-columnel-table-column aligncenter propoperation label操作template slot-scopescopeel-select changeoperationChange(scope.row.operation,scope.row.index) sizesmallv-modelscope.row.operation placeholder请选择操作类型el-option v-foritem in operationOption :keyitem.value :labelitem.label:valueitem.value/el-option/el-select/template/el-table-columnel-table-column aligncenter propparam label参数template #defaultscopeel-input sizesmall v-modelscope.row.param placeholder非必填有则填写/el-input/template/el-table-columnel-table-column aligncenter propdelayTime label延时template #defaultscopeel-input sizesmall v-modelscope.row.delayTime placeholder填写延时时长单位秒/el-input/template/el-table-columnel-table-column aligncenter propdate label操作template slot-scopescopeel-button link typeprimary sizesmall clickaddForm添加/el-buttonel-button link typeprimary sizesmall v-ifcommandInfo.commands.length1clickremoveIdx(scope.row,scope.row.index) stylecolor:rgb(216,30,6)删除/el-button/template/el-table-column/el-tabletemplate #footerspan classdialog-footerel-button clickaddCommandVisible false取消/el-buttonel-button typeprimary clickaddCommand确定/el-button/span/template/el-dialogel-dialog title编辑设备 :visible.syncupdateDeviceVisibleel-form :modeldeviceInfoel-form-item label设备编号 :label-widthformLabelWidthel-input v-modeldeviceInfo.sn autocompleteoff disabled/el-input/el-form-itemel-form-item label设备名称 :label-widthformLabelWidthel-input v-modeldeviceInfo.name autocompleteoff/el-input/el-form-item/el-formdiv slotfooter classdialog-footerel-button clickupdateDeviceVisible false取 消/el-buttonel-button typeprimary clickupdateDevice确 定/el-button/div/el-dialog/div
/template
scriptimport {getDeviceList, updateDevice,getCommandList,addCommand,deleteCommand,executeCommand} from /api/deviceexport default {name: device,data() {return {formLabelWidth: 140px,addCommandVisible: false,commandInfo: {name:,commands: [{operation: ,param: ,delayTime: }]},operationOption: [{value: 单击,label: 单击},{value: 返回,label: 返回},{value: 右滑,label: 右滑},{value: 截屏,label: 截屏},{value: 点击Home键,label: 点击Home键},{value: 卸载,label: 卸载},{value: 输入文字,label: 输入文字},{value: 左滑,label: 左滑}],deviceListData: [],commandListData: [],deviceInfo: {sn: ,name: },executeParam:{devices:[],name:},updateDeviceVisible:false,}},mounted() {this.getDeviceList()this.getCommandList()},methods: {selectDevices(val) {let selection this.$refs.deviceTable.selection;this.executeParam.devices []for (let item of selection){this.executeParam.devices.push(item.sn)}console.log(JSON.stringify(this.executeParam.devices))},getDeviceList() {getDeviceList().then(res {if (res.code 0) {this.deviceListData res.data;} else {this.$message.error(查询失败)}this.loading false}).catch(err {this.loading falsethis.$message.error(err)})},operationChange(operation, index) {this.commandInfo.commands[index].operation operation},editDevice(data){this.deviceInfo datathis.updateDeviceVisible true;},updateDevice() {updateDevice(this.deviceInfo).then(res {if (res.code 0) {this.getDeviceList()} else {this.$message.error(查询失败)}this.loading falsethis.updateDeviceVisible false;}).catch(err {this.loading falsethis.$message.error(err)})},getCommandList() {getCommandList().then(res {if (res.code 0) {this.commandListData res.data;} else {this.$message.error(查询失败)}this.loading false}).catch(err {this.loading falsethis.$message.error(err)})},addCommand() {addCommand(this.commandInfo).then(res {if (res.code 0) {this.getCommandList()} else {this.$message.error(命令添加失败)}this.loading falsethis.addCommandVisible false;}).catch(err {this.loading falsethis.$message.error(err)})},updateCommand(data){this.addCommandVisible true;this.commandInfo.name data.namethis.commandInfo.commands data.commands},deleteCommand(name){deleteCommand(name).then(res {if (res.code 0) {this.getCommandList()} else {this.$message.error(查询失败)}this.loading false}).catch(err {this.loading falsethis.$message.error(err)})},executeCommand(name){if (this.executeParam.devices.length 0){this.$message.error(请先在左侧选择设备)return}this.executeParam.name nameexecuteCommand(this.executeParam).then(res {if (res.code 0) {this.$message.success(执行完成)} else {this.$message.error(执行失败)}this.loading false}).catch(err {this.loading falsethis.$message.error(err)})},// 添加indextableRowClassName({row, rowIndex}) {row.index rowIndex},// 添加操作addForm() {if (this.isDataComplete()) {this.commandInfo.commands.push({operation: ,param: ,delayTime: })} else {this.$message({message: 请完善信息后再添加,type: warning})}},isDataComplete() {return this.commandInfo.commands.every((item) item.operation)},// 删除操作removeIdx(item, index) {this.commandInfo.commands.splice(index, 1)this.$message({message: 删除成功,type: success})}}}
/script
style scoped/style实际的效果可以看下视频演示 如何用电脑批量操作多部手机